-
-
Notifications
You must be signed in to change notification settings - Fork 584
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 scheme and trailing slashes in meta_schemes key #822
Conversation
Codecov Report
@@ Coverage Diff @@
## main python-jsonschema/jsonschema#822 +/- ##
==========================================
+ Coverage 96.08% 96.12% +0.03%
==========================================
Files 18 18
Lines 2706 2733 +27
Branches 308 308
==========================================
+ Hits 2600 2627 +27
Misses 86 86
Partials 20 20
Continue to review full report at Codecov.
|
Should I do something else? |
Hey! Sorry for not responding here -- the key thing we need to verify is whether this change is actually fully correct under the spec. Specifically, I think what we need to do here is ask this question upstream, in perhaps the slack or discussion board. EDIT: to clarify a bit further:
|
Thanks for the reply. I understand the motivation to stick to the spec, but the original issue reported a URI with trailing slash and hash and my motivation has a trailing hash in it, so there is a practical aspect to consider also. If it turns out to be against spec to have trailing slashes/hashes, would it be acceptable to have something like a |
If it's against the spec, it'd seem quite easy to do external from the validation process. I.e. I could possibly be convinced that'd be worth adding somewhere (there's some precedence in wanting this kind of thing in e.g. python-jsonschema/referencing#2 or #252) but yeah not as a flag. |
I asked on their Slack channel; I'll reproduce the response here for completeness:
I'll think about your proposal for a |
Did you ask specifically about trailing fragments too? Ignoring schemes I was sure wasn't going to fly, so unsurprised there, but those seemed more likely to be allowed. Is an empty fragment considered the same URL as fragmentless? As for the helper function, either way is fine with me on reusing this one or creating a new one -- whatever is easiest for you. And thanks! |
Sorry, should have included my question also:
I don't know enough about this, to be honest. It seems that the safest way forward is to only accept the format that is in the schema |
Sorry for the lack of update. The longer I thought about it, the more I got convinced I was getting myself into a pickle. I agree that the least-intrusive way to solve this is to add an utility function that allows the user to override a particular I've updated the PR with the utility function. Here is an MWE. The first attempt fails because the import jsonschema
schema = {
"$schema": "https://json-schema.org/draft-04/schema/#",
"definitions": {
"my_type": {
"type": "number",
"maximum": 10,
"exclusiveMaximum": True
}
},
"properties": {
"my_number": {
"$ref": "#/definitions/my_type"
}
}
}
instance = {
"$schema": "https://json-schema.org/draft-04/schema/#",
"my_number": 7
}
# Fails
try:
jsonschema.validate(instance, schema)
except jsonschema.exceptions.SchemaError as exc:
print("failed")
# Succeeds
jsonschema.validators.set_validator_for(schema, jsonschema.validators.Draft4Validator)
jsonschema.validate(instance, schema)
print("success") I will fix the merge conflict and add unit tests together with other comments you may have. |
Any feedback @Julian ? |
Apologies, I am inordinately busy, even busier than usual, as academic semester is starting -- I'll try to get you some feedback but it likely won't be before middle of the week or early next. Sorry -- please do ping me if you have to wait any longer. |
No worries! Just wanted to make sure that it was noticed. |
@lcvisser -- looking at this briefly, my honest reaction is -- is this really any better than just recommending people do |
@Julian Personally, I think the utility functions is more user friendly, as it is discoverable and documented via the docstring. But it's a personal preference, so if you'd like the code base as minimal as possible, than that's a valid argument too of course. In that case, I'd propose to reject and close this MR (and arguably also the linked issue). |
I think for now will close -- I appreciate your effort and research. We can revisit in the future if needed. |
This PR intends to resolve #569 by ignoring the scheme (http, https) and any trailing slashes in the
$schema
uri.