コード例 #1
0
        protected override void VisitResource(JsonSchemaResource resource)
        {
            if (resource.Id != null)
            {
                writer.WriteString(Keys.Id, resource.Id.ToString());
            }

            if (resource.Anchor != null)
            {
                writer.WriteString(Keys.Anchor, resource.Anchor);
            }

            if (resource.RecursiveAnchor != null)
            {
                writer.WriteBoolean(Keys.RecursiveAnchor, resource.RecursiveAnchor.Value);
            }

            if (resource.Title != null)
            {
                writer.WriteString(Keys.Title, resource.Title);
            }

            if (resource.Description != null)
            {
                writer.WriteString(Keys.Description, resource.Description);
            }

            if (resource.Default != null)
            {
                WriteDefault(resource.Default);
            }

            if (resource.Deprecated != null)
            {
                writer.WriteBoolean(Keys.Deprecated, resource.Deprecated.Value);
            }

            if (resource.ReadOnly != null)
            {
                writer.WriteBoolean(Keys.ReadOnly, resource.ReadOnly.Value);
            }

            if (resource.WriteOnly != null)
            {
                writer.WriteBoolean(Keys.WriteOnly, resource.WriteOnly.Value);
            }

            if (resource.Examples != null)
            {
                WriteExamples(resource.Examples);
            }

            if (resource.Comment != null)
            {
                writer.WriteString(Keys.Comment, resource.Comment);
            }

            base.VisitResource(resource);
        }
コード例 #2
0
        protected virtual void VisitResource(JsonSchemaResource resource)
        {
            if (resource.Constraints.Count > 0)
            {
                VisitConstraints(resource.Constraints);
            }

            if (!resource.Definitions.IsNullOrEmpty())
            {
                VisitDefinitions(resource.Definitions);
            }
        }
コード例 #3
0
        public static async Task SerializeAsync(
            Stream stream,
            JsonSchemaResource resource,
            JsonSerializerOptions?options       = null,
            CancellationToken cancellationToken = default)
        {
            CheckValue(stream, nameof(stream));
            CheckValue(resource, nameof(resource));

            using (var schemaWriter = new JsonSchemaWriter(stream, options))
            {
                schemaWriter.Write(resource);
                await schemaWriter.FlushAsync(cancellationToken);
            }
        }
コード例 #4
0
        public static string Serialize(
            JsonSchemaResource resource,
            JsonSerializerOptions?options = null)
        {
            CheckValue(resource, nameof(resource));

            using (var stream = MemoryStreamManager.GetStream())
                using (var reader = new StreamReader(stream, System.Text.Encoding.UTF8))
                    using (var writer = new JsonSchemaWriter(stream, options))
                    {
                        writer.Write(resource);
                        writer.Flush();
                        stream.Position = 0;
                        return(reader.ReadToEnd());
                    }
        }
コード例 #5
0
 protected virtual void Visit(JsonSchemaResource resource)
 => resource.Accept(this);
コード例 #6
0
        /// <summary>
        /// Writes the <paramref name="resource"/> to the provided stream/writer/buffer.
        /// </summary>
        public void Write(JsonSchemaResource resource)
        {
            CheckNotDisposed();

            Visit(resource);
        }