Skip to content

Fix AJV warning, "$ref: keywords ignored in schema" #392

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

Merged
merged 2 commits into from
Dec 15, 2020
Merged

Fix AJV warning, "$ref: keywords ignored in schema" #392

merged 2 commits into from
Dec 15, 2020

Conversation

joshkel
Copy link
Contributor

@joshkel joshkel commented Dec 15, 2020

The improved handling for recursive schemas that was added in #383 resulted in type-related keywords being added alongside the $ref keywords. Such keywords are ignored according to draft-07 of the JSON Schema, so AJV (and possibly other tools) warn about them.

For more information, see ajv-validator/ajv#1121

To address this, I revised the recursive ref logic to only include "annotation" keywords, based on the list here:

http://json-schema.org/understanding-json-schema/reference/generic.html#annotations

(That page also includes title, but typescript-json-schema currently doesn't recognize that.)

Note that draft 2019-09 of JSON Schema changes $ref to act like a normal keyword, so this change will no longer be necessary in that version of the spec.

Fixes #391.

Please:

  • Make your pull request atomic, fixing one issue at a time unless there are many relevant issues that cannot be decoupled.
  • Provide a test case & update the documentation in the Readme.md

The improved handling for recursive schemas that was added in #383 resulted in type-related keywords being added alongside the `$ref` keywords. Such keywords are ignored according to draft-07 of the JSON Schema, so AJV (and possibly other tools) warn about them.

For more information, see ajv-validator/ajv#1121

To address this, I revised the recursive ref logic to only include "annotation" keywords, based on the list here:

http://json-schema.org/understanding-json-schema/reference/generic.html#annotations

(That page also includes `title`, but typescript-json-schema currently doesn't recognize that.)

Note that draft 2019-09 of JSON Schema changes `$ref` to act like a normal keyword, so this change will no longer be necessary in that version of the spec.

Fixes #391.
@joshkel joshkel mentioned this pull request Dec 15, 2020
* Subset of descriptive, non-type keywords that are permitted alongside a $ref.
* Prior to JSON Schema draft 2019-09, $ref is a special keyword that doesn't
* permit keywords alongside it, and so AJV may raise warnings if it encounters
* any type-related keywords; see https://github.com/ajv-validator/ajv/issues/1121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This is what I should have done when fixing the other issue but it was too much back then. 👍

@domoritz domoritz merged commit 589e78d into YousefED:master Dec 15, 2020
@joshkel joshkel deleted the ref-keywords-ignored branch December 15, 2020 11:43
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

Successfully merging this pull request may close these issues.

Top-level $ref in 0.44.0
3 participants