Class JsonSchema
Encapsulates and models JSON Schema.
Implements
Inherited Members
Namespace: Manatee.Json.Schema
Assembly: Manatee.Json.dll
Syntax
public class JsonSchema : List<IJsonSchemaKeyword>, IList<IJsonSchemaKeyword>, ICollection<IJsonSchemaKeyword>, IReadOnlyList<IJsonSchemaKeyword>, IReadOnlyCollection<IJsonSchemaKeyword>, IEnumerable<IJsonSchemaKeyword>, IList, ICollection, IEnumerable, IJsonSerializable, IEquatable<JsonSchema>
Constructors
| Improve this Doc View SourceJsonSchema()
Creates a new instance of the JsonSchema class.
Declaration
public JsonSchema()
JsonSchema(Boolean)
Creates a new instance of the JsonSchema class, explicitly set to a true/false value.
Declaration
public JsonSchema(bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | value |
Fields
| Improve this Doc View SourceEmpty
Defines the empty schema. Analogous to True.
Declaration
public static readonly JsonSchema Empty
Field Value
Type | Description |
---|---|
JsonSchema |
False
Defines the False schema. Validates no JSON instances.
Declaration
public static readonly JsonSchema False
Field Value
Type | Description |
---|---|
JsonSchema |
True
Defines the True schema. Validates all JSON instances.
Declaration
public static readonly JsonSchema True
Field Value
Type | Description |
---|---|
JsonSchema |
Properties
| Improve this Doc View SourceDocumentPath
Defines the document path. If not explicitly provided, it will be derived from the Id property.
Declaration
public Uri? DocumentPath { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<System.Uri> |
ErrorTemplate
Gets or sets the error message template used for false
schemas.
Declaration
public static string ErrorTemplate { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Remarks
Does not supports any tokens.
Id
Gets the $id
(or id
for draft-04) property value, if declared.
Declaration
public string? Id { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.String> |
OtherData
Gets other data that may be present in the schema but unrelated to any known keywords.
Declaration
public JsonObject OtherData { get; set; }
Property Value
Type | Description |
---|---|
JsonObject |
ProcessingVersion
Gets or sets the processing version for this schema.
Declaration
public JsonSchemaVersion? ProcessingVersion { get; set; }
Property Value
Type | Description |
---|---|
System.Nullable<JsonSchemaVersion> |
Schema
Gets the $schema
property, if declared.
Declaration
public string? Schema { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.String> |
SupportedVersions
Declaration
public JsonSchemaVersion SupportedVersions { get; }
Property Value
Type | Description |
---|---|
JsonSchemaVersion |
Methods
| Improve this Doc View SourceEquals(Nullable<JsonSchema>)
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(JsonSchema? other)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonSchema> | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the current object is equal to the |
Equals(Nullable<Object>)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Object> | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the specified object is equal to the current object; otherwise, false. |
FromJson(JsonValue, JsonSerializer)
Builds an object from a JsonValue.
Declaration
public void FromJson(JsonValue json, JsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
JsonValue | json | The JsonValue representation of the object. |
JsonSerializer | serializer | The JsonSerializer instance to use for additional serialization of values. |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the current object. |
Overrides
RegisterSubschemas(SchemaValidationContext)
Used register any subschemas during validation. Enables look-forward compatibility with $ref
keywords.
Declaration
public void RegisterSubschemas(SchemaValidationContext context)
Parameters
Type | Name | Description |
---|---|---|
SchemaValidationContext | context | The context for the validation. |
ResolveSubschema(JsonPointer, Uri, JsonSchemaVersion)
Resolves any subschemas during resolution of a $ref
during validation.
Declaration
public JsonSchema? ResolveSubschema(JsonPointer pointer, Uri baseUri, JsonSchemaVersion supportedVersions)
Parameters
Type | Name | Description |
---|---|---|
JsonPointer | pointer | A JsonPointer to the target schema. |
System.Uri | baseUri | The current base URI. |
JsonSchemaVersion | supportedVersions | Indicates the root schema's supported versions. |
Returns
Type | Description |
---|---|
System.Nullable<JsonSchema> | The referenced schema, if it exists; otherwise null. |
ToJson(JsonSerializer)
Converts an object to a JsonValue.
Declaration
public JsonValue ToJson(JsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
JsonSerializer | serializer | The JsonSerializer instance to use for additional serialization of values. |
Returns
Type | Description |
---|---|
JsonValue | The JsonValue representation of the object. |
Validate(JsonValue, Nullable<JsonSchemaOptions>)
Validates a JSON instance.
Declaration
public SchemaValidationResults Validate(JsonValue json, JsonSchemaOptions? options = default(JsonSchemaOptions? ))
Parameters
Type | Name | Description |
---|---|---|
JsonValue | json | The instance to validate. |
System.Nullable<JsonSchemaOptions> | options | Options for the validation. |
Returns
Type | Description |
---|---|
SchemaValidationResults | Results object containing a final result and any errors that may have been found. |
Validate(SchemaValidationContext)
DO NOT USE FOR BASIC JSON INSTANCE VALIDATION. Used for subschema validation from within a custom keyword.
Declaration
public SchemaValidationResults Validate(SchemaValidationContext context)
Parameters
Type | Name | Description |
---|---|---|
SchemaValidationContext | context | The context for the validation. |
Returns
Type | Description |
---|---|
SchemaValidationResults | The schema validation results. |
ValidateSchema(Nullable<JsonSchemaOptions>)
Validates that the schema object represents a valid schema in accordance with a known meta-schema.
Declaration
public MetaSchemaValidationResults ValidateSchema(JsonSchemaOptions? options = default(JsonSchemaOptions? ))
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonSchemaOptions> | options |
Returns
Type | Description |
---|---|
MetaSchemaValidationResults | Validation results. |
Operators
| Improve this Doc View SourceEquality(Nullable<JsonSchema>, Nullable<JsonSchema>)
Overloads the equals operator for JsonSchema.
Declaration
public static bool operator ==(JsonSchema? left, JsonSchema? right)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonSchema> | left | |
System.Nullable<JsonSchema> | right |
Returns
Type | Description |
---|---|
System.Boolean | true if the two values represent the same schema; false otherwise |
Implicit(Boolean to JsonSchema)
Implicitly converts a boolean into a boolean schema.
Declaration
public static implicit operator JsonSchema(bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | value |
Returns
Type | Description |
---|---|
JsonSchema |
Inequality(Nullable<JsonSchema>, Nullable<JsonSchema>)
Overloads the not-equal operator for JsonSchema.
Declaration
public static bool operator !=(JsonSchema? left, JsonSchema? right)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<JsonSchema> | left | |
System.Nullable<JsonSchema> | right |
Returns
Type | Description |
---|---|
System.Boolean | false if the two values represent the same schema; true otherwise |