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

Negative filter on "format" #82

Closed
Stranger6667 opened this issue May 27, 2021 · 2 comments
Closed

Negative filter on "format" #82

Stranger6667 opened this issue May 27, 2021 · 2 comments

Comments

@Stranger6667
Copy link
Contributor

I noticed that jsonschema doesn't raise errors when the input string does not match the "format" (as per docs)

This behavior leads to unsatisfiable errors when the "not" keyword is involved. For example:

from hypothesis_jsonschema import from_schema

from_schema({'type': 'string', 'not': {'format': 'date'}}).example()

...

Unsatisfiable: Unable to satisfy assumptions of hypothesis example_generating_inner_function.

However, as hypothesis-jsonschema generates values matching certain formats, then it seems to me that it should also be able to generate values NOT matching them.

I assume that it could be solved by passing the right format_checker to jsonschema validators.

What do you think?

@Zac-HD
Copy link
Member

Zac-HD commented May 30, 2021

I think the current behaviour is strictly correct, since the spec is careful to treat format as advisory. However, I think your idea of adding a format checker should do the trick without requiring any change to hypothesis-jsonschema: see

https://github.com/Zac-HD/hypothesis-jsonschema/blob/1c5f107230ccbd48c66d7c6693833745a598e294/src/hypothesis_jsonschema/_from_schema.py#L158-L166

@Stranger6667
Copy link
Contributor Author

Thanks! I think the issue could be closed, then :)

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

No branches or pull requests

2 participants