-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[REQ][python-nextgen] Allow integers as numbers when no format is set #15098
Comments
robertschweizer
changed the title
[REQ][python-experimental] Allow integers as numbers when no format is set
[REQ][python-nextgen] Allow integers as numbers when no format is set
Mar 31, 2023
I agree and asked for this differentiation in this comment: #14618 (comment) |
6 tasks
As discussed, doing a #10541 introduces options to let users pick the right type for their use cases (based on the experience from pydantic project that no single solution fits all) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
With the current default
floatStrictType=true
, an integer passed in a field with "number" type and no format in the JSON schema raises a validation error. This should only happen for numbers with formatfloat
according to JSON schema (previously mentioned in #14618 (comment)).Describe the solution you'd like
For fields with type "number" and no format, integers should be allowed while still being strict about other types such as strings. This could be achieved with a pydantic validator that converts all fields with this type in a model:
Describe alternatives you've considered
Currently, I set
floatStrictType=false
, but this is not strict at all, i.e. it also coerces strings to float instead of raising a validation error. It is also inconvenient when getting started with the generator: The generated client by default does not follow the JSON schema spec.Additional context
With this change, the need for the
floatStrictType
config flag might go away. Converting ints to floats is as strict as possible and addresses the original issue #14499 that led to the introduction of the flag.The text was updated successfully, but these errors were encountered: