Skip to content

V2019-09 $ref cannot be resolved in array 'additionalItems' #493

Closed
@carolkao

Description

@carolkao

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

changed the title [-]V2019-09 $ref cannot find in array 'additionalItems'[/-] [+]V2019-09 $ref cannot be resolved in array 'additionalItems'[/+] on Jan 11, 2022
stevehu

stevehu commented on Jan 12, 2022

@stevehu
Contributor

@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

carolkao commented on Jan 13, 2022

@carolkao
ContributorAuthor

@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.

carolkao

carolkao commented on Jan 14, 2022

@carolkao
ContributorAuthor

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!

stevehu

stevehu commented on Jan 15, 2022

@stevehu
Contributor

@carolkao Thanks a lot for your help. I will schedule a release soon.

carolkao

carolkao commented on Jan 16, 2022

@carolkao
ContributorAuthor

@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

carolkao commented on Jan 24, 2022

@carolkao
ContributorAuthor

Hi @stevehu,

May I know the schedule of the next release? Thank you.

Best regards,
Carol

stevehu

stevehu commented on Jan 25, 2022

@stevehu
Contributor

We have several pending PRs in the pipeline. Once they are merged and tested, I will release another version. Stay Tuned. Thanks.

carolkao

carolkao commented on Jan 25, 2022

@carolkao
ContributorAuthor

Got it. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @stevehu@carolkao

        Issue actions

          V2019-09 $ref cannot be resolved in array 'additionalItems' · Issue #493 · networknt/json-schema-validator