/// <summary> /// Add a single property requirement to the <code>properties</code> keyword. /// </summary> public static JsonSchema Property(this JsonSchema schema, string name, JsonSchema property) { var keyword = schema.OfType <PropertiesKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new PropertiesKeyword(); schema.Add(keyword); } keyword.Add(name, property); return(schema); }
/// <summary> /// Add an <code>anyOf</code> keyword to the schema. /// </summary> public static JsonSchema AnyOf(this JsonSchema schema, params JsonSchema[] definitions) { var keyword = schema.OfType <AnyOfKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new AnyOfKeyword(); schema.Add(keyword); } keyword.AddRange(definitions); return(schema); }
/// <summary> /// Add a single definition to the <code>definitions</code> keyword. /// </summary> public static JsonSchema Definition(this JsonSchema schema, string name, JsonSchema definition) { var keyword = schema.OfType <DefinitionsKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new DefinitionsKeyword(); schema.Add(keyword); } keyword.Add(name, definition); return(schema); }
/// <summary> /// Add a schema-based dependency to the <code>dependencies</code> keyword. /// </summary> public static JsonSchema Dependency(this JsonSchema schema, string name, JsonSchema dependency) { var keyword = schema.OfType <DependenciesKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new DependenciesKeyword(); schema.Add(keyword); } keyword.Add(new SchemaDependency(name, dependency)); return(schema); }
/// <summary> /// Add a named text to the <code>info</code> keyword. /// </summary> /// <param name="schema">Json Schema to add text to</param> /// <param name="name">Name for text</param> /// <param name="text">Actual text</param> /// <returns>schema containing new text</returns> public static JsonSchema Info(this JsonSchema schema, string name, string text) { var keyword = schema.OfType <InfoKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new InfoKeyword(); schema.Add(keyword); } keyword.Add(name, text); return(schema); }
/// <summary> /// Add a single property requirement to the `properties` keyword. /// </summary> public static JsonSchema Vocabulary(this JsonSchema schema, SchemaVocabulary vocabulary, bool required) { var keyword = schema.OfType <VocabularyKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new VocabularyKeyword(); schema.Add(keyword); } keyword[vocabulary] = required; return(schema); }
/// <summary> /// Add a property-based dependency to the `dependencies` keyword. /// </summary> public static JsonSchema DependentRequired(this JsonSchema schema, string name, params string[] dependencies) { var keyword = schema.OfType <DependentRequiredKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new DependentRequiredKeyword(); schema.Add(keyword); } keyword.Add(new PropertyDependency(name, dependencies)); return(schema); }
/// <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); }
/// <summary> /// Add an `items` keyword to the schema. /// </summary> public static JsonSchema Item(this JsonSchema schema, JsonSchema definition) { var keyword = schema.OfType <ItemsKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new ItemsKeyword { IsArray = true }; schema.Add(keyword); } keyword.Add(definition); return(schema); }
/// <summary> /// Add a category of texts to the <code>texts</code> keyword. /// </summary> /// <param name="schema">Json Schema to add category of texts to</param> /// <param name="category">Category for text</param> /// <param name="name">Name for text</param> /// <param name="text">Actual text</param> /// <returns>schema containing new category and texts</returns> public static JsonSchema Texts(this JsonSchema schema, string category, string name, string text) { var keyword = schema.OfType <TextsKeyword>().FirstOrDefault(); if (keyword == null) { keyword = new TextsKeyword(); schema.Add(keyword); } if (keyword.ContainsKey(category)) { JsonSchema categorySchema = keyword[category]; categorySchema.OtherData.Add(name, text); } else { JsonSchema categorySchema = new JsonSchema(); categorySchema.OtherData.Add(name, text); keyword.Add(category, categorySchema); } return(schema); }
/// <summary> /// Gets the indicated keyword, if present. /// </summary> public static T Get <T>(this JsonSchema schema) where T : IJsonSchemaKeyword { return(schema.OfType <T>().FirstOrDefault()); }