<PackageReference Include="NJsonSchema" Version="10.2.2" />

JsonSchema

A base class for describing a JSON schema.
public static string ToolchainVersion { get; }

Gets the NJsonSchema toolchain version.

public string ActualDiscriminator { get; }

Gets the discriminator property (Swagger only).

Gets the actual resolved discriminator of this schema (no inheritance, OpenApi only).

Gets all properties of this schema (i.e. all direct properties and properties from the schemas in allOf which do not have a type).

public virtual JsonSchema ActualSchema { get; }

Gets the actual schema, either this or the referenced schema.

public virtual JsonSchema ActualTypeSchema { get; }

Gets the type actual schema (e.g. the shared schema of a property, parameter, etc.).

public JsonSchema AdditionalItemsSchema { get; set; }

Gets or sets the schema for the additional items.

Gets or sets the schema for the additional properties.

Gets the list of all inherited/parent schemas.

public ICollection<JsonSchema> AllOf { get; }

Gets the collection of schemas where each schema must be valid.

public bool AllowAdditionalItems { get; set; }

Gets or sets a value indicating whether additional items are allowed (default: true).

public bool AllowAdditionalProperties { get; set; }

Gets or sets a value indicating whether additional properties are allowed (default: true).

public ICollection<JsonSchema> AnyOf { get; }

Gets the collection of schemas where at least one must be valid.

public object Default { get; set; }

Gets or sets the default value.

public IDictionary<string, JsonSchema> Definitions { get; }

Gets the other schema definitions of this schema.

public string DeprecatedMessage { get; set; }

Gets or sets a message indicating why the schema is deprecated (custom extension, sets 'x-deprecatedMessage').

public virtual string Description { get; set; }

Gets or sets the description.

public JsonSchema DictionaryKey { get; set; }

Gets or sets the dictionary key schema (x-key, only enum schemas are allowed).

public string Discriminator { get; set; }

Gets or sets the discriminator property (Swagger only, should not be used in internal tooling).

Gets or sets the discriminator of this schema (OpenApi only).

public ICollection<object> Enumeration { get; }

Gets the collection of required properties.

public Collection<string> EnumerationNames { get; set; }

Gets or sets the enumeration names (optional, draft v5).

public object Example { get; set; }

Gets or sets the example (Swagger and Open API only).

public decimal? ExclusiveMaximum { get; set; }

Gets or sets the exclusive maximum value (v6).

public decimal? ExclusiveMinimum { get; set; }

Gets or sets the exclusive minimum value (v6).

public IDictionary<string, object> ExtensionData { get; set; }

Gets or sets the extension data (i.e. additional properties which are not directly defined by JSON Schema).

public string Format { get; set; }

Gets or sets the format string.

public bool HasAllOfSchemaReference { get; }

Gets a value indicating whether this is an allOf schema reference.

public bool HasAnyOfSchemaReference { get; }

Gets a value indicating whether this is an anyOf schema reference.

public bool HasOneOfSchemaReference { get; }

Gets a value indicating whether this is an oneOf schema reference.

public bool HasReference { get; }

Gets a value indicating whether this is a schema reference ($ref, HasAllOfSchemaReference, HasOneOfSchemaReference or HasAnyOfSchemaReference).

public bool HasTypeNameTitle { get; }

Gets a value indicating whether the schema title can be used as type name.

public string Id { get; set; }

Gets or sets the id.

public JsonSchema InheritedSchema { get; }

Gets the inherited/parent schema (most probable base schema in allOf).

Gets the inherited/parent schema which may also be inlined (the schema itself if it is a dictionary or array, otherwise InheritedSchema).

public bool IsAbstract { get; set; }

Gets or sets a value indicating whether the type is abstract, i.e. cannot be instantiated directly (x-abstract).

public bool IsAnyType { get; }

Gets a value indicating whether this is any type (e.g. any in TypeScript or object in CSharp).

public bool IsArray { get; }

Gets a value indicating whether the schema represents an array type (an array where each item has the same type).

public bool IsBinary { get; }

Gets a value indicating whether the schema is binary (file or binary format).

public bool IsDeprecated { get; set; }

Gets or sets a value indicating whether the schema is deprecated (native in Open API 'deprecated', custom in Swagger/JSON Schema 'x-deprecated').

public bool IsDictionary { get; }

Gets a value indicating whether the schema represents a dictionary type (no properties and AdditionalProperties or PatternProperties contain a schema).

public bool IsEnumeration { get; }

Gets a value indicating whether this is enumeration.

public bool IsExclusiveMaximum { get; set; }

Gets or sets a value indicating whether the minimum value is excluded (v4).

public bool IsExclusiveMinimum { get; set; }

Gets or sets a value indicating whether the minimum value is excluded (v4).

public bool IsFlagEnumerable { get; set; }

Gets or sets a value indicating this is an bit flag enum (custom extension, sets 'x-enumFlags', default: false).

public bool? IsNullableRaw { get; set; }

Gets or sets a value indicating whether the schema is nullable (native in Open API 'nullable', custom in Swagger 'x-nullable').

public bool IsObject { get; }

Gets a value indicating whether the schema describes an object.

public bool IsTuple { get; }

Gets a value indicating whether the schema represents an tuple type (an array where each item may have a different type).

public JsonSchema Item { get; set; }

Gets or sets the schema of an array item.

public ICollection<JsonSchema> Items { get; }

Gets or sets the schemas of the array's tuple values.

public decimal? Maximum { get; set; }

Gets or sets the maximum allowed value.

public int MaxItems { get; set; }

Gets or sets the maximum length of the array.

public int? MaxLength { get; set; }

Gets or sets the maximum length of the value string.

public int MaxProperties { get; set; }

Gets or sets the maximal number of allowed properties in an object.

public decimal? Minimum { get; set; }

Gets or sets the minimum allowed value.

public int MinItems { get; set; }

Gets or sets the minimum length of the array.

public int? MinLength { get; set; }

Gets or sets the minimum length of the value string.

public int MinProperties { get; set; }

Gets or sets the minimal number of allowed properties in an object.

public decimal? MultipleOf { get; set; }

Gets or sets the required multiple of for the number value.

public JsonSchema Not { get; set; }

Gets or sets the schema which must not be valid.

public ICollection<JsonSchema> OneOf { get; }

Gets the collection of schemas where exactly one must be valid.

public virtual object Parent { get; set; }

Gets the parent schema of this schema.

public JsonSchema ParentSchema { get; }

Gets the parent schema of this schema.

public string Pattern { get; set; }

Gets or sets the validation pattern as regular expression.

Gets the pattern properties of the type.

public IDictionary<string, JsonSchemaProperty> Properties { get; }

Gets the properties of the type.

public ICollection<string> RequiredProperties { get; }

Gets the collection of required properties.

Gets the discriminator or discriminator of an inherited schema (or null).

public string SchemaVersion { get; set; }

Gets or sets the schema.

public string Title { get; set; }

Gets or sets the title.

public JsonObjectType Type { get; set; }

Gets the object types (as enum flags).

public bool UniqueItems { get; set; }

Gets or sets a value indicating whether the items in the array must be unique.

public JsonXmlObject Xml { get; set; }

Gets the xml object of the schema (used in Swagger specifications).

public JsonSchema()

Initializes a new instance of the JsonSchema class.

public static JsonSchema CreateAnySchema()

Creates a schema which matches any data.

public static TSchemaType CreateAnySchema<TSchemaType>() where TSchemaType : JsonSchema

Creates a schema which matches any data.

Creates the serializer contract resolver based on the SchemaType.

public static Task<JsonSchema> FromFileAsync(string filePath)

Loads a JSON Schema from a given file path (only available in .NET 4.x).

public static Task<JsonSchema> FromFileAsync(string filePath, Func<JsonSchema, JsonReferenceResolver> referenceResolverFactory)

Loads a JSON Schema from a given file path (only available in .NET 4.x).

public static Task<JsonSchema> FromJsonAsync(string data)

Deserializes a JSON string to a JsonSchema.

public static Task<JsonSchema> FromJsonAsync(string data, string documentPath)

Deserializes a JSON string to a JsonSchema.

public static Task<JsonSchema> FromJsonAsync(string data, string documentPath, Func<JsonSchema, JsonReferenceResolver> referenceResolverFactory)

Deserializes a JSON string to a JsonSchema.

public static JsonSchema FromSampleJson(string data)

Creates a JsonSchema from sample JSON data.

public static JsonSchema FromType<TType>()

Creates a JsonSchema from a given type.

public static JsonSchema FromType(Type type)

Creates a JsonSchema from a given type.

public static JsonSchema FromType<TType>(JsonSchemaGeneratorSettings settings)

Creates a JsonSchema from a given type.

public static JsonSchema FromType(Type type, JsonSchemaGeneratorSettings settings)

Creates a JsonSchema from a given type.

public static Task<JsonSchema> FromUrlAsync(string url)

Loads a JSON Schema from a given URL (only available in .NET 4.x).

public static Task<JsonSchema> FromUrlAsync(string url, Func<JsonSchema, JsonReferenceResolver> referenceResolverFactory)

Loads a JSON Schema from a given URL (only available in .NET 4.x).

public bool Inherits(JsonSchema schema)

Determines whether the given schema is the parent schema of this schema (i.e. super/base class).

public bool InheritsSchema(JsonSchema parentSchema)

Gets a value indicating whether this schema inherits from the given parent schema.

public virtual bool IsNullable(SchemaType schemaType)

Gets a value indicating whether the validated data can be null.

public string ToJson()

Serializes the JsonSchema to a JSON string.

public string ToJson(Formatting formatting)

Serializes the JsonSchema to a JSON string.

Creates a JsonSchema from sample JSON data.

public ICollection<ValidationError> Validate(string jsonData, IFormatValidator[] customValidators)

Validates the given JSON data against this schema.

public ICollection<ValidationError> Validate(JToken token, IFormatValidator[] customValidators)

Validates the given JSON token against this schema.