1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
-- schema.json --
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"title": "Main schema",
"description": "Specify who you are and all.",
"$defs": {
"address": {
"description": "address stores a postal address",
"type": "string",
"minLength": 4,
"maxLength": 20
},
"phone number": {
"description": "a telephone number",
"type": "string"
}
},
"properties": {
"person": {
"description": "A person is a human being.",
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"examples": [
"foo"
]
},
"address": {
"description": "where does this person live?",
"$ref": "#/$defs/address"
},
"children": {
"description": "A very large comment that will be wrapped after a certain line length. Let's keep on going and see what happens.",
"type": "array",
"items": {
"type": "string"
},
"default": []
},
"home phone": {
"$ref": "#/$defs/phone number",
"deprecated": true
}
}
}
}
}
-- out/decode/extract --
// Main schema
//
// Specify who you are and all.
import "strings"
@jsonschema(schema="https://json-schema.org/draft/2019-09/schema")
// A person is a human being.
person?: {
name!: string
// where does this person live?
address?: #address
// A very large comment that will be wrapped after a certain line
// length. Let's keep on going and see what happens.
children?: [...string]
"home phone"?: #."phone number" @deprecated()
...
}
// a telephone number
#: "phone number": string
// address stores a postal address
#address: strings.MinRunes(4) & strings.MaxRunes(20)
...
|