Swagger openApi Spec 3.0 - DELETE operation

11,825

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.

Share:
11,825
Aravinth
Author by

Aravinth

Updated on August 29, 2022

Comments

  • Aravinth
    Aravinth about 1 year

    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
    
  • Aravinth
    Aravinth over 4 years
    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.