when trying validate following schema using http://www.jsonschemavalidator.net/,
{ "id": "http://some.site.somewhere/entry-schema#", "$schema": "http://json-schema.org/draft-04/schema#", "description": "schema formularspecification", "definitions": { "elementid": { "id": "http://jsonschema.net/elementid", "type": "string" }, "mappingkey": { "id": "http://jsonschema.net/mappingkey", "type": "string" }, "elementtype": { "id": "http://jsonschema.net/elementtype", "type": "string" }, "length": { "id": "http://jsonschema.net/length", "type": "integer" }, "label": { "id": "http://jsonschema.net/label", "type": "string" }, "content": { "id": "http://jsonschema.net/content", "type": "string" }, "placeholder": { "id": "http://jsonschema.net/placeholder", "type": "string" }, "date": { "id": "http://jsonschema.net/date", "type": "string" }, "option": { "id": "http://jsonschema.net/option", "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "label": { "$ref": "#/definitions/label" } }, "required": ["elementid", "label"] }, "options": { "id": "http://jsonschema.net/options", "type": "array", "items": { "$ref": "#/definitions/option" }, "minitems": 1, "uniqueitems": true }, "textfield": { "id": "http://jsonschema.net/textfield", "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "length": { "$ref": "#/definitions/length" }, "label": { "$ref": "#/definitions/label" }, "placeholder": { "$ref": "#/definitions/placeholder" }, "textfieldtype": { "enum": [ "text", "ext4", "btrfs" ] } }, "required": ["elementid", "length", "label", "placeholder", "textfieldtype"] }, "checkbox": { "id": "http://jsonschema.net/checkbox", "type": "object", "properties": { "label": { "$ref": "#/definitions/label" } }, "required": ["label"] }, "radio": { "id": "http://jsonschema.net/radio", "type": "object", "properties": { "label": { "$ref": "#/definitions/label" }, "options": { "$ref": "#/definitions/options" } }, "required": ["label", "options"] }, "dropdown": { "id": "http://jsonschema.net/dropdown", "type": "object", "properties": { "label": { "$ref": "#/definitions/label" }, "options": { "$ref": "#/definitions/options" } }, "required": ["label", "options"] }, "validator": { "id": "http://jsonschema.net/validator", "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" } } }, "validators": { "id": "http://jsonschema.net/validators", "type": "array", "items": { "$ref": "#/definitions/validator" } }, "interactivedetails": { "type": "object", "oneof": [ { "textfield": { "$ref": "#/definitions/textfield" } }, { "checkbox": { "$ref": "#/definitions/checkbox" } }, { "radio": { "$ref": "#/definitions/radio" } }, { "dropdown": { "$ref": "#/definitions/dropdown" } }, { "date": { "$ref": "#/definitions/date" } } ] }, "interactive": { "id": "http://jsonschema.net/interactive", "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "elementtype": { "$ref": "#/definitions/elementtype" }, "mappingkey": { "$ref": "#/definitions/mappingkey" }, "validators": { "$ref": "#/definitions/validators" }, "interactivedetails" : { "$ref": "#/definitions/interactivedetails" } }, "required": ["elementid", "elementtype", "mappingkey", "validators"] }, "interactives": { "id": "http://jsonschema.net/interactives", "type": "array", "items": { "$ref": "#/definitions/interactive" } }, "description": { "id": "http://jsonschema.net/description", "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "elementtype": { "$ref": "#/definitions/elementtype" }, "content": { "$ref": "#/definitions/content" } }, "required": ["elementid", "elementtype", "content"] }, "descriptions": { "items": { "$ref": "#/definitions/description" } }, "children": { "items": { "anyof": [ { "$ref": "#/definitions/group" }, { "$ref": "#/definitions/question" } ] }, "minitems": 1 }, "question": { "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "descriptions": { "$ref": "#/definitions/descriptions" }, "interactives": { "$ref": "#/definitions/interactives" } }, "required": ["elementid", "descriptions", "interactives"] }, "group": { "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "descriptions": { "$ref": "#/definitions/descriptions" }, "children": { "$ref": "#/definitions/children"} }, "required": ["elementid", "descriptions", "children"] } }, "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "description": { "$ref": "#/definitions/descriptions" }, "children": { "$ref": "#/definitions/children" } }, "required": [ "elementid", "descriptions", "children" ] }
i'm getting following error:
error when resolving schema reference '#/definitions/elementid'. path 'definitions.description.properties.elementid', line 135, position 30.
i cannot figure out problem is. scanned documentation several times , had @ tutorials, not have clue.
the semantics of id
keyword are bit confusing. i'm not sure understand myself. in general never idea include id
anywhere other root of schema.
the "id" keyword (or "id", short) used alter resolution scope. when id encountered, implementation must resolve id against immediate parent scope. resolved uri new resolution scope subschema , children, until id encountered.
consider following excerpt schema. because include id
keyword, "elementid" , "label" $ref
s don't resolve against root of document expect, resolve nearest parent schema id
.
"option": { "id": "http://jsonschema.net/option", "type": "object", "properties": { "elementid": { "$ref": "#/definitions/elementid" }, "label": { "$ref": "#/definitions/label" } }, "required": ["elementid", "label"], "definitions": { ... } <-- $refs expect values here } },
i have seen in circles, people write schemas id
s every subschema. i'm not sure benefit think getting out of doing that, suspect think of id
label , don't understand how alters resolution scope.
if have reason use id
s everywhere , want leave them in, can explicitly reference root id
when have conflict.
{ "$ref": "http://some.site.somewhere/entry-schema#definitions/elementid" }
Comments
Post a Comment