networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
822 stars 323 forks source link

Add annotation support refactor keywords to use annotations implement output formats #942

Closed justin-tay closed 7 months ago

justin-tay commented 7 months ago

Closes #940, closes #939, closes #936, closes #935, closes #889, closes #881, closes #857, closes #831, closes #286

This should not contain any breaking changes from 1.3.0

The document updates in this PR assume it will be released as 1.3.1

The following keywords were refactored to improve performance and meet the functional requirements.

In particular this converts the unevaluatedItems and unevaluatedProperties validators to use annotations to perform the evaluation instead of the current mechanism which affects performance. This also refactors $recursiveRef to not rely on that same mechanism.

This also fixes the issue where the unevaluatedItems keyword does not take into account the contains keyword when performing the evaluation.

This also fixes cases where anyOf short-circuits to not short-circuit the evaluation if a adjacent unevaluatedProperties or unevaluatedItems keyword exists.

This should fix most of the remaining functional and performance issues.

Functional

Implementations Overall DRAFT_03 DRAFT_04 DRAFT_06 DRAFT_07 DRAFT_2019_09 DRAFT_2020_12
NetworkNt pass: r:4703 (100.0%) o:2369 (100.0%)
fail: r:0 (0.0%) o:1 (0.0%)
pass: r:600 (100.0%) o:251 (100.0%)
fail: r:0 (0.0%) o:0 (0.0%)
pass: r:796 (100.0%) o:318 (100.0%)
fail: r:0 (0.0%) o:0 (0.0%)
pass: r:880 (100.0%) o:541 (100.0%)
fail: r:0 (0.0%) o:0 (0.0%)
pass: r:1201 (100.0%) o:625 (100.0%)
fail: r:0 (0.0%) o:0 (0.0%)
pass: r:1226 (100.0%) o:634 (99.8%)
fail: r:0 (0.0%) o:1 (0.2%)

Performance

NetworkNT 1.3.1
Benchmark                                                          Mode  Cnt       Score      Error   Units
NetworkntBenchmark.testValidate                                   thrpt   10    6776.693 ±  115.309   ops/s
NetworkntBenchmark.testValidate:·gc.alloc.rate                    thrpt   10     971.191 ±   16.420  MB/sec
NetworkntBenchmark.testValidate:·gc.alloc.rate.norm               thrpt   10  165318.816 ±    0.459    B/op
NetworkntBenchmark.testValidate:·gc.churn.G1_Eden_Space           thrpt   10     968.894 ±   51.234  MB/sec
NetworkntBenchmark.testValidate:·gc.churn.G1_Eden_Space.norm      thrpt   10  164933.962 ± 8636.203    B/op
NetworkntBenchmark.testValidate:·gc.churn.G1_Survivor_Space       thrpt   10       0.002 ±    0.001  MB/sec
NetworkntBenchmark.testValidate:·gc.churn.G1_Survivor_Space.norm  thrpt   10       0.274 ±    0.218    B/op
NetworkntBenchmark.testValidate:·gc.count                         thrpt   10      89.000             counts
NetworkntBenchmark.testValidate:·gc.time                          thrpt   10      99.000                 ms
Everit 1.14.1
Benchmark                                                          Mode  Cnt       Score       Error   Units
EveritBenchmark.testValidate                                      thrpt   10    3719.192 ±   125.592   ops/s
EveritBenchmark.testValidate:·gc.alloc.rate                       thrpt   10    1448.208 ±    74.746  MB/sec
EveritBenchmark.testValidate:·gc.alloc.rate.norm                  thrpt   10  449621.927 ±  7400.825    B/op
EveritBenchmark.testValidate:·gc.churn.G1_Eden_Space              thrpt   10    1446.397 ±    79.919  MB/sec
EveritBenchmark.testValidate:·gc.churn.G1_Eden_Space.norm         thrpt   10  449159.799 ± 18614.931    B/op
EveritBenchmark.testValidate:·gc.churn.G1_Survivor_Space          thrpt   10       0.001 ±     0.001  MB/sec
EveritBenchmark.testValidate:·gc.churn.G1_Survivor_Space.norm     thrpt   10       0.364 ±     0.391    B/op
EveritBenchmark.testValidate:·gc.count                            thrpt   10     133.000              counts
EveritBenchmark.testValidate:·gc.time                             thrpt   10     148.000                  ms
codecov-commenter commented 7 months ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 78.57143% with 291 lines in your changes missing coverage. Please review.

Project coverage is 78.85%. Comparing base (e95642c) to head (d008b9b). Report is 90 commits behind head on master.

Files Patch % Lines
...schema/annotation/JsonNodeAnnotationPredicate.java 0.00% 30 Missing :warning:
...va/com/networknt/schema/RecursiveRefValidator.java 55.73% 20 Missing and 7 partials :warning:
...tworknt/schema/annotation/JsonNodeAnnotations.java 22.72% 17 Missing :warning:
...n/java/com/networknt/schema/output/OutputUnit.java 65.30% 17 Missing :warning:
...n/java/com/networknt/schema/output/OutputFlag.java 0.00% 16 Missing :warning:
...java/com/networknt/schema/DynamicRefValidator.java 28.57% 14 Missing and 1 partial :warning:
...c/main/java/com/networknt/schema/RefValidator.java 54.83% 10 Missing and 4 partials :warning:
...va/com/networknt/schema/result/JsonNodeResult.java 36.36% 14 Missing :warning:
...etworknt/schema/annotation/JsonNodeAnnotation.java 66.66% 12 Missing and 1 partial :warning:
...schema/output/HierarchicalOutputUnitFormatter.java 86.25% 5 Missing and 6 partials :warning:
... and 35 more

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #942 +/- ## ============================================ - Coverage 79.04% 78.85% -0.19% - Complexity 1504 1687 +183 ============================================ Files 143 157 +14 Lines 4915 5652 +737 Branches 932 1068 +136 ============================================ + Hits 3885 4457 +572 - Misses 670 794 +124 - Partials 360 401 +41 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

big-andy-coates commented 7 months ago

@justin-tay Nice work on zero required failures, and only one optional failure! :)

Performance of 1.30.0 was looking amazing too: https://www.creekservice.org/json-schema-validation-comparison/performance

Off the back of these performance and functional improvements.... https://github.com/creek-service/creek-kafka/issues/491