Closed
Description
Hi, I encounter a reference problem in array 'additionalItems'. Here is my schema:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"additionalProperties": false,
"properties": {
"parameters": {
"type": "array",
"uniqueItems": true,
"items": [
{
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"const": "param-required"
},
"value": {
"anyOf": [
{
"$ref": "#/$defs/test-ref1"
},
{
"$ref": "#/$defs/test-ref2"
}
]
}
}
}
],
"additionalItems": {
"oneOf": [
{
"type": "object",
"required": [
"name",
"value"
],
"properties": {
"name": {
"const": "param-optional"
},
"value": {
"anyOf": [
{
"$ref": "#/$defs/test-ref1"
},
{
"$ref": "#/$defs/test-ref2"
}
]
}
}
}
]
},
"minItems": 1,
"maxItems": 2
}
},
"$defs": {
"test-ref1": {
"type": "string",
"pattern": "^\\{\\{.+\\}\\}$"
},
"test-ref2": {
"type": "integer"
}
}
}
When I try to validate the following data:
{
"parameters": [
{
"name": "param-required",
"value": 123
},
{
"name": "param-optional",
"value": "{{test}}"
}
]
}
I got the exception:
com.networknt.schema.JsonSchemaException: anyOf/$ref: Reference #/$defs/test-ref1 cannot be resolved
at com.networknt.schema.RefValidator.<init>(RefValidator.java:48)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Seems when looping to 'findAncestor' from "$ref": "#/$defs/test-ref1"
, the 'root' is 'additionalItems' but not the root of the whole document. All reference works fine in 'items' section, only fails at 'additionalItems'. May I know if it is a bug? Or I need to copy all the '$defs' into 'additionalItems'?
Activity
[-]V2019-09 $ref cannot find in array 'additionalItems'[/-][+]V2019-09 $ref cannot be resolved in array 'additionalItems'[/+]stevehu commentedon Jan 12, 2022
@carolkao I think it is very likely a bug. The use case you have is much more complicated than the official test suite and that is why the bug is not identified so far. Could you please add your test case and try to get it resolved? As you said, the issue might be in the additionalItems. Thanks a lot for raising this issue.
carolkao commentedon Jan 13, 2022
@stevehu Thank you for your reply. Unfortunately, I haven't find the root cause of this problem and don't know how to resolve it so far. If you can give me some clue or hint will be appreciated, and I'm willing to contribute it.
parent schema of additionItems can be correctly refered (networknt#493)
parent schema of additionItems can be correctly referenced (networknt…
carolkao commentedon Jan 14, 2022
Hi @stevehu ,
I've created a PR : #497 for fixing the issue. Please help to review and let me know if there exists any problem. Thank you!
parent schema of additionItems can be correctly referenced (#493) (#497)
stevehu commentedon Jan 15, 2022
@carolkao Thanks a lot for your help. I will schedule a release soon.
carolkao commentedon Jan 16, 2022
@stevehu Appreciate your review, I'm looking forward to having the new version. Since the PR is merged already, I can close this issue. Thanks again.
carolkao commentedon Jan 24, 2022
Hi @stevehu,
May I know the schedule of the next release? Thank you.
Best regards,
Carol
stevehu commentedon Jan 25, 2022
We have several pending PRs in the pipeline. Once they are merged and tested, I will release another version. Stay Tuned. Thanks.
carolkao commentedon Jan 25, 2022
Got it. Thank you.