| •1 |
; root-schema is identical to schema, but additionally allows for |
| 2 |
; definitions. |
| 3 |
; |
| 4 |
; definitions are prohibited from appearing on non-root schemas. |
| 5 |
root-schema = { |
| 6 |
? definitions: { * tstr => { schema}}, |
| 7 |
schema, |
| 8 |
} |
| 9 |
|
| 10 |
; schema is the main CDDL rule defining a JTD schema. |
| 11 |
; |
| 12 |
; All JTD schemas are JSON objects taking on one of eight forms |
| 13 |
; listed here. |
| 14 |
schema = ( |
| 15 |
ref // |
| 16 |
type // |
| 17 |
enum // |
| 18 |
elements // |
| 19 |
properties // |
| 20 |
values // |
| 21 |
discriminator // |
| 22 |
empty // |
| 23 |
) |
| 24 |
|
| 25 |
; shared is a CDDL rule containing properties that all eight schema |
| 26 |
; forms share. |
| 27 |
shared = ( |
| 28 |
? metadata: { * tstr => any }, |
| 29 |
? nullable: bool, |
| 30 |
) |
| 31 |
|
| 32 |
; empty describes the "empty" schema form. |
| 33 |
empty = shared |
| 34 |
|
| 35 |
; ref describes the "ref" schema form. |
| 36 |
; |
| 37 |
; There are additional constraints on this form that cannot be |
| 38 |
; expressed in CDDL. Section 2.2.2 describes these additional |
| 39 |
; constraints in detail. |
| 40 |
ref = ( ref: tstr, shared ) |
| 41 |
|
| 42 |
; type describes the "type" schema form. |
| 43 |
type = ( |
| 44 |
type: "boolean" |
| 45 |
/ "float32" |
| 46 |
/ "float64" |
| 47 |
/ "int8" |
| 48 |
/ "uint8" |
| 49 |
/ "int16" |
| 50 |
/ "uint16" |
| 51 |
/ "int32" |
| 52 |
/ "uint32" |
| 53 |
/ "string" |
| 54 |
/ "timestamp", |
| 55 |
shared, |
| 56 |
) |
| 57 |
|
| 58 |
; enum describes the "enum" schema form. |
| 59 |
; |
| 60 |
; There are additional constraints on this form that cannot be |
| 61 |
; expressed in CDDL. Section 2.2.4 describes these additional |
| 62 |
; constraints in detail. |
| 63 |
enum = ( enum: [+ tstr], shared ) |
| 64 |
|
| 65 |
; elements describes the "elements" schema form. |
| 66 |
elements = ( elements: { schema }, shared ) |
| 67 |
|
| 68 |
; properties describes the "properties" schema form. |
| 69 |
; |
| 70 |
; This CDDL rule is defined so that a schema of the "properties" form |
| 71 |
; may omit a member named "properties" or a member named |
| 72 |
; "optionalProperties", but not both. |
| 73 |
; |
| 74 |
; There are additional constraints on this form that cannot be |
| 75 |
; expressed in CDDL. Section 2.2.6 describes these additional |
| 76 |
; constraints in detail. |
| 77 |
properties = (with-properties // with-optional-properties) |
| 78 |
|
| 79 |
with-properties = ( |
| 80 |
properties: { * tstr => { schema }}, |
| 81 |
? optionalProperties: { * tstr => { schema }}, |
| 82 |
? additionalProperties: bool, |
| 83 |
shared, |
| 84 |
) |
| 85 |
|
| 86 |
with-optional-properties = ( |
| 87 |
? properties: { * tstr => { schema }}, |
| 88 |
optionalProperties: { * tstr => { schema }}, |
| 89 |
? additionalProperties: bool, |
| 90 |
shared, |
| 91 |
) |
| 92 |
|
| 93 |
; values describes the "values" schema form. |
| 94 |
values = ( values: { schema }, shared ) |
| 95 |
|
| 96 |
; discriminator describes the "discriminator" schema form. |
| 97 |
; |
| 98 |
; There are additional constraints on this form that cannot be |
| 99 |
; expressed in CDDL. Section 2.2.8 describes these additional |
| 100 |
; constraints in detail. |
| 101 |
discriminator = ( |
| 102 |
discriminator: tstr, |
| 103 |
|
| 104 |
; Note well: this rule is defined in terms of the "properties" |
| 105 |
; CDDL rule, not the "schema" CDDL rule. |
| 106 |
mapping: { * tstr => { properties } } |
| 107 |
shared, |
| 108 |
) |