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

Refactor format validation #958

Merged
merged 12 commits into from
Feb 7, 2024
Merged

Refactor format validation #958

merged 12 commits into from
Feb 7, 2024

Conversation

justin-tay
Copy link
Contributor

Closes #957, closes #848

This shouldn't contain any breaking changes, instead some methods are deprecated with some workarounds to cater to the old behavior.

This refactors the format validation to do the following

  • Allow custom formats to apply to non-string values
  • Refactor the logic such that all the validation logic exists in the format implementations. ie. ipv6 and date-time logic now all reside in a format implementation.
  • Implement handling for unknown format. When the assertion vocab is used, unknown formats trigger an assertion. Otherwise need to set strict format to trigger an assertion.
  • Refactor to use localised messages. Previously it used hardcoded english strings as the error description.

Custom Format
https://json-schema.org/draft/2020-12/json-schema-validation#name-foreword

All format attributes defined in this section apply to strings, 
but a format attribute can be specified to apply to any instance types defined in the data 
model defined in the [core JSON Schema.]

Unknown Format
https://json-schema.org/draft/2020-12/json-schema-validation#name-custom-format-attributes

When the Format-Assertion vocabulary is specified, implementations MUST fail upon encountering unknown formats.

Note that having the vocab is different from enabling assertions as an option.

@codecov-commenter
Copy link

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (32356e9) 79.01% compared to head (e2ac373) 78.79%.

Files Patch % Lines
...ain/java/com/networknt/schema/FormatValidator.java 69.23% 5 Missing and 3 partials ⚠️
...main/java/com/networknt/schema/JsonMetaSchema.java 68.42% 5 Missing and 1 partial ⚠️
...va/com/networknt/schema/format/DateTimeFormat.java 85.71% 1 Missing and 1 partial ⚠️
...ava/com/networknt/schema/format/PatternFormat.java 84.61% 0 Missing and 2 partials ⚠️
src/main/java/com/networknt/schema/Format.java 93.33% 1 Missing ⚠️
...va/com/networknt/schema/format/DurationFormat.java 85.71% 0 Missing and 1 partial ⚠️
...com/networknt/schema/format/IdnHostnameFormat.java 80.00% 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     #958      +/-   ##
============================================
- Coverage     79.01%   78.79%   -0.23%     
- Complexity     1726     1767      +41     
============================================
  Files           158      160       +2     
  Lines          5753     5797      +44     
  Branches       1087     1080       -7     
============================================
+ Hits           4546     4568      +22     
- Misses          809      825      +16     
- Partials        398      404       +6     

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

@stevehu stevehu merged commit e60f81f into networknt:master Feb 7, 2024
4 checks passed
@justin-tay justin-tay deleted the gh957 branch February 20, 2024 01:47
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.

Custom Formats are not allowed for types other than Strings Add an option to have strict "format" validation
3 participants