Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref within def does not act consistently #2391

Open
meghprkh opened this issue Mar 10, 2024 · 0 comments
Open

Ref within def does not act consistently #2391

meghprkh opened this issue Mar 10, 2024 · 0 comments

Comments

@meghprkh
Copy link

meghprkh commented Mar 10, 2024

What version of Ajv are you using? Does the issue happen if you use the latest version?
Yes

├── ajv-cli@5.0.0
├── ajv@8.12.0

Ajv options object

CLI invocation ajv validate -s test.schema.json -d test.json

JSON Schema

This schema would work complain that:

schema schema/test.schema.json is invalid
error: can't resolve reference #/$defs/JSONValue from id KVMap
{
  "$ref": "#/$defs/KVMap",
  "$defs": {
    "JSONValue": {
      "$id": "JSONValue"
    },
    "KVMap": {
      "$id": "KVMap",
      "type": "object",
      "patternProperties": {
        "^(.*)$": {
          "$ref": "#/$defs/JSONValue"
        }
      }
    }
  }
}

I am unsure if refs should use IDs instead of JSON Pointers everywhere, but IDs do seem to work.

The inconsistency between VSCode and ajv's validator wrt IDs is that ajv accepts ID as JSONValue instead of #JSONValue too, whereas VSCode does not. I cant find any mention of this on JSONSchema and think it might be VSCode which is wrong here.

Sample data

{}

What results did you expect?

This should be a valid case in JSON schema, because dictionaries are not sorted so it would be impossible to refer to a non-id anchor based def.

Are you going to resolve the issue?
I dont know

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

No branches or pull requests

1 participant