$ref uses JSON Pointer (RFC6901)
Annotation keywords (optional)
title
description
default
examples
$comment
Type keywords & constraints
- a type, or an array of types (union)
Types & common refinement keywords:
- string:
- length: minLength, maxLength,
- pattern: /regular expression/, regex (new)
- (formats): date-time, time, date (RFC3339/ISO8601)
- email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, iri, iri-reference, uri-template
- contentMediaType, contentEncoding
- json-pointer (for complex JSON), relative-json-pointer
- number: integer, number
- multipleOf, minimum, maximum, exclusiveMinimum, exclusiveMaximum
- boolean, null
- object (always string keys):
- properties - define properties, by default OPTIONAL
- additionalProperties
- true/false, allow additional properties
- an schema: validate against additional properties' values
- patternProperties: match property name, then specify constraint
- required - an array of required property names
- propertyNames - {"pattern":"someRegexPattern"} enforce property names
- minProperties / maxProperties - restrict number of properties
- dependencies
- property dependencies: if one property is present, the other is required as well
- schema dependencies: also define dependent property's other constraints
- array (list validation / tuple validation):
- additionalItems: ok or not for tuple to contain additional items
- minItems, maxItems, uniqueItems
- items:
- {...} a schema, list validation,
- [ {...}, {...}, {...} ] - an array of schema, tuple validation
- by default ok if partial / additional elements
- contains: only requires contain (not every) item
Constraint common to all types:
- enum - an array of enum values
- constant - constant, (enum of only one)
Accept an array of schema and combine:
- allOf
- not used to extend schema, since adding "required" and requires "additionalProperties" would break
- anyOf
- oneOf - one and only one
- not - not any of
if-then-else