private void WriteType(string propertyName, JsonWriter writer, JsonSchemaType type) { IList <JsonSchemaType> types; if (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 (var jsonSchemaType in types) { writer.WriteValue(JsonSchemaBuilder.MapType(jsonSchemaType)); } writer.WriteEndArray(); }
/// <summary> /// Reads a <see cref="JsonSchema"/> from the specified <see cref="JsonReader"/>. /// </summary> /// <param name="reader">The <see cref="JsonReader"/> containing the JSON Schema to read.</param> /// <param name="resolver">The <see cref="JsonSchemaResolver"/> to use when resolving schema references.</param> /// <returns>The <see cref="JsonSchema"/> object representing the JSON Schema.</returns> public static JsonSchema Read(JsonReader reader, JsonSchemaResolver resolver) { ValidationUtils.ArgumentNotNull(reader, "reader"); ValidationUtils.ArgumentNotNull(resolver, "resolver"); var builder = new JsonSchemaBuilder(resolver); return builder.Read(reader); }