Skip to main content

Schema

Struct Schema 

Source
pub struct Schema {
Show 65 fields pub schema: Option<Url>, pub id: Option<String>, pub ref_: Option<String>, pub anchor: Option<String>, pub dynamic_ref: Option<String>, pub dynamic_anchor: Option<String>, pub comment: Option<String>, pub defs: Option<BTreeMap<String, SchemaValue>>, pub vocabulary: Option<IndexMap<Url, bool>>, pub properties: IndexMap<String, SchemaValue>, pub pattern_properties: IndexMap<String, SchemaValue>, pub additional_properties: Option<Box<SchemaValue>>, pub property_names: Option<Box<SchemaValue>>, pub dependent_schemas: IndexMap<String, SchemaValue>, pub items: Option<Box<SchemaValue>>, pub prefix_items: Option<Vec<SchemaValue>>, pub contains: Option<Box<SchemaValue>>, pub all_of: Option<Vec<SchemaValue>>, pub any_of: Option<Vec<SchemaValue>>, pub one_of: Option<Vec<SchemaValue>>, pub not: Option<Box<SchemaValue>>, pub if_: Option<Box<SchemaValue>>, pub then_: Option<Box<SchemaValue>>, pub else_: Option<Box<SchemaValue>>, pub unevaluated_properties: Option<Box<SchemaValue>>, pub unevaluated_items: Option<Box<SchemaValue>>, pub type_: Option<TypeValue>, pub enum_: Option<Vec<Value>>, pub const_: Option<Value>, pub minimum: Option<Number>, pub maximum: Option<Number>, pub exclusive_minimum: Option<Number>, pub exclusive_maximum: Option<Number>, pub multiple_of: Option<Number>, pub min_length: Option<u64>, pub max_length: Option<u64>, pub pattern: Option<String>, pub min_items: Option<u64>, pub max_items: Option<u64>, pub unique_items: bool, pub min_contains: Option<u64>, pub max_contains: Option<u64>, pub required: Option<Vec<String>>, pub min_properties: Option<u64>, pub max_properties: Option<u64>, pub dependent_required: Option<IndexMap<String, Vec<String>>>, pub title: Option<String>, pub description: Option<String>, pub default: Option<Value>, pub deprecated: bool, pub read_only: bool, pub write_only: bool, pub examples: Option<Vec<Value>>, pub format: Option<String>, pub content_media_type: Option<String>, pub content_encoding: Option<String>, pub content_schema: Option<Box<SchemaValue>>, pub markdown_description: Option<String>, pub markdown_enum_descriptions: Option<Vec<Option<String>>>, pub x_lintel: Option<LintelSchemaExt>, pub x_taplo: Option<TaploSchemaExt>, pub x_taplo_info: Option<TaploInfoSchemaExt>, pub x_tombi: TombiSchemaExt, pub x_intellij: IntellijSchemaExt, pub extra: BTreeMap<String, Value>,
}
Expand description

A JSON Schema object (draft 2020-12).

Represents a single schema resource as defined by the JSON Schema Core and JSON Schema Validation specifications.

Fields are grouped by vocabulary:

  • Core ($schema, $id, $ref, $anchor, $dynamicRef, $dynamicAnchor, $comment, $defs, $vocabulary)
  • Metadata / Annotation (title, description, default, deprecated, readOnly, writeOnly, examples)
  • Validation — type (type, enum, const)
  • Applicator — object (properties, patternProperties, additionalProperties, propertyNames, unevaluatedProperties)
  • Validation — object (required, minProperties, maxProperties, dependentRequired)
  • Applicator — array (items, prefixItems, contains, unevaluatedItems)
  • Validation — array (minItems, maxItems, uniqueItems, minContains, maxContains)
  • Validation — number (minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf)
  • Validation — string (minLength, maxLength, pattern, format)
  • Applicator — composition (allOf, anyOf, oneOf, not)
  • Applicator — conditional (if, then, else, dependentSchemas)
  • Content (contentMediaType, contentEncoding, contentSchema)

Fields§

§schema: Option<Url>

The $schema keyword — JSON Schema dialect identifier.

The "$schema" keyword is both used as a JSON Schema dialect identifier and as the identifier of a resource which is itself a JSON Schema, which describes the set of valid schemas written for this particular dialect.

The value of this keyword MUST be a URI (containing a scheme) and this URI MUST be normalized. The current schema MUST be valid against the meta-schema identified by this URI.

If this URI identifies a retrievable resource, that resource SHOULD be of media type "application/schema+json".

The "$schema" keyword SHOULD be used in the document root schema object, and MAY be used in the root schema objects of embedded schema resources. It MUST NOT appear in non-resource root schema objects. If absent from the document root schema, the resulting behavior is implementation-defined.

Values for this property are defined elsewhere in this and other documents, and by other parties.

See JSON Schema Core §8.1.1.

§id: Option<String>

The $id keyword — schema resource identifier.

The "$id" keyword identifies a schema resource with its canonical URI.

Note that this URI is an identifier and not necessarily a network locator. In the case of a network-addressable URL, a schema need not be downloadable from its canonical URI.

If present, the value for this keyword MUST be a string, and MUST represent a valid URI-reference. This URI-reference SHOULD be normalized, and MUST resolve to an absolute-URI (without a fragment), or to a URI with an empty fragment.

The absolute-URI also serves as the base URI for relative URI-references in keywords within the schema resource, in accordance with RFC 3986 section 5.1.1 regarding base URIs embedded in content.

The presence of "$id" in a subschema indicates that the subschema constitutes a distinct schema resource within a single schema document.

See JSON Schema Core §8.2.1.

§ref_: Option<String>

The $ref keyword — static schema reference.

The "$ref" keyword is an applicator that is used to reference a statically identified schema. Its results are the results of the referenced schema. Note that this definition of how the results are determined means that other keywords can appear alongside of "$ref" in the same schema object.

The value of the "$ref" keyword MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI of the schema to apply. This resolution is safe to perform on schema load, as the process of evaluating an instance cannot change how the reference resolves.

See JSON Schema Core §8.2.3.1.

§anchor: Option<String>

The $anchor keyword — plain-name fragment identifier.

The "$anchor" and "$dynamicAnchor" keywords are used to specify plain name fragments. They are identifier keywords that can only be used to create plain name fragments, rather than absolute URIs as seen with "$id".

If present, the value of this keyword MUST be a string and MUST start with a letter ([A-Za-z]) or underscore ("_"), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), and periods (".").

See JSON Schema Core §8.2.2.

§dynamic_ref: Option<String>

The $dynamicRef keyword — dynamic schema reference.

The "$dynamicRef" keyword is an applicator that allows for deferring the full resolution until runtime, at which point it is resolved each time it is encountered while evaluating an instance.

Together with "$dynamicAnchor", "$dynamicRef" implements a cooperative extension mechanism that is primarily useful with recursive schemas (schemas that reference themselves). Both the extension point and the runtime-determined extension target are defined with "$dynamicAnchor", and only exhibit runtime dynamic behavior when referenced with "$dynamicRef".

The value of the "$dynamicRef" property MUST be a string which is a URI-Reference. Resolved against the current URI base, it produces the URI used as the starting point for runtime resolution.

See JSON Schema Core §8.2.3.2.

§dynamic_anchor: Option<String>

The $dynamicAnchor keyword — dynamic extension point.

Separately from the usual usage of URIs, "$dynamicAnchor" indicates that the fragment is an extension point when used with the "$dynamicRef" keyword. This low-level, advanced feature makes it easier to extend recursive schemas such as the meta-schemas, without imposing any particular semantics on that extension.

If present, the value of this keyword MUST be a string and MUST conform to the same rules as "$anchor".

See JSON Schema Core §8.2.2.

§comment: Option<String>

The $comment keyword — schema author comments.

This keyword reserves a location for comments from schema authors to readers or maintainers of the schema.

The value of this keyword MUST be a string. Implementations MUST NOT present this string to end users. Tools for editing schemas SHOULD support displaying and editing this keyword. The value of this keyword MAY be used in debug or error output which is intended for developers making use of schemas.

Implementations MAY strip "$comment" values at any point during processing. In particular, this allows for shortening schemas when the size of deployed schemas is a concern.

Implementations MUST NOT take any other action based on the presence, absence, or contents of "$comment" properties. In particular, the value of "$comment" MUST NOT be collected as an annotation result.

See JSON Schema Core §8.3.

§defs: Option<BTreeMap<String, SchemaValue>>

The $defs keyword — inline re-usable schema definitions.

The $defs keyword reserves a location for schema authors to inline re-usable JSON Schemas into a more general schema. The keyword does not directly affect the validation result.

This keyword’s value MUST be an object. Each member value of this object MUST be a valid JSON Schema.

As an example, here is a schema describing an array of positive integers, where the positive integer constraint is a subschema in $defs:

{
    "type": "array",
    "items": { "$ref": "#/$defs/positiveInteger" },
    "$defs": {
        "positiveInteger": {
            "type": "integer",
            "exclusiveMinimum": 0
        }
    }
}

See JSON Schema Core §8.2.4.

§vocabulary: Option<IndexMap<Url, bool>>

The $vocabulary keyword — meta-schema vocabulary declaration.

The "$vocabulary" keyword is used in meta-schemas to identify the vocabularies available for use in schemas described by that meta-schema. It is also used to indicate whether each vocabulary is required or optional, in the sense that an implementation MUST understand the required vocabularies in order to successfully process the schema. Together, this information forms a dialect. Any vocabulary that is understood by the implementation MUST be processed in a manner consistent with the semantic definitions contained within the vocabulary.

The value of this keyword MUST be an object. The property names in the object MUST be URIs (containing a scheme) and this URI MUST be normalized. Each URI that appears as a property name identifies a specific set of keywords and their semantics.

The values of the object properties MUST be booleans. If the value is true, then implementations that do not recognize the vocabulary MUST refuse to process any schemas that declare this meta-schema with "$schema". If the value is false, implementations that do not recognize the vocabulary SHOULD proceed with processing such schemas. The value has no impact if the implementation understands the vocabulary.

The "$vocabulary" keyword SHOULD be used in the root schema of any schema document intended for use as a meta-schema. It MUST NOT appear in subschemas.

The "$vocabulary" keyword MUST be ignored in schema documents that are not being processed as a meta-schema.

See JSON Schema Core §8.1.2.

§properties: IndexMap<String, SchemaValue>

The properties keyword — per-property subschemas.

The value of "properties" MUST be an object. Each value of this object MUST be a valid JSON Schema.

Validation succeeds if, for each name that appears in both the instance and as a name within this keyword’s value, the child instance for that name successfully validates against the corresponding schema.

The annotation result of this keyword is the set of instance property names matched by this keyword. This annotation affects the behavior of "additionalProperties" (in this vocabulary) and "unevaluatedProperties" in the Unevaluated vocabulary.

Omitting this keyword has the same assertion behavior as an empty object.

See JSON Schema Core §10.3.2.1.

§pattern_properties: IndexMap<String, SchemaValue>

The patternProperties keyword — regex-matched property subschemas.

The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the ECMA-262 regular expression dialect. Each property value of this object MUST be a valid JSON Schema.

Validation succeeds if, for each instance name that matches any regular expressions that appear as a property name in this keyword’s value, the child instance for that name successfully validates against each schema that corresponds to a matching regular expression.

The annotation result of this keyword is the set of instance property names matched by this keyword. This annotation affects the behavior of "additionalProperties" (in this vocabulary) and "unevaluatedProperties" (in the Unevaluated vocabulary).

Omitting this keyword has the same assertion behavior as an empty object.

See JSON Schema Core §10.3.2.2.

§additional_properties: Option<Box<SchemaValue>>

The additionalProperties keyword — schema for unmatched properties.

The value of "additionalProperties" MUST be a valid JSON Schema.

The behavior of this keyword depends on the presence and annotation results of "properties" and "patternProperties" within the same schema object. Validation with "additionalProperties" applies only to the child values of instance names that do not appear in the annotation results of either "properties" or "patternProperties".

For all such properties, validation succeeds if the child instance validates against the "additionalProperties" schema.

The annotation result of this keyword is the set of instance property names validated by this keyword’s subschema. This annotation affects the behavior of "unevaluatedProperties" in the Unevaluated vocabulary.

Omitting this keyword has the same assertion behavior as an empty schema.

See JSON Schema Core §10.3.2.3.

§property_names: Option<Box<SchemaValue>>

The propertyNames keyword — property name schema.

The value of "propertyNames" MUST be a valid JSON Schema.

If the instance is an object, this keyword validates if every property name in the instance validates against the provided schema. Note the property name that the schema is testing will always be a string.

Omitting this keyword has the same behavior as an empty schema.

See JSON Schema Core §10.3.2.4.

§dependent_schemas: IndexMap<String, SchemaValue>

The dependentSchemas keyword — conditional subschemas by property name.

This keyword specifies subschemas that are evaluated if the instance is an object and contains a certain property.

This keyword’s value MUST be an object. Each value in the object MUST be a valid JSON Schema.

If the object key is a property in the instance, the entire instance must validate against the subschema. Its use is dependent on the presence of the property.

Omitting this keyword has the same behavior as an empty object.

See JSON Schema Core §10.2.2.4.

§items: Option<Box<SchemaValue>>

The items keyword — schema for remaining array items.

The value of "items" MUST be a valid JSON Schema.

This keyword applies its subschema to all instance elements at indexes greater than the length of the "prefixItems" array in the same schema object, as reported by the annotation result of that "prefixItems" keyword. If no such annotation result exists, "items" applies its subschema to all instance array elements. Note that the behavior of "items" without "prefixItems" is identical to that of the schema form of "items" in prior drafts. When "prefixItems" is present, the behavior of "items" is identical to the former "additionalItems" keyword.

If the "items" subschema is applied to any positions within the instance array, it produces an annotation result of boolean true, indicating that all remaining array elements have been evaluated against this keyword’s subschema. This annotation affects the behavior of "unevaluatedItems" in the Unevaluated vocabulary.

Omitting this keyword has the same assertion behavior as an empty schema.

See JSON Schema Core §10.3.1.2.

§prefix_items: Option<Vec<SchemaValue>>

The prefixItems keyword — positional array item schemas.

The value of "prefixItems" MUST be a non-empty array of valid JSON Schemas.

Validation succeeds if each element of the instance validates against the schema at the same position, if any. This keyword does not constrain the length of the array. If the array is longer than this keyword’s value, this keyword validates only the prefix of matching length.

This keyword produces an annotation value which is the largest index to which this keyword applied a subschema. The value MAY be a boolean true if a subschema was applied to every index of the instance, such as is produced by the "items" keyword. This annotation affects the behavior of "items" and "unevaluatedItems".

Omitting this keyword has the same assertion behavior as an empty array.

See JSON Schema Core §10.3.1.1.

§contains: Option<Box<SchemaValue>>

The contains keyword — array containment schema.

The value of this keyword MUST be a valid JSON Schema.

An array instance is valid against "contains" if at least one of its elements is valid against the given schema, except when "minContains" is present and has a value of 0, in which case an array instance MUST be considered valid against the "contains" keyword, even if none of its elements is valid against the given schema.

This keyword produces an annotation value which is an array of the indexes to which this keyword validates successfully when applying its subschema, in ascending order. The value MAY be a boolean true if the subschema validates successfully when applied to every index of the instance.

The subschema MUST be applied to every array element even after the first match has been found, in order to collect annotations for use by other keywords. This is to ensure that all possible annotations are collected.

See JSON Schema Core §10.3.1.3.

§all_of: Option<Vec<SchemaValue>>

The allOf keyword — conjunction of subschemas.

This keyword’s value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.

An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword’s value.

See JSON Schema Core §10.2.1.1.

§any_of: Option<Vec<SchemaValue>>

The anyOf keyword — disjunction of subschemas.

This keyword’s value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.

An instance validates successfully against this keyword if it validates successfully against at least one schema defined by this keyword’s value. Note that when annotations are being collected, all subschemas MUST be examined so that annotations are collected from each subschema that validates successfully.

See JSON Schema Core §10.2.1.2.

§one_of: Option<Vec<SchemaValue>>

The oneOf keyword — exclusive disjunction of subschemas.

This keyword’s value MUST be a non-empty array. Each item of the array MUST be a valid JSON Schema.

An instance validates successfully against this keyword if it validates successfully against exactly one schema defined by this keyword’s value.

See JSON Schema Core §10.2.1.3.

§not: Option<Box<SchemaValue>>

The not keyword — negation.

This keyword’s value MUST be a valid JSON Schema.

An instance is valid against this keyword if it fails to validate successfully against the schema defined by this keyword.

See JSON Schema Core §10.2.1.4.

§if_: Option<Box<SchemaValue>>

The if keyword — conditional guard.

This keyword’s value MUST be a valid JSON Schema.

This validation outcome of this keyword’s subschema has no direct effect on the overall validation result. Rather, it controls which of the "then" or "else" keywords are evaluated.

Instances that successfully validate against this keyword’s subschema MUST also be valid against the subschema value of the "then" keyword, if present.

Instances that fail to validate against this keyword’s subschema MUST also be valid against the subschema value of the "else" keyword, if present.

If annotations are being collected, they are collected from this keyword’s subschema in the usual way, including when the keyword is present without either "then" or "else".

See JSON Schema Core §10.2.2.1.

§then_: Option<Box<SchemaValue>>

The then keyword — consequent subschema.

This keyword’s value MUST be a valid JSON Schema.

When "if" is present, and the instance successfully validates against its subschema, then validation succeeds against this keyword if the instance also successfully validates against this keyword’s subschema.

This keyword has no effect when "if" is absent, or when the instance fails to validate against its subschema. Implementations MUST NOT evaluate the instance against this keyword, for either validation or annotation collection purposes, in such cases.

See JSON Schema Core §10.2.2.2.

§else_: Option<Box<SchemaValue>>

The else keyword — alternative subschema.

This keyword’s value MUST be a valid JSON Schema.

When "if" is present, and the instance fails to validate against its subschema, then validation succeeds against this keyword if the instance successfully validates against this keyword’s subschema.

This keyword has no effect when "if" is absent, or when the instance successfully validates against its subschema. Implementations MUST NOT evaluate the instance against this keyword, for either validation or annotation collection purposes, in such cases.

See JSON Schema Core §10.2.2.3.

§unevaluated_properties: Option<Box<SchemaValue>>

The unevaluatedProperties keyword — schema for properties not covered by other keywords.

The value of "unevaluatedProperties" MUST be a valid JSON Schema.

The behavior of this keyword depends on the annotation results of adjacent keywords that apply to the instance location being validated. Specifically, the annotations from "properties", "patternProperties", and "additionalProperties", which can come from those keywords when they are adjacent to the "unevaluatedProperties" keyword. Those three annotations, as well as "unevaluatedProperties", can also result from any and all adjacent in-place applicator keywords.

Validation with "unevaluatedProperties" applies only to the child values of instance names that do not appear in the "properties", "patternProperties", "additionalProperties", or "unevaluatedProperties" annotation results that apply to the instance location being validated.

For all such properties, validation succeeds if the child instance validates against the "unevaluatedProperties" schema.

The annotation result of this keyword is the set of instance property names validated by this keyword’s subschema. This annotation affects the behavior of "unevaluatedProperties" in parent schemas.

Omitting this keyword has the same assertion behavior as an empty schema.

See JSON Schema Core §11.3.

§unevaluated_items: Option<Box<SchemaValue>>

The unevaluatedItems keyword — schema for array items not covered by other keywords.

The value of "unevaluatedItems" MUST be a valid JSON Schema.

The behavior of this keyword depends on the annotation results of adjacent keywords that apply to the instance location being validated. Specifically, the annotations from "prefixItems", "items", and "contains", which can come from those keywords when they are adjacent to the "unevaluatedItems" keyword. Those three annotations, as well as "unevaluatedItems", can also result from any and all adjacent in-place applicator keywords.

If no relevant annotations are present, the "unevaluatedItems" subschema MUST be applied to all locations in the array. If a boolean true value is present from any of the relevant annotations, "unevaluatedItems" MUST be ignored. Otherwise, the subschema MUST be applied to any index greater than the largest annotation value for "prefixItems", which does not appear in any annotation value for "contains".

If the "unevaluatedItems" subschema is applied to any positions within the instance array, it produces an annotation result of boolean true, analogous to the behavior of "items". This annotation affects the behavior of "unevaluatedItems" in parent schemas.

Omitting this keyword has the same assertion behavior as an empty schema.

See JSON Schema Core §11.2.

§type_: Option<TypeValue>

The type keyword — instance type constraint.

The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.

String values MUST be one of the six primitive types ("null", "boolean", "object", "array", "number", or "string"), or "integer" which matches any number with a zero fractional part.

If the value of "type" is a string, then an instance validates successfully if its type matches the type represented by the value of the string. If the value of "type" is an array, then an instance validates successfully if its type matches any of the types indicated by the strings in the array.

See JSON Schema Validation §6.1.1.

§enum_: Option<Vec<Value>>

The enum keyword — enumerated values constraint.

The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.

An instance validates successfully against this keyword if its value is equal to one of the elements in this keyword’s array value.

Elements in the array might be of any type, including null.

See JSON Schema Validation §6.1.2.

§const_: Option<Value>

The const keyword — constant value constraint.

The value of this keyword MAY be of any type, including null.

Use of this keyword is functionally equivalent to an "enum" (Section 6.1.2) with a single value.

An instance validates successfully against this keyword if its value is equal to the value of the keyword.

See JSON Schema Validation §6.1.3.

§minimum: Option<Number>

The minimum keyword — inclusive lower bound.

The value of "minimum" MUST be a number, representing an inclusive lower limit for a numeric instance.

If the instance is a number, then this keyword validates only if the instance is greater than or exactly equal to "minimum".

See JSON Schema Validation §6.2.4.

§maximum: Option<Number>

The maximum keyword — inclusive upper bound.

The value of "maximum" MUST be a number, representing an inclusive upper limit for a numeric instance.

If the instance is a number, then this keyword validates only if the instance is less than or exactly equal to "maximum".

See JSON Schema Validation §6.2.2.

§exclusive_minimum: Option<Number>

The exclusiveMinimum keyword — exclusive lower bound.

The value of "exclusiveMinimum" MUST be a number, representing an exclusive lower limit for a numeric instance.

If the instance is a number, then the instance is valid only if it has a value strictly greater than (not equal to) "exclusiveMinimum".

See JSON Schema Validation §6.2.5.

§exclusive_maximum: Option<Number>

The exclusiveMaximum keyword — exclusive upper bound.

The value of "exclusiveMaximum" MUST be a number, representing an exclusive upper limit for a numeric instance.

If the instance is a number, then the instance is valid only if it has a value strictly less than (not equal to) "exclusiveMaximum".

See JSON Schema Validation §6.2.3.

§multiple_of: Option<Number>

The multipleOf keyword — divisibility constraint.

The value of "multipleOf" MUST be a number, strictly greater than 0.

A numeric instance is valid only if division by this keyword’s value results in an integer.

See JSON Schema Validation §6.2.1.

§min_length: Option<u64>

The minLength keyword — minimum string length.

The value of this keyword MUST be a non-negative integer.

A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.

The length of a string instance is defined as the number of its characters as defined by RFC 8259.

Omitting this keyword has the same behavior as a value of 0.

See JSON Schema Validation §6.3.2.

§max_length: Option<u64>

The maxLength keyword — maximum string length.

The value of this keyword MUST be a non-negative integer.

A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.

The length of a string instance is defined as the number of its characters as defined by RFC 8259.

See JSON Schema Validation §6.3.1.

§pattern: Option<String>

The pattern keyword — regex constraint.

The value of this keyword MUST be a string. This string SHOULD be a valid regular expression, according to the ECMA-262 regular expression dialect.

A string instance is considered valid if the regular expression matches the instance successfully. Recall: regular expressions are not implicitly anchored.

See JSON Schema Validation §6.3.3.

§min_items: Option<u64>

The minItems keyword — minimum array length.

The value of this keyword MUST be a non-negative integer.

An array instance is valid against "minItems" if its size is greater than, or equal to, the value of this keyword.

Omitting this keyword has the same behavior as a value of 0.

See JSON Schema Validation §6.4.2.

§max_items: Option<u64>

The maxItems keyword — maximum array length.

The value of this keyword MUST be a non-negative integer.

An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.

See JSON Schema Validation §6.4.1.

§unique_items: bool

The uniqueItems keyword — array element uniqueness.

The value of this keyword MUST be a boolean.

If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.

Omitting this keyword has the same behavior as a value of false.

See JSON Schema Validation §6.4.3.

§min_contains: Option<u64>

The minContains keyword — minimum contains matches.

The value of this keyword MUST be a non-negative integer.

If "contains" is not present within the same schema object, then this keyword has no effect.

An instance array is valid against "minContains" in two ways, depending on the form of the annotation result of an adjacent "contains" keyword. The first way is if the annotation result is an array and the length of that array is greater than or equal to the "minContains" value. The second way is if the annotation result is a boolean true and the instance array length is greater than or equal to the "minContains" value.

A value of 0 is allowed, but is only useful for setting a range of occurrences from 0 to the value of "maxContains". A value of 0 causes "minContains" and "contains" to always pass validation (but validation can still fail against a "maxContains" keyword).

Omitting this keyword has the same behavior as a value of 1.

See JSON Schema Validation §6.4.5.

§max_contains: Option<u64>

The maxContains keyword — maximum contains matches.

The value of this keyword MUST be a non-negative integer.

If "contains" is not present within the same schema object, then this keyword has no effect.

An instance array is valid against "maxContains" in two ways, depending on the form of the annotation result of an adjacent "contains" keyword. The first way is if the annotation result is an array and the length of that array is less than or equal to the "maxContains" value. The second way is if the annotation result is a boolean true and the instance array length is less than or equal to the "maxContains" value.

See JSON Schema Validation §6.4.4.

§required: Option<Vec<String>>

The required keyword — required property names.

The value of this keyword MUST be an array. Elements of this array, if any, MUST be strings, and MUST be unique.

An object instance is valid against this keyword if every item in the array is the name of a property in the instance.

Omitting this keyword has the same behavior as an empty array.

See JSON Schema Validation §6.5.3.

§min_properties: Option<u64>

The minProperties keyword — minimum property count.

The value of this keyword MUST be a non-negative integer.

An object instance is valid against "minProperties" if its number of properties is greater than, or equal to, the value of this keyword.

Omitting this keyword has the same behavior as a value of 0.

See JSON Schema Validation §6.5.2.

§max_properties: Option<u64>

The maxProperties keyword — maximum property count.

The value of this keyword MUST be a non-negative integer.

An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.

See JSON Schema Validation §6.5.1.

§dependent_required: Option<IndexMap<String, Vec<String>>>

The dependentRequired keyword — conditional required properties.

The value of this keyword MUST be an object. Properties in this object, if any, MUST be arrays. Elements in each array, if any, MUST be strings, and MUST be unique.

This keyword specifies properties that are required if a specific other property is present. Their requirement is dependent on the presence of the other property.

Validation succeeds if, for each name that appears in both the instance and as a name within this keyword’s value, every item in the corresponding array is also the name of a property in the instance.

Omitting this keyword has the same behavior as an empty object.

See JSON Schema Validation §6.5.4.

§title: Option<String>

The title keyword — short summary annotation.

The value of this keyword MUST be a string.

Both "title" and "description" can be used to decorate a user interface with information about the data produced by this user interface. A title will preferably be short, whereas a description will provide explanation about the purpose of the instance described by this schema.

See JSON Schema Validation §9.1.

§description: Option<String>

The description keyword — explanatory annotation.

The value of this keyword MUST be a string.

Both "title" and "description" can be used to decorate a user interface with information about the data produced by this user interface. A title will preferably be short, whereas a description will provide explanation about the purpose of the instance described by this schema.

See JSON Schema Validation §9.1.

§default: Option<Value>

The default keyword — default value annotation.

There are no restrictions placed on the value of this keyword. When multiple occurrences of this keyword are applicable to a single sub-instance, implementations SHOULD remove duplicates.

This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.

See JSON Schema Validation §9.2.

§deprecated: bool

The deprecated keyword — deprecation annotation.

The value of this keyword MUST be a boolean. When multiple occurrences of this keyword are applicable to a single sub-instance, applications SHOULD consider the instance location to be deprecated if any occurrence specifies a true value.

If "deprecated" has a value of boolean true, it indicates that applications SHOULD refrain from usage of the declared property. It MAY mean the property is going to be removed in the future.

A root schema containing "deprecated" with a value of true indicates that the entire resource being described MAY be removed in the future.

The "deprecated" keyword applies to each instance location to which the schema object containing the keyword successfully applies. This can result in scenarios where every array item or object property is deprecated even though the containing array or object is not.

Omitting this keyword has the same behavior as a value of false.

See JSON Schema Validation §9.3.

§read_only: bool

The readOnly keyword — read-only annotation.

The value of this keyword MUST be a boolean. When multiple occurrences of this keyword are applicable to a single sub-instance, the resulting behavior SHOULD be as for a true value if any occurrence specifies a true value, and SHOULD be as for a false value otherwise.

If "readOnly" has a value of boolean true, it indicates that the value of the instance is managed exclusively by the owning authority, and attempts by an application to modify the value of this property are expected to be ignored or rejected by that owning authority.

An instance document that is marked as "readOnly" for the entire document MAY be ignored if sent to the owning authority, or MAY result in an error, at the authority’s discretion.

Omitting this keyword has the same behavior as a value of false.

See JSON Schema Validation §9.4.

§write_only: bool

The writeOnly keyword — write-only annotation.

The value of this keyword MUST be a boolean.

If "writeOnly" has a value of boolean true, it indicates that the value is never present when the instance is retrieved from the owning authority. It can be present when sent to the owning authority to update or create the document (or the resource it represents), but it will not be included in any updated or newly created version of the instance.

An instance document that is marked as "writeOnly" for the entire document MAY be returned as a blank document of some sort, or MAY produce an error upon retrieval, or have the retrieval request ignored, at the authority’s discretion.

Omitting this keyword has the same behavior as a value of false.

See JSON Schema Validation §9.4.

§examples: Option<Vec<Value>>

The examples keyword — example values annotation.

The value of this keyword MUST be an array. There are no restrictions placed on the values within the array. When multiple occurrences of this keyword are applicable to a single sub-instance, implementations MUST provide a flat array of all values rather than an array of arrays.

This keyword can be used to provide sample JSON values associated with a particular schema, for the purpose of illustrating usage. It is RECOMMENDED that these values be valid against the associated schema.

Implementations MAY use the value(s) of "default", if present, as an additional example. If "examples" is absent, "default" MAY still be used in this manner.

See JSON Schema Validation §9.5.

§format: Option<String>

The format keyword — semantic format annotation.

Structural validation alone may be insufficient to allow an application to correctly utilize certain values. The "format" annotation keyword is defined to allow schema authors to convey semantic information for a fixed subset of values which are accurately described by authoritative resources, be they RFCs or other external specifications.

The value of this keyword is called a format attribute. It MUST be a string.

See JSON Schema Validation §7.

§content_media_type: Option<String>

The contentMediaType keyword — media type of string content.

If the instance is a string, this property indicates the media type of the contents of the string. If "contentEncoding" is present, this property describes the decoded string.

The value of this property MUST be a string, which MUST be a media type, as defined by RFC 2046.

See JSON Schema Validation §8.4.

§content_encoding: Option<String>

The contentEncoding keyword — encoding of string content.

If the instance value is a string, this property defines that the string SHOULD be interpreted as encoded binary data and decoded using the encoding named by this property.

Possible values indicating base 16, 32, and 64 encodings with several variations are listed in RFC 4648. Additionally, sections 6.7 and 6.8 of RFC 2045 provide encodings used in MIME.

If this keyword is absent, but "contentMediaType" is present, this indicates that the encoding is the identity encoding, meaning that no transformation was needed in order to represent the content in a UTF-8 string.

The value of this property MUST be a string.

See JSON Schema Validation §8.3.

§content_schema: Option<Box<SchemaValue>>

The contentSchema keyword — schema for decoded string content.

If the instance is a string, and if "contentMediaType" is present, this property contains a schema which describes the structure of the string.

This keyword MAY be used with any media type that can be mapped into JSON Schema’s data model.

The value of this property MUST be a valid JSON schema. It SHOULD be ignored if "contentMediaType" is not present.

See JSON Schema Validation §8.5.

§markdown_description: Option<String>

The markdownDescription keyword — Markdown-formatted description (VS Code / non-standard extension).

Not part of the JSON Schema specification. When present, it is preferred over description by editors that support Markdown rendering.

§markdown_enum_descriptions: Option<Vec<Option<String>>>

Per-enum-value Markdown descriptions (VS Code / non-standard extension).

§x_lintel: Option<LintelSchemaExt>

Lintel provenance metadata (x-lintel).

§x_taplo: Option<TaploSchemaExt>

Taplo TOML toolkit extension (x-taplo).

§x_taplo_info: Option<TaploInfoSchemaExt>

Taplo informational metadata (x-taplo-info).

§x_tombi: TombiSchemaExt

Tombi TOML extensions (x-tombi-*).

§x_intellij: IntellijSchemaExt

IntelliJ IDEA extensions (x-intellij-*).

§extra: BTreeMap<String, Value>

Unknown or unsupported properties.

Any JSON property that is not recognized as a standard keyword or known extension is captured here, preserving round-trip fidelity.

Implementations§

Source§

impl Schema

Source

pub fn from_value(value: Value) -> Result<Self, Error>

Parse from a serde_json::Value without migration.

§Errors

Returns an error if the value cannot be deserialized into a Schema.

Source

pub fn description(&self) -> Option<&str>

Get the best description text, preferring markdownDescription.

Source

pub fn required_set(&self) -> &[String]

Get the required fields, or an empty slice.

Source

pub fn is_deprecated(&self) -> bool

Whether this schema is deprecated.

Source

pub fn type_str(&self) -> Option<String>

Produce a short human-readable type string.

Source

pub fn validate(&self) -> Vec<SchemaError>

Validate structural integrity of this schema.

Recursively walks the schema tree and checks that all local $ref pointers (starting with #/) resolve to valid targets.

Source

pub fn absolute(&self) -> Schema

Rewrite all local $ref pointers (#/…) to absolute URLs using the schema’s $id as base. Returns the schema unchanged if $id is absent.

Source

pub fn flatten(&self, root: &SchemaValue) -> Schema

Flatten composition keywords (currently allOf) into a single merged schema.

Properties from allOf entries are merged into the root, and unreferenced $defs entries are pruned. The allOf array is preserved so provenance remains visible.

Source

pub fn get_keyword(&self, key: &str) -> Option<&SchemaValue>

Look up a schema-keyword field by its JSON key name.

Returns a reference to the SchemaValue stored under that keyword, or None if the field is absent.

Source

pub fn get_map_entry(&self, keyword: &str, key: &str) -> Option<&SchemaValue>

Look up a named child within a keyword that holds a map of schemas.

For example, get_map_entry("properties", "name") returns the schema for the name property.

Source

pub fn get_array_entry( &self, keyword: &str, index: usize, ) -> Option<&SchemaValue>

Look up an indexed child within a keyword that holds an array of schemas.

Trait Implementations§

Source§

impl Add for Schema

Source§

fn add(self, rhs: Self) -> Self

Merge two schemas with left-bias.

  • Map fields (properties, pattern_properties, defs, dependent_schemas): merge — rhs entries added only if key doesn’t exist in self.
  • required: union (deduplicate).
  • extra (BTreeMap catch-all): merge — rhs entries added only if key doesn’t exist.
  • All other Option<T> fields: self.field.or(rhs.field) — left wins.
  • bool fields: self.field || rhs.field — true wins.
Source§

type Output = Schema

The resulting type after applying the + operator.
Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Schema

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Schema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for Schema

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

Generates a JSON Schema for this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for Schema

Source§

fn eq(&self, other: &Schema) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Schema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Schema

Source§

impl StructuralPartialEq for Schema

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,