コード例 #1
0
        private void WriteType(string propertyName, JsonWriter writer, JsonSchemaType type)
        {
            IList <JsonSchemaType> types;

            if (System.Enum.IsDefined(typeof(JsonSchemaType), type))
            {
                types = new List <JsonSchemaType> {
                    type
                }
            }
            ;
            else
            {
                types = EnumUtils.GetFlagsValues(type).Where(v => v != JsonSchemaType.None).ToList();
            }

            if (types.Count == 0)
            {
                return;
            }

            writer.WritePropertyName(propertyName);

            if (types.Count == 1)
            {
                writer.WriteValue(JsonSchemaBuilder.MapType(types[0]));
                return;
            }

            writer.WriteStartArray();
            foreach (JsonSchemaType jsonSchemaType in types)
            {
                writer.WriteValue(JsonSchemaBuilder.MapType(jsonSchemaType));
            }
            writer.WriteEndArray();
        }
コード例 #2
0
 /// <summary>
 /// Add a `$comment` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="comment">The comment.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Comment(this JsonSchemaBuilder builder, string comment)
 {
     builder.Add(new CommentKeyword(comment));
     return(builder);
 }
コード例 #3
0
 /// <summary>
 /// Add an `anyOf` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="schemas">The schemas for `anyOf`.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder AnyOf(this JsonSchemaBuilder builder, IEnumerable <JsonSchema> schemas)
 {
     builder.Add(new AnyOfKeyword(schemas));
     return(builder);
 }
コード例 #4
0
 /// <summary>
 /// Add an `anyOf` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="schemas">The schemas for `anyOf`.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder AnyOf(this JsonSchemaBuilder builder, params JsonSchema[] schemas)
 {
     builder.Add(new AnyOfKeyword(schemas));
     return(builder);
 }
コード例 #5
0
 /// <summary>
 /// Add an `additionalProperties` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="schema">The schema for `additionalProperties`.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder AdditionalProperties(this JsonSchemaBuilder builder, JsonSchema schema)
 {
     builder.Add(new AdditionalPropertiesKeyword(schema));
     return(builder);
 }
コード例 #6
0
 /// <summary>
 /// Add a `definitions` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="defs">The schema definition map.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Definitions(this JsonSchemaBuilder builder, params (string name, JsonSchema schema)[] defs)
コード例 #7
0
 /// <summary>
 /// Add a `definitions` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="defs">The schema definition map.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Definitions(this JsonSchemaBuilder builder, IReadOnlyDictionary <string, JsonSchema> defs)
 {
     builder.Add(new DefinitionsKeyword(defs));
     return(builder);
 }
コード例 #8
0
 /// <summary>
 /// Add a `default` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="element">The value.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Default(this JsonSchemaBuilder builder, JsonElement element)
 {
     builder.Add(new DefaultKeyword(element));
     return(builder);
 }
コード例 #9
0
 /// <summary>
 /// Add an `contains` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="schema">The schema for `contains`.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Contains(this JsonSchemaBuilder builder, JsonSchema schema)
 {
     builder.Add(new ContainsKeyword(schema));
     return(builder);
 }
コード例 #10
0
 /// <summary>
 /// Add an `$anchor` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="reference">The anchor reference.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Anchor(this JsonSchemaBuilder builder, string reference)
 {
     builder.Add(new AnchorKeyword(reference));
     return(builder);
 }
コード例 #11
0
 /// <summary>
 /// Add a `const` keyword.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <param name="element">The constant value.</param>
 /// <returns>The builder.</returns>
 public static JsonSchemaBuilder Const(this JsonSchemaBuilder builder, JsonElementProxy element)
 {
     builder.Add(new ConstKeyword(element));
     return(builder);
 }