tfranzel / drf-spectacular

Sane and flexible OpenAPI 3 schema generation for Django REST framework.
https://drf-spectacular.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.38k stars 264 forks source link

`OpenApiParameter` with Python `float` type is incorrectly labeled as `float` (32-bit) OpenAPI format rather than `double` (64-bit) #687

Closed johnthagen closed 2 years ago

johnthagen commented 2 years ago

Describe the bug OpenApiParameter with the native Python float type is formatted as a 32-bit float rather than 64-bit double.

Related to #674

To Reproduce

Use drf-spectacular 0.22.0.

input_param = OpenApiParameter(
    name="input",
    description="Description",
    type=float,
    default=1.0,
)

class MyViewSet(RetrieveModelMixin, GenericViewSet):
    @extend_schema(parameters=[input_param])
    def retrieve(self, request: Request, *args: Any, **kwargs: str) -> Response:
        ...

The resulting schema:

        schema:
          type: number
          format: float
          default: 1.0

Expected behavior

Expected schema

        schema:
          type: number
          format: double
          default: 1.0
tfranzel commented 2 years ago

well, that was a kind of obvious oversight, but iteration is our business, right? :laughing:

johnthagen commented 2 years ago

I can confirm that 0.22.1 fixes this issue. Thanks!