You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 format float 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:
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:
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
As discussed, doing a float(value behind the scene using a validator may be counter-intuitive the users.
#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)
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: