1[ 2 { 3 "description": "root pointer ref", 4 "schema": { 5 "properties": { 6 "foo": {"$ref": "#"} 7 }, 8 "additionalProperties": false 9 }, 10 "tests": [ 11 { 12 "description": "match", 13 "data": {"foo": false}, 14 "valid": true 15 }, 16 { 17 "description": "recursive match", 18 "data": {"foo": {"foo": false}}, 19 "valid": true 20 }, 21 { 22 "description": "mismatch", 23 "data": {"bar": false}, 24 "valid": false 25 }, 26 { 27 "description": "recursive mismatch", 28 "data": {"foo": {"bar": false}}, 29 "valid": false 30 } 31 ] 32 }, 33 { 34 "description": "relative pointer ref to object", 35 "schema": { 36 "properties": { 37 "foo": {"type": "integer"}, 38 "bar": {"$ref": "#/properties/foo"} 39 } 40 }, 41 "tests": [ 42 { 43 "description": "match", 44 "data": {"bar": 3}, 45 "valid": true 46 }, 47 { 48 "description": "mismatch", 49 "data": {"bar": true}, 50 "valid": false 51 } 52 ] 53 }, 54 { 55 "description": "relative pointer ref to array", 56 "schema": { 57 "items": [ 58 {"type": "integer"}, 59 {"$ref": "#/items/0"} 60 ] 61 }, 62 "tests": [ 63 { 64 "description": "match array", 65 "data": [1, 2], 66 "valid": true 67 }, 68 { 69 "description": "mismatch array", 70 "data": [1, "foo"], 71 "valid": false 72 } 73 ] 74 }, 75 { 76 "description": "escaped pointer ref", 77 "schema": { 78 "definitions": { 79 "tilde~field": {"type": "integer"}, 80 "slash/field": {"type": "integer"}, 81 "percent%field": {"type": "integer"} 82 }, 83 "properties": { 84 "tilde": {"$ref": "#/definitions/tilde~0field"}, 85 "slash": {"$ref": "#/definitions/slash~1field"}, 86 "percent": {"$ref": "#/definitions/percent%25field"} 87 } 88 }, 89 "tests": [ 90 { 91 "description": "slash invalid", 92 "data": {"slash": "aoeu"}, 93 "valid": false 94 }, 95 { 96 "description": "tilde invalid", 97 "data": {"tilde": "aoeu"}, 98 "valid": false 99 }, 100 { 101 "description": "percent invalid", 102 "data": {"percent": "aoeu"}, 103 "valid": false 104 }, 105 { 106 "description": "slash valid", 107 "data": {"slash": 123}, 108 "valid": true 109 }, 110 { 111 "description": "tilde valid", 112 "data": {"tilde": 123}, 113 "valid": true 114 }, 115 { 116 "description": "percent valid", 117 "data": {"percent": 123}, 118 "valid": true 119 } 120 ] 121 }, 122 { 123 "description": "nested refs", 124 "schema": { 125 "definitions": { 126 "a": {"type": "integer"}, 127 "b": {"$ref": "#/definitions/a"}, 128 "c": {"$ref": "#/definitions/b"} 129 }, 130 "$ref": "#/definitions/c" 131 }, 132 "tests": [ 133 { 134 "description": "nested ref valid", 135 "data": 5, 136 "valid": true 137 }, 138 { 139 "description": "nested ref invalid", 140 "data": "a", 141 "valid": false 142 } 143 ] 144 }, 145 { 146 "description": "ref overrides any sibling keywords", 147 "schema": { 148 "definitions": { 149 "reffed": { 150 "type": "array" 151 } 152 }, 153 "properties": { 154 "foo": { 155 "$ref": "#/definitions/reffed", 156 "maxItems": 2 157 } 158 } 159 }, 160 "tests": [ 161 { 162 "description": "remote ref valid", 163 "data": { "foo": [] }, 164 "valid": true 165 }, 166 { 167 "description": "remote ref valid, maxItems ignored", 168 "data": { "foo": [ 1, 2, 3] }, 169 "valid": true 170 }, 171 { 172 "description": "ref invalid", 173 "data": { "foo": "string" }, 174 "valid": false 175 } 176 ] 177 }, 178 { 179 "description": "property named $ref, containing an actual $ref", 180 "schema": { 181 "properties": { 182 "$ref": {"$ref": "#/definitions/is-string"} 183 }, 184 "definitions": { 185 "is-string": { 186 "type": "string" 187 } 188 } 189 }, 190 "tests": [ 191 { 192 "description": "property named $ref valid", 193 "data": {"$ref": "a"}, 194 "valid": true 195 }, 196 { 197 "description": "property named $ref invalid", 198 "data": {"$ref": 2}, 199 "valid": false 200 } 201 ] 202 }, 203 { 204 "description": "$ref prevents a sibling id from changing the base uri", 205 "schema": { 206 "id": "http://localhost:1234/sibling_id/base/", 207 "definitions": { 208 "foo": { 209 "id": "http://localhost:1234/sibling_id/foo.json", 210 "type": "string" 211 }, 212 "base_foo": { 213 "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json", 214 "id": "foo.json", 215 "type": "number" 216 } 217 }, 218 "extends": [ 219 { 220 "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json", 221 "id": "http://localhost:1234/sibling_id/", 222 "$ref": "foo.json" 223 } 224 ] 225 }, 226 "tests": [ 227 { 228 "description": "$ref resolves to /definitions/base_foo, data does not validate", 229 "data": "a", 230 "valid": false 231 }, 232 { 233 "description": "$ref resolves to /definitions/base_foo, data validates", 234 "data": 1, 235 "valid": true 236 } 237 ] 238 }, 239 { 240 "description": "remote ref, containing refs itself", 241 "schema": {"$ref": "http://json-schema.org/draft-03/schema#"}, 242 "tests": [ 243 { 244 "description": "remote ref valid", 245 "data": {"items": {"type": "integer"}}, 246 "valid": true 247 }, 248 { 249 "description": "remote ref invalid", 250 "data": {"items": {"type": 1}}, 251 "valid": false 252 } 253 ] 254 }, 255 { 256 "description": "naive replacement of $ref with its destination is not correct", 257 "schema": { 258 "definitions": { 259 "a_string": { "type": "string" } 260 }, 261 "enum": [ 262 { "$ref": "#/definitions/a_string" } 263 ] 264 }, 265 "tests": [ 266 { 267 "description": "do not evaluate the $ref inside the enum, matching any string", 268 "data": "this is a string", 269 "valid": false 270 }, 271 { 272 "description": "match the enum exactly", 273 "data": { "$ref": "#/definitions/a_string" }, 274 "valid": true 275 } 276 ] 277 } 278] 279