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

Support custom vocabularies and unknown keyword and meta-schema handling #980

Merged
merged 16 commits into from
Mar 1, 2024

Conversation

justin-tay
Copy link
Contributor

Closes #977, closes #829

This adds support for customizing

  • Custom vocabularies
  • Unknown keyword handling
  • Unknown meta-schema handling

This contains breaking changes in how custom meta-schemas are created and the documentation updates assume it will be released as 1.4.0.

JsonSchemaFactory

  • The following were renamed on JsonSchemaFactory builder
    • defaultMetaSchemaURI -> defaultMetaSchemaIri
    • enableUriSchemaCache -> enableSchemaCache
  • The builder now accepts a JsonMetaSchemaFactory which can be used to restrict the loading of meta-schemas that aren't explicitly defined in the JsonSchemaFactory. The DisallowUnknownJsonMetaSchemaFactory can be used to only allow explicitly configured meta-schemas.

JsonMetaSchema

  • In particular Version201909 and Version202012 had most of the keywords moved to their respective vocabularies.
  • The following were renamed
    • getUri -> getIri
  • The builder now accepts a vocabularyFactory to allow for custom vocabularies.
  • The builder now accepts a unknownKeywordFactory. By default this uses the UnknownKeywordFactory implementation that logs a warning and returns a AnnotationKeyword. The DisallowUnknownKeywordFactory can be used to disallow the use of unknown keywords.
  • The implementation of the builder now correctly throws an exception for $vocabulary with value of true that are not known to the implementation.

ValidatorTypeCode

  • getNonFormatKeywords has been removed and replaced with getKeywords. This now includes the format keyword as the JsonMetaSchema.Builder now needs to know if the format keyword was configured, as it might not be in meta-schemas that don't define the format vocabulary.
  • The applicable VersionCode for each of the ValidatorTypeCode were modified to remove the keywords that are defined in vocabularies for Version201909 and Version202012.

Vocabulary

  • This now contains Keyword instances instead of the string keyword value as it needs to know the explicit implementation. For instance the implementation for the items keyword in Draft 2019-09 and Draft 2020-12 are different.
  • The following were renamed
    • getId -> getIri

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 85.71429% with 48 lines in your changes are missing coverage. Please review.

Project coverage is 78.51%. Comparing base (fed46cf) to head (42cbbe5).

Files Patch % Lines
...main/java/com/networknt/schema/JsonMetaSchema.java 72.97% 17 Missing and 3 partials ⚠️
...n/java/com/networknt/schema/JsonSchemaFactory.java 73.33% 5 Missing and 7 partials ⚠️
...ain/java/com/networknt/schema/AbstractKeyword.java 18.18% 9 Missing ⚠️
...networknt/schema/DefaultJsonMetaSchemaFactory.java 88.88% 0 Missing and 3 partials ⚠️
src/main/java/com/networknt/schema/Vocabulary.java 57.14% 3 Missing ⚠️
...tworknt/schema/format/BaseFormatJsonValidator.java 66.66% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #980      +/-   ##
============================================
- Coverage     78.64%   78.51%   -0.13%     
- Complexity     1852     1866      +14     
============================================
  Files           165      169       +4     
  Lines          6002     6088      +86     
  Branches       1148     1153       +5     
============================================
+ Hits           4720     4780      +60     
- Misses          845      871      +26     
  Partials        437      437              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stevehu stevehu merged commit 95911ba into networknt:master Mar 1, 2024
4 checks passed
@rishabh413
Copy link

Hi @justin-tay

Will this also fix #475 (comment) ?

@justin-tay
Copy link
Contributor Author

Hi @justin-tay

Will this also fix #475 (comment) ?

That should already have been fixed as it has nothing to do with implementing custom vocabularies. That issue has to do with the lack of support for $dynamicRef which was fixed in

@rishabh413
Copy link

It did, thanks!!

johnaohara pushed a commit to Hyperfoil/Horreum that referenced this pull request Mar 19, 2024
Bumps [com.networknt:json-schema-validator](https://github.com/networknt/json-schema-validator) from 1.3.3 to 1.4.0.
- [Release notes](https://github.com/networknt/json-schema-validator/releases)
- [Changelog](https://github.com/networknt/json-schema-validator/blob/master/CHANGELOG.md)
- [Commits](networknt/json-schema-validator@1.3.3...1.4.0)

---
updated-dependencies:
- dependency-name: com.networknt:json-schema-validator
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

- Modified call to JsonSchemaFactory.Builder() - see networknt/json-schema-validator#980 (comment)
johnaohara pushed a commit to Hyperfoil/Horreum that referenced this pull request Mar 19, 2024
Bumps [com.networknt:json-schema-validator](https://github.com/networknt/json-schema-validator) from 1.3.3 to 1.4.0.
- [Release notes](https://github.com/networknt/json-schema-validator/releases)
- [Changelog](https://github.com/networknt/json-schema-validator/blob/master/CHANGELOG.md)
- [Commits](networknt/json-schema-validator@1.3.3...1.4.0)

---
updated-dependencies:
- dependency-name: com.networknt:json-schema-validator
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

- Modified call to JsonSchemaFactory.Builder() - see networknt/json-schema-validator#980 (comment)
johnaohara pushed a commit to Hyperfoil/Horreum that referenced this pull request Mar 19, 2024
Bumps [com.networknt:json-schema-validator](https://github.com/networknt/json-schema-validator) from 1.3.3 to 1.4.0.
- [Release notes](https://github.com/networknt/json-schema-validator/releases)
- [Changelog](https://github.com/networknt/json-schema-validator/blob/master/CHANGELOG.md)
- [Commits](networknt/json-schema-validator@1.3.3...1.4.0)

---
updated-dependencies:
- dependency-name: com.networknt:json-schema-validator
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

- Modified call to JsonSchemaFactory.Builder() - see networknt/json-schema-validator#980 (comment)
johnaohara pushed a commit to Hyperfoil/Horreum that referenced this pull request Mar 19, 2024
Bumps [com.networknt:json-schema-validator](https://github.com/networknt/json-schema-validator) from 1.3.3 to 1.4.0.
- [Release notes](https://github.com/networknt/json-schema-validator/releases)
- [Changelog](https://github.com/networknt/json-schema-validator/blob/master/CHANGELOG.md)
- [Commits](networknt/json-schema-validator@1.3.3...1.4.0)

---
updated-dependencies:
- dependency-name: com.networknt:json-schema-validator
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

- Modified call to JsonSchemaFactory.Builder() - see networknt/json-schema-validator#980 (comment)
Julian added a commit to bowtie-json-schema/bowtie that referenced this pull request Mar 23, 2024
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.

Are there plans to support custom vocabularies? Schema version no longer validated since version 1.0.83
4 participants