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

Ignore trailing '#' in meta-schema URLs #497

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

GREsau
Copy link
Contributor

@GREsau GREsau commented Sep 9, 2024

A single trailing # should be present for draft-07 and earlier, but should not be present for 2019-09 or 2020-12 (e.g. see the $schema value in draft2020-12/schema.json). But for simplicity and robustness, we can just ignore it in all cases.

With this change, the output of this example is now false:

let schema = JSONSchema::compile(&json!({
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "unevaluatedProperties": false
}))
.unwrap();

let value = json!({
    "blah": 1
});

println!("{}", schema.is_valid(&value));

A single trailing # should be present for draft-07 and earlier, but should not be present for 2019-09 or 2020-12. But for simplicity and robustness, we can just ignore it in all cases
Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.05%. Comparing base (f001fe6) to head (79c8de5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #497      +/-   ##
==========================================
+ Coverage   89.87%   90.05%   +0.18%     
==========================================
  Files          58       58              
  Lines        9945     9866      -79     
==========================================
- Hits         8938     8885      -53     
+ Misses       1007      981      -26     

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

Copy link

codspeed-hq bot commented Sep 9, 2024

CodSpeed Performance Report

Merging #497 will degrade performances by 49.53%

Comparing GREsau:meta_schema_trailing_hash (79c8de5) with master (c449e7a)

Summary

⚡ 17 improvements
❌ 15 regressions
✅ 288 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master GREsau:meta_schema_trailing_hash Change
additional_properties_and_properties bartruefoo1[jsonschema/is_valid/invalid] 1.4 µs 1.2 µs +12.63%
additional_properties_false [jsonschema/is_valid/valid] 427.8 ns 360.6 ns +18.64%
additional_properties_false [jsonschema/validate/valid] 2.6 µs 2.3 µs +13.45%
additional_properties_false foo1[jsonschema/is_valid/invalid] 645.6 ns 391.7 ns +64.82%
additional_properties_false_and_properties bar2foo1[jsonschema/is_valid/invalid] 1,050 ns 923.9 ns +13.65%
additional_properties_single foo1[jsonschema/is_valid/invalid] 955.3 ns 793.6 ns +20.37%
additional_properties_single foobar[jsonschema/is_valid/valid] 960.8 ns 823.9 ns +16.62%
any_of 1[jsonschema/is_valid/valid] 611.1 ns 698.6 ns -12.52%
any_of_multiple_types foo[jsonschema/is_valid/valid] 736.9 ns 882.8 ns -16.52%
any_of_multiple_types null[jsonschema/is_valid/invalid] 737.8 ns 883.6 ns -16.5%
boolean_false 1[jsonschema/is_valid/invalid] 29.7 ns 58.9 ns -49.53%
const 1[jsonschema/is_valid/valid] 392.2 ns 479.7 ns -18.24%
const foo[jsonschema/is_valid/invalid] 240.3 ns 327.8 ns -26.69%
format_date 06/19/1963[jsonschema/is_valid/invalid] 985.3 ns 1,135.8 ns -13.26%
format_email foo[jsonschema/is_valid/invalid] 585.6 ns 527.2 ns +11.06%
format_ipv4 127.0.0.999[jsonschema/is_valid/invalid] 1.7 µs 1.5 µs +16.28%
format_ipv4 20010db885a3000000008a2e03707334[jsonschema/is_valid/invalid] 1.8 µs 1.6 µs +12.49%
format_ipv6 20010db885a3000000008a2e03707334[jsonschema/is_valid/valid] 1.8 µs 1.6 µs +16.97%
format_time 083006.283185Z[jsonschema/validate/valid] 5 µs 5.8 µs -12.7%
format_uri_template http//example.com/dictionary/term1/term[jsonschema/validate/valid] 5.3 µs 6.1 µs -13.9%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

@Stranger6667
Copy link
Owner

Thanks!

Should the example be evaluated as true? Given the example from learnjsonschema.com:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "unevaluatedProperties": false
}

All object instances fail against the false schema

Am I correct that this change exposes #496 more clearly?

@GREsau
Copy link
Contributor Author

GREsau commented Sep 9, 2024

Should the example be evaluated as true?

Whoops, sorry that was a typo. I meant it currently outputs true, but with this PR, it now outputs false!

@GREsau
Copy link
Contributor Author

GREsau commented Sep 9, 2024

Am I correct that this change exposes #496 more clearly?

Kinda, in that you no longer need to specify .with_draft(Draft::Draft202012), as it will now infer that it's a 2020-12 schema from $schema

@Stranger6667
Copy link
Owner

Whoops, sorry that was a typo. I meant it currently outputs true, but with this PR, it now outputs false!

Aha, got it! So, the other part of my comment is irrelevant then :) I haven't checked it myself yet, but it would not fix #496, right? as it seems to me that #496 is caused by some issue in UnevaluatedPropertiesValidator::is_valid

@Stranger6667 Stranger6667 merged commit 9c12d24 into Stranger6667:master Sep 10, 2024
31 of 33 checks passed
@GREsau
Copy link
Contributor Author

GREsau commented Sep 10, 2024

I haven't checked it myself yet, but it would not fix #496, right? as it seems to me that #496 is caused by some issue in UnevaluatedPropertiesValidator::is_valid

Correct, they're entirely separate issues

@GREsau GREsau deleted the meta_schema_trailing_hash branch September 10, 2024 14:30
@Stranger6667
Copy link
Owner

Good. I am going through the failures in bowtie.report and will push some fixes this week. For today, I plan to fix the issue of $ref ignoring $schema inside the resolved schema.

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.

2 participants