cuelang.org/go@v0.13.0/encoding/jsonschema/testdata/txtar/ref.txtar (about) 1 // This test tests the conversion and ordering of $defs. 2 3 #noverify 4 5 -- schema.json -- 6 { 7 "$schema": "http://json-schema.org/draft-07/schema#", 8 9 "$id": "http://cuelang.org/go/encoding/openapi/testdata/order.json", 10 11 "$defs": { 12 "address": { 13 "type": "object", 14 "properties": { 15 "city": { "type": "string" } 16 } 17 }, 18 "int": { 19 "type": "integer" 20 }, 21 "string-int": { 22 "type": [ "integer", "string" ] 23 }, 24 "person": { 25 "type": "object", 26 "properties": { 27 "name": { "type": "string" }, 28 "children": { 29 "type": "object", 30 "properties": { 31 "x": { "$ref": "http://acme.com/external.json#/properties/foo" }, 32 33 "a": { "$ref": "#/$defs/int" }, 34 "b": { "$ref": "http://cuelang.org/person.json#/$defs/int" }, 35 "c": { "$ref": "http://cuelang.org/go/encoding/openapi/testdata/order.json#/$defs/int" }, 36 "d": { "$ref": "http://cuelang.org/go/encoding/openapi/testdata/order.json#/$defs/address" }, 37 "e": { "$ref": "http://cuelang.org/go/encoding/openapi/testdata/order.json#/$defs/string-int" }, 38 "f": { "$ref": "http://cuelang.org/person.json" }, 39 "g": { "$ref": "http://acme.com/external.json#/definitions/foo" }, 40 "h": { "$ref": "http://acme.com/external.json#/properties/foo" }, 41 "i": { "$ref": "http://acme.com/external.json" }, 42 "j": { "$ref": "http://acme.com/external-foo.json" }, 43 "k": { "$ref": "http://acme.com/external-bar.json" }, 44 "z": {} 45 } 46 } 47 }, 48 "$id": "http://cuelang.org/person.json", 49 "$defs": { 50 "int": { 51 "type": "integer" 52 } 53 } 54 } 55 }, 56 57 "type": "object", 58 59 "properties": { 60 "person": { "$ref": "#/$defs/person" }, 61 "billing_address": { "$ref": "#/$defs/address" }, 62 "shipping_address": { "$ref": "#/$defs/address" } 63 } 64 } 65 66 -- out/decode/extract -- 67 import ( 68 "acme.com/external.json:external" 69 "acme.com/external-foo.json:schema" 70 schema_1 "acme.com/external-bar.json:schema" 71 ) 72 73 @jsonschema(schema="http://json-schema.org/draft-07/schema#") 74 @jsonschema(id="http://cuelang.org/go/encoding/openapi/testdata/order.json") 75 person?: #person 76 billing_address?: #address 77 shipping_address?: #address 78 79 #: "string-int": int | string 80 81 #address: { 82 city?: string 83 ... 84 } 85 86 #int: int 87 88 #person: { 89 @jsonschema(id="http://cuelang.org/person.json") 90 name?: string 91 children?: { 92 x?: external._#defs."/properties/foo" 93 a?: _#defs."/$defs/person/$defs/int" 94 b?: _#defs."/$defs/person/$defs/int" 95 c?: #int 96 d?: #address 97 e?: #."string-int" 98 f?: #person 99 g?: external.#foo 100 h?: external._#defs."/properties/foo" 101 i?: external 102 j?: schema 103 k?: schema_1 104 z?: _ 105 ... 106 } 107 ... 108 } 109 110 _#defs: "/$defs/person/$defs/int": int 111 ...