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

Parameter that is required, but optional on the ModelField is has the "null" type included #1211

Open
gabn88 opened this issue Mar 22, 2024 · 1 comment

Comments

@gabn88
Copy link

gabn88 commented Mar 22, 2024

Describe the bug
A model with a public_access_uuid (UUIDField(blank=True,null=True)) is used as a path paramater, let's say:

/api/order/{public_access_uuid}

This results in a scheme:

      parameters:
        - in: path
          name: public_access_uuid
          schema:
            type:
              - string
              - 'null'
            format: uuid
          required: true

As you can see the 'null' and required: true do bite eachother. And because of this scheme, the swagger-ui cannot be used for this endpoint and gives Required field is not provided.

To Reproduce
Add a ModelField like about.
Add a ModelSerializer with that field as lookup_field.

Expected behavior
The null type can be omitted.

I tried to explicitly add a public_access_uuid = serializers.UUIDField, with different options (required=True, allow_null=False), but that did not help.

I have now overridden it with:

    parameters=[
        OpenApiParameter(
            "public_access_uuid", OpenApiTypes.UUID, OpenApiParameter.PATH
        ),  # path variable was overridden
    ],

And that works, but it would be nice to have it work out of the box.

@gabn88
Copy link
Author

gabn88 commented Mar 22, 2024

This seems to have to do with using OpenAPI 3.1.0. If I load our schema in the OpenAPI editor it also shows an error on those lines, while the OpenAPI next-editor does not stumble over these lines.

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

1 participant