3

I am using swagger openapi specification 3.0 to generate swagger from my interface. I have a delete method where it accepts request-body. But according to RFC7231, DELETE does not accept any request body. Also Swagger-request body tells that so. But my API is designed to accept request body in DELETE operation. Is there any work around in creating swagger such that DELETE operation accepts request body. Currently what error I am getting from swagger generation is,

Sematic error: DELETE operations cannot have a requestBody
Zafrullah Syed
  • 1,170
  • 2
  • 15
  • 38
Aravinth
  • 686
  • 2
  • 8
  • 14

2 Answers2

8

No, you cannot use the OpenAPI 3.0 Specification and Swagger tools to implement DELETE requests with a request body. As you correctly pointed out, the HTTP RFC says the DELETE request body has no defined semantics (and thus should be avoided), and OpenAPI 3.0 specifically disallows bodies in HTTP methods where the body does not have defined semantics. See this discussion for some context.

Consider changing your API design, for example, replace the DELETE body with path, query string or header parameters. Check out RESTful Alternatives to DELETE Request Body for some ideas.

Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thank you Helen. Only possible way is to change the API design. Thought is there any way to generate but found nothing. We have to follow the rule else we'll be ruled. Closing this one. – Aravinth Mar 05 '19 at 05:42
0

This type of operation (DELETE, GET requests with a body) was explicitly banned in Open API 3.0. Prior to that it was allowed or vague.

jsuperh
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 07 '22 at 18:52