Usage of $ref in validation
gurpiarbassi opened this issue · comments
Here is my schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"order_id": {
"$ref": "resource:/schema/definitions.json"
},
"status": {
"type": "object",
"properties": {
"value": {
"type": "string",
"enum": [
"ACCEPTED",
"REJECTED",
"COLLECTED",
"SETTLED",
"SETTLEMENT_FAILURE",
"NOTIFICATION_ERROR"
]
},
"date_time": {
"type": "string",
"description": "Status change date in ISO8601 format with offset"
}
},
"required": [
"value",
"date_time"
]
}
},
"allOf": [
{
"required": [
"order_id",
"status"
]
},
{
"$ref": "resource:/schema/definitions.json#/definitions/order_id"
}
]
}
And my definitions.json
{
"definitions": {
"order_id": {
"type": "array",
"minItems": 1,
"items": [
{
"type": "object",
"required": [
"id",
"scope"
],
"properties": {
"id": {
"type": "string"
},
"scope": {
"type": "string",
"enum": [
"WEB",
"OMS",
"STORE"
]
}
}
}
]
}
}
}
This is the payload I am trying to validate:
{
"order_id" : [ {
"id" : "1",
"scope" : "OMS"
}, {
"id" : "2",
"scope" : "WEB"
} ],
"status" : {
"value" : "ACCEPTED",
"date_time" : "2019-08-12T15:15:39+00:00"
}
}
The result I get is:
"domain" : "validation",
"keyword" : "allOf",
"message" : "instance failed to match all required schemas (matched only 1 out of 2)",
"matched" : 1,
"nrSchemas" : 2,
"reports" : {
"/allOf/0" : [ ],
"/allOf/1" : [ {
"level" : "error",
"schema" : {
"loadingURI" : "resource:/schema/definitions.json#",
"pointer" : "/definitions/order_id"
},
"instance" : {
"pointer" : ""
},
"domain" : "validation",
"keyword" : "type",
"message" : "instance type (object) does not match any allowed primitive type (allowed: [\"array\"])",
"found" : "object",
"expected" : [ "array" ]
} ]
}
It fails validation on the $ref.
Hi,
I'm having the same problem.
Please advise.
We are using this library as well for JSON schema validation and we would like to improve the schema by using the definitions $ref... because the result of not using the $ref is a huge schema which is very hard to maintain.
Can you please share if this issue is going to be fixed soon?
Thanks