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

Can't create a request body that is an array of integers #1014

Closed
bryandyck opened this issue Jun 22, 2023 · 2 comments
Closed

Can't create a request body that is an array of integers #1014

bryandyck opened this issue Jun 22, 2023 · 2 comments

Comments

@bryandyck
Copy link

Describe the bug
I'm using the extend_schema to specify a request body that is simply an array of integers, however in the generated schema (no errors or warning were displayed during the generation) the request body is simply omitted.

To Reproduce

    @extend_schema(
        operation_id='batch_delete_material',
        summary='Batch Delete Material',
        description="""Performs batch delete of materials records. The request body must be a an array of ids.""",
        request={
            "type": "array",
            "items": {"type": "integer"}
        },
        responses=common_types.BATCH_JOB_RESPONSES
    )
    @action(methods=['DELETE'], detail=False)
    def batch_delete_method(self, request):
        return super().batch_delete_method(request)

generates this schema:

        "/api/v1/batch_delete_method/": {
            "delete": {
                "operationId": "batch_delete_material",
                "description": "Performs batch delete of materials records. The request body must be a an array of ids.",
                "summary": "Batch Delete Material",
                "tags": [
                    "Global Configuration"
                ],
                "security": [
                    {
                        "jwtAuth": []
                    },
                    {
                        "tokenAuth": []
                    }
                ],
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "string",
                                            "format": "uuid"
                                        }
                                    }
                                }
                            }
                        },
                        "description": "Successful response."
                    }
                }
            }
        },

Expected behavior
I expected there to be a requestBody parameter with an appropriate schema such as:

        "/api/v1/batch_delete_method/": {
            "delete": {
                "operationId": "batch_delete_material",
                "description": "Performs batch delete of materials records. The request body must be a an array of ids.",
                "summary": "Batch Delete Material",
                "tags": [
                    "Global Configuration"
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "array",
                                "items": {
                                    "type": "integer"
                                }
                            }
                        }
                    },
                    "required": true
                },
                "security": [
                    {
                        "jwtAuth": []
                    },
                    {
                        "tokenAuth": []
                    }
                ],
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "string",
                                            "format": "uuid"
                                        }
                                    }
                                }
                            }
                        },
                        "description": "Successful response."
                    }
                }
            }
        },
@tfranzel
Copy link
Owner

Hey @bryandyck, that is on purpose and has been raised before. See #809 for a detailed explanation.

tldr: OpenAPI 3.0.3 (we are not yet on 3.1) does not support request bodies on DELETE operations.

@bryandyck
Copy link
Author

Thanks @tfranzel!

@bryandyck bryandyck closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2023
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

2 participants