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

Make $schema lookup more liberal for empty fragment URLs #569

Closed
jswinarton opened this issue Jun 12, 2019 · 12 comments
Closed

Make $schema lookup more liberal for empty fragment URLs #569

jswinarton opened this issue Jun 12, 2019 · 12 comments
Labels
Bug Something doesn't work the way it should.

Comments

@jswinarton
Copy link

I have a valid schema document that contains the following $schema value:

{
  "$schema": "http://json-schema.org/draft-07/schema/#"
}

When validating an instance against this schema, I get the following warning:

/usr/local/lib/python3.7/site-packages/jsonschema/validators.py:893: DeprecationWarning: The metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.

I discovered that I can suppress the error by changing removing the trailing slash and hash from the schema URI, e.g. http://json-schema.org/draft-07/schema.

I think the validator should allow for some variations on URI formats--the JSON Schema documentation specifies the $schema value with the trailing slash and hash, so I believe that will be the most common format users attempt.

@jswinarton jswinarton changed the title metaschema validation raises warnings on valid schema Metaschema validation raises warnings on valid schema Jun 12, 2019
@Julian
Copy link
Member

Julian commented Jun 14, 2019

This looks reasonable -- I'm not sure we want to accept multiple variations on its own, but really it depends what the JSON Schema spec says (if anything) about whether those URLs are the same or not as far as its concerned. Probably you're right that they are.

So yeah definitely thanks for filing.

@Julian Julian added the Bug Something doesn't work the way it should. label Jun 27, 2019
@scottj97

This comment has been minimized.

@Julian

This comment has been minimized.

@jayeye

This comment has been minimized.

@Julian Julian changed the title Metaschema validation raises warnings on valid schema Make $schema lookup more liberal for empty fragment URLs Jul 1, 2020
@wmarcuse
Copy link

I get the same DepriciationWarning when I create a reusable schema validator:

validator_class = jsonschema.validators.validator_for(SCHEMA)
validator = validator_class(schema=SCHEMA, format_checker=jsonschema.FormatChecker())

Specifying the draft version validator did the trick:

validator_class = jsonschema.validators.Draft7Validator
validator = validator_class(schema=SCHEMA, format_checker=jsonschema.FormatChecker())

@lcvisser
Copy link

lcvisser commented Apr 1, 2021

Maybe also accept both http:// and https://?

@anriijmind
Copy link

@wmarcuse Could you give, please, an example with validating schema and response? Because I don't understand what should I do with validator = validator_class(schema=SCHEMA, format_checker=jsonschema.FormatChecker()), if warning shows in that code
validate(instance=respose_json, schema=schema)
Schema has this type "$schema": "http://json-schema.org/schema#"

and I have this error:
/lib/python3.8/site-packages/jsonschema/validators.py:928: DeprecationWarning: The metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future. cls = validator_for(schema)

@Hoohm
Copy link

Hoohm commented Jun 7, 2021

I have the same error as you @anriijmind
Using this link : http://json-schema.org/draft/2020-12/schema

@anriijmind
Copy link

I have the same error as you @anriijmind
Using this link : http://json-schema.org/draft/2020-12/schema

Still warning shows.
Tried:

  1. "$schema": "http://json-schema.org/schema#" -> "$schema": "http://json-schema.org/draft/2020-12/schema#"
  2. "$schema": "http://json-schema.org/schema#" -> "$schema": "http://json-schema.org/draft/2020-12/schema"

I have jsonschema "version": "==3.2.0"

@Kaelink
Copy link

Kaelink commented Jul 2, 2021

I had the same issue, but the README only claims support for:

Full support for Draft 7, Draft 6, Draft 4 and Draft 3

Changing to http://json-schema.org/draft-07/schema# therefore solved the warning in my case.

@anriijmind
Copy link

I had the same issue, but the README only claims support for:

Full support for Draft 7, Draft 6, Draft 4 and Draft 3

Changing to http://json-schema.org/draft-07/schema# therefore solved the warning in my case.

Thanks, it solves warning

@Julian
Copy link
Member

Julian commented Sep 30, 2021

Given the combination of some of what's proposed here being against the spec, and the rest being fairly easy to do by simply ensuring you use precisely the identifier that the meta schema says you should, I'm going to WONTFIX this.

You can see some additional discussion at the bottom of #822.

If you really insist on (or have a use case where) you cannot change what's in the actual schema itself, something like your_schema["$schema"] = Draft4Validator.META_SCHEMA["$id"] just before you call validate works as well.

@Julian Julian closed this as completed Sep 30, 2021
Julian added a commit that referenced this issue Jul 11, 2022
69acf529 Merge pull request #572 from json-schema-org/default-reviewers
26a51ca3 Merge pull request #575 from jdesrosiers/add-package-json
d0e80a96 Re-add package.json
88d69482 Merge pull request #573 from json-schema-org/handling-nulls-in-instances
bd653f34 fixed findings by julian
eab34ba6 fix `prefixItems` tests to actually use it (instead of `items`, copy-paste error)
6680a003 fixed typo in `type` declaration: surround with quotes
257f5220 added null-handling tests for unevaluatedItems
e3c007dd added null-handling tests for unevaluatedProperties
3d3bdf4e added null-handling tests for properties
54cc5703 added null-handling tests for patternProperties
28419842 added null-handling tests for contains
4d1a916a added null-handling tests for additionalItems
6e47a99a added null-handling tests for prefixItems; fixed indentation on previous commit
761d4b2b added null-handling tests for array-form items
6315a51d added null-handling tests for single-form items
278e5b3b added null-handling tests for additionalProperties
bce6b82a Set up default reviewers (the whole test suite team).
9cb7da92 Merge pull request #564 from json-schema-org/sanity-check-terminology
2a316683 Merge pull request #569 from spacether/feat_adds_new_python_consumer
fae0017d Removes idea files
8af12a3f Adds python-experimental to the users list
c7a0f3e9 Reconcile terminology in the sanity checker with the README

git-subtree-dir: json
git-subtree-split: 69acf52990b004240839ae19b4bec8fb01d50876
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something doesn't work the way it should.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants