-
Notifications
You must be signed in to change notification settings - Fork 260
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
Django FloatField
is incorrectly labeled as float
(32-bit) OpenAPI format rather than double
(64-bit)
#674
Comments
FloatField
is incorrectly labeled as float
(32-bit) OpenAPI format rather than double
(64-bit)
Hey John, excellent find! This must have slipped through the crack due to the imprecise naming. CPython uses double internally and postgres, mysql and oracle Django DB adapters all map to So it makes sense to change the default mapping. One note however, |
@tfranzel Would it be possible to get a release with this fix? |
@johnthagen it's coming very soon. just dealing with some loose ends. |
closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up. |
Sorry for the late reply. I tested 0.22.0 and can confirm this issue is fixed! Thanks! ❤️ |
Consider a Django model:
From the Django docs
float
's in Python are effectively always 64-bitdouble
precision floats (it may be possible on some bespoke embedded platforms like MicroPython they are something else, but those are out of scope for Django usage).But
drf-spectacular
, generates a schema for thisFloatField
of:According to the OpenAPI 3 spec, the correct format for this should be:
It's likely many users have not hit this because some common client languages (e.g. Python and JavaScript/TypeScript) only have one
float
/number
type so this would not have an impact on the generated client code.However, a language such as C# does have two different floating point types,
float
anddouble
. OpenAPI Generator using thecsharp-netcore
generator parses thedrf-spectacular
schema and uses 32-bit C#float
instead of 64-bitdouble
. This means that the client will lose precision that otherwise is stored in Django.Example C# output:
Expected output:
The text was updated successfully, but these errors were encountered: