/// <summary> /// Builds an object from a <see cref="JsonValue"/>. /// </summary> /// <param name="json">The <see cref="JsonValue"/> representation of the object.</param> /// <param name="serializer">The <see cref="JsonSerializer"/> instance to use for additional /// serialization of values.</param> public void FromJson(JsonValue json, JsonSerializer serializer) { foreach (var kvp in json.Object) { var vocabulary = SchemaKeywordCatalog.GetVocabulary(kvp.Key) ?? new SchemaVocabulary(kvp.Key); this[vocabulary] = kvp.Value.Boolean; } }
/// <summary> /// Add a single property requirement to the `properties` keyword. /// </summary> public static JsonSchema Vocabulary(this JsonSchema schema, string id, bool required) { var keyword = schema.OfType <VocabularyKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new VocabularyKeyword(); schema.Add(keyword); } var vocabulary = SchemaKeywordCatalog.GetVocabulary(id) ?? new SchemaVocabulary(id); keyword[vocabulary] = required; return(schema); }