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

Generate integers for "number" schema? #80

Open
Stranger6667 opened this issue May 13, 2021 · 1 comment
Open

Generate integers for "number" schema? #80

Stranger6667 opened this issue May 13, 2021 · 1 comment

Comments

@Stranger6667
Copy link
Contributor

Stranger6667 commented May 13, 2021

At the moment the "number" type corresponds to st.float strategy, but as integers are valid for the "number" type in JSON Schema, I am wondering whether it will make sense to generate integers there as well.

I believe it may increase the output variation. What do you think?

I was thinking about your comment in the context of negating schemas and tried to canonicalise {"not": {"minimum": 42}} which gives {'not': {'minimum': 42, 'type': 'number'}, 'type': 'number'}. Even though it is a valid transformation, it seems too restrictive. For example, the end-user might expect that negating {"minimum": 42} will give e.g. 41, or some other integers, but there will be always floats. Having type: integer in place will solve this ({"not": {"minimum": 42}, "type": "integer"} works), but still sometimes it happens that it is missing.

@Zac-HD
Copy link
Member

Zac-HD commented May 13, 2021

I remember that a while ago I looked at adding some logic along the lines of "sometimes try casting "number" values to Python type int" and vice-versa, but ran into trouble with the semantics on older jsonschema versions (I think draft-04?). See python-jsonschema/jsonschema#705 for upstream discussion when I raised this last year.

It's a nice feature to have, but might not be practical short of the 'rewrite everything to use objects and track schema version etc' plan that is eternally somewhere low on my todo list 😕

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