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

$id is incompatible with allowUnknownAttributes: false #389

Open
natnat-mc opened this issue Oct 6, 2023 · 0 comments
Open

$id is incompatible with allowUnknownAttributes: false #389

natnat-mc opened this issue Oct 6, 2023 · 0 comments

Comments

@natnat-mc
Copy link

Setting allowUnknownAttributes: false in settings causes Validator.validate to fail if the schema or a subschema uses the $id property, making the use of subschemas impossible in this case.
This can technically be worked around by using id instead of $id.

Minimal example:

const {Validator} = require('jsonschema')
const v = new Validator()
v.addSchema({$id: '/Test', type: 'string'})
console.log(v.validate('a', {$ref: '/Test'}))
console.log(v.validate('a', {$ref: '/Test'}, {allowUnknownAttributes: false}))

Expected result: not crashing, validating correctly
Actual result: crashes on line 5, SchemaError: Unsupported attribute: $id, schema: { '$id': '/Test', type: 'string' }
(this is not dependant on line 4 being present, but this shows that line 4 works as expected)

Adding $id: true in lib/attribute.js, attribute.ignoreProperties seems to fix this.

If needed, i can create a PR for this, but I don't know what to write for the tests as there doesnt seem to be any for allowUnknownAttributes yet.

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

No branches or pull requests

1 participant