JSONSchema validation error using $ ref (Draft v3)

I created a JSON scheme after the specifications of the v3 project. The scheme is as follows:

{ "$schema": "http://json-schema.org/draft-03/schema#", "additionalProperties": false, "type": "object", "properties": { "ExecutionPlanList": { "type": "array", "items": [{ "type": "object", "properties": { "model": { "required": true, "properties": { "featureList": { "required": true, "items": { "properties": { "featureName": { "type": ["string", "null"] }, "featureType": { "type": "string" } }, "type": "object" }, "type": "array" }, "modelId": { "required": true, "type": "string" } }, "type": "object" }, "cascadeSteps": { "required": false, "items": { "properties": { "binaryModel": { "$ref": "#/properties/ExecutionPlanList/items/properties/model", "required": true }, "threshold": { "required": true, "default": "0.0", "maximum": 100.0, "type": "number" }, "backupModel": { "$ref": "#/properties/ExecutionPlanList/items/properties/model", "required": true } } }, "type": "array" }, "marketplaceId": { "required": true, "type": "integer" } } }] } }, "required": true } 

Essentially, executePlanList contains a list of models and a cascadeStep, and each cascade of Step contains two models with a number. So I'm trying to reuse the schema for the model in cascadeStep, but the check ( https://www.jsonschemavalidator.net/ ) fails with Could not resolve schema reference '#/properties/ExecutionPlanList/items/properties/model' .

Would thank all the pointers for what is wrong with this circuit.

+5
source share
2 answers

how about adding β€œdefinitions” and refer like this:

 { "$schema": "http://json-schema.org/draft-03/schema#", "additionalProperties": false, "type": "object", "definitions": { "model": { "required": true, "properties": { "featureList": { "required": true, "items": { "properties": { "featureName": { "type": ["string", "null"] }, "featureType": { "type": "string" } }, "type": "object" }, "type": "array" }, "modelId": { "required": true, "type": "string" } }, "type": "object" } }, "properties": { "ExecutionPlanList": { "type": "array", "items": [{ "type": "object", "properties": { "model": { "$ref" : "#/definitions/model" }, "cascadeSteps": { "required": false, "items": { "properties": { "binaryModel": { "$ref" : "#/definitions/model", "required": true }, "threshold": { "required": true, "default": "0.0", "maximum": 100.0, "type": "number" }, "backupModel": { "$ref" : "#/definitions/model", "required": true } } }, "type": "array" }, "marketplaceId": { "required": true, "type": "integer" } } }] } }, "required": true } 
+3
source

It should be "# / properties / ExecutionPlanList / items / 0 / properties / model"

The circuit, by the way, checks only the first element.

+4
source

Source: https://habr.com/ru/post/1273259/


All Articles