Skip to content

Interface: JSONSchema ​

A JSON Schema (drafts 04 to 2020-12), or an OpenAPI 3.0/3.1 schema object (the schemas of the property maps are objects: a boolean schema can be written as {} or {not: {}}). Returned by toJsonSchema() and DTO.toJsonSchema(), accepted by fromJsonSchema() and DTO.fromJsonSchema(). The keywords not listed (the extensions, x-...) are allowed as well.

Indexable ​

[keyword: string]: unknown

Properties ​

$anchor? ​

optional $anchor?: string

A plain name identifying the schema in its document, which a reference reaches as #name (draft 2019-09 and later).


$comment? ​

optional $comment?: string

A comment for the schema maintainers, ignored by the validation.


$defs? ​

optional $defs?: Record<string, JSONSchema>

The reusable schemas, by name, which the references reach as #/$defs/<name> (draft 2019-09 and later).


$dynamicAnchor? ​

optional $dynamicAnchor?: string

A name which the $dynamicRef references resolve to dynamically (draft 2020-12).


$dynamicRef? ​

optional $dynamicRef?: string

A reference resolved in the dynamic scope of the validation, to the $dynamicAnchor of the same name (draft 2020-12).


$id? ​

optional $id?: string

The URI identifying the schema, which the references ($ref) of other schemas can point to (drafts 06 and later).


$recursiveAnchor? ​

optional $recursiveAnchor?: boolean

Whether the schema is a target of the $recursiveRef references (draft 2019-09).


$recursiveRef? ​

optional $recursiveRef?: string

A reference resolved in the dynamic scope of the validation, to the schemas marked with $recursiveAnchor (draft 2019-09).


$ref? ​

optional $ref?: string

A reference to another schema, by URI or JSON pointer (#/$defs/User), which the value must match too.


$schema? ​

optional $schema?: string

The URI of the JSON Schema version (dialect) the schema is written in, like https://json-schema.org/draft/2020-12/schema.


additionalItems? ​

optional additionalItems?: JSONSchemaDefinition

The schema of the items following the ones items lists as an array (drafts 04 to 2019-09).


additionalProperties? ​

optional additionalProperties?: JSONSchemaDefinition

The schema of the properties neither properties nor patternProperties list; false forbids them.


allOf? ​

optional allOf?: JSONSchemaDefinition[]

The schemas the value must all match.


anyOf? ​

optional anyOf?: JSONSchemaDefinition[]

The schemas the value must match at least one of.


const? ​

optional const?: unknown

The only value allowed.


contains? ​

optional contains?: JSONSchemaDefinition

A schema at least one item of an array value must match (minContains and maxContains change the count).


contentEncoding? ​

optional contentEncoding?: string

The encoding of the content of a string value, like base64.


contentMediaType? ​

optional contentMediaType?: string

The media type of the content of a string value, like application/json.


default? ​

optional default?: unknown

The value used when it is missing (a schema imported by fromJsonSchema() applies it).


definitions? ​

optional definitions?: Record<string, JSONSchema>

The reusable schemas, by name, which the references reach as #/definitions/<name> (drafts 04 to 07).


dependencies? ​

optional dependencies?: Record<string, JSONSchema | string[]>

By property name: when the property is present, the properties listed must be too, or the object must match the schema (drafts 04 to 07, split into dependentRequired and dependentSchemas in draft 2019-09).


dependentRequired? ​

optional dependentRequired?: Record<string, string[]>

By property name: the properties an object value must have when it has that property (draft 2019-09 and later).


dependentSchemas? ​

optional dependentSchemas?: Record<string, JSONSchema>

By property name: the schema an object value must match when it has that property (draft 2019-09 and later).


deprecated? ​

optional deprecated?: boolean

Whether the value should not be used any more (draft 2019-09 and later, OpenAPI).

Default ​

ts
false

description? ​

optional description?: string

A description of the value, for documentation.


else? ​

optional else?: JSONSchemaDefinition

The schema a value not matching if must match.


enum? ​

optional enum?: unknown[]

The only values allowed.


example? ​

optional example?: unknown

An example value, for documentation (OpenAPI).


examples? ​

optional examples?: unknown[]

Example values, for documentation.


exclusiveMaximum? ​

optional exclusiveMaximum?: number | boolean

The limit a numeric value must be lower than (a number from draft 06), or in draft 04 and OpenAPI 3.0 whether maximum is exclusive (a boolean).


exclusiveMinimum? ​

optional exclusiveMinimum?: number | boolean

The limit a numeric value must be greater than (a number from draft 06), or in draft 04 and OpenAPI 3.0 whether minimum is exclusive (a boolean).


format? ​

optional format?: string

The format of a string value: date-time, email, uri, uuid, ipv4…


id? ​

optional id?: string

The URI identifying the schema in draft 04 (replaced by $id in the later drafts).


if? ​

optional if?: JSONSchemaDefinition

A condition: a value matching it must match then, the others else (draft 07 and later).


items? ​

optional items?: JSONSchemaDefinition | JSONSchemaDefinition[]

The schema of every item of an array value; an array of schemas lists the schemas of the first items (drafts 04 to 2019-09, replaced by prefixItems in draft 2020-12).


maxContains? ​

optional maxContains?: number

The maximum number of items matching contains (draft 2019-09 and later).


maximum? ​

optional maximum?: number

The largest numeric value allowed (inclusive).


maxItems? ​

optional maxItems?: number

The maximum number of items of an array value.


maxLength? ​

optional maxLength?: number

The maximum length of a string value, in characters (Unicode code points).


maxProperties? ​

optional maxProperties?: number

The maximum number of properties of an object value.


minContains? ​

optional minContains?: number

The minimum number of items matching contains (draft 2019-09 and later).

Default ​

ts
1

minimum? ​

optional minimum?: number

The smallest numeric value allowed (inclusive).


minItems? ​

optional minItems?: number

The minimum number of items of an array value.


minLength? ​

optional minLength?: number

The minimum length of a string value, in characters (Unicode code points).


minProperties? ​

optional minProperties?: number

The minimum number of properties of an object value.


multipleOf? ​

optional multipleOf?: number

The number a numeric value must be a multiple of (greater than 0).


not? ​

optional not?: JSONSchemaDefinition

A schema the value must not match.


nullable? ​

optional nullable?: boolean

Whether the value may be null as well as of its type (OpenAPI 3.0; the later versions add null to type).

Default ​

ts
false

oneOf? ​

optional oneOf?: JSONSchemaDefinition[]

The schemas the value must match exactly one of.


pattern? ​

optional pattern?: string

The regular expression (ECMA 262) a string value must match, anywhere in the string unless anchored.


patternProperties? ​

optional patternProperties?: Record<string, JSONSchema>

The schemas of the properties whose name matches a regular expression, by regular expression.


prefixItems? ​

optional prefixItems?: JSONSchemaDefinition[]

The schemas of the first items of an array value, in order (draft 2020-12).


properties? ​

optional properties?: Record<string, JSONSchema>

The schemas of the properties of an object value, by property name.


propertyNames? ​

optional propertyNames?: JSONSchemaDefinition

The schema every property name of an object value must match.


readOnly? ​

optional readOnly?: boolean

Whether the value is managed by its owner and is ignored when sent to it.

Default ​

ts
false

required? ​

optional required?: string[]

The names of the properties an object value must have.


then? ​

optional then?: JSONSchemaDefinition

The schema a value matching if must match.


title? ​

optional title?: string

A short title of the value, for documentation.


type? ​

optional type?: JSONSchemaTypeName | JSONSchemaTypeName[]

The type of the value, or the types it may have.


unevaluatedItems? ​

optional unevaluatedItems?: JSONSchemaDefinition

The schema of the array items no other keyword evaluated (draft 2019-09 and later).


unevaluatedProperties? ​

optional unevaluatedProperties?: JSONSchemaDefinition

The schema of the properties no other keyword evaluated (draft 2019-09 and later).


uniqueItems? ​

optional uniqueItems?: boolean

Whether the items of an array value must all be different.

Default ​

ts
false

writeOnly? ​

optional writeOnly?: boolean

Whether the value is only sent to its owner and never returned by it (a password).

Default ​

ts
false

Released under the MIT License.