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

OpenAPI 3.1 supports Body for DELETE method #1432

Closed
jsg91 opened this issue Oct 24, 2024 · 5 comments · Fixed by #1436
Closed

OpenAPI 3.1 supports Body for DELETE method #1432

jsg91 opened this issue Oct 24, 2024 · 5 comments · Fixed by #1436
Labels
Milestone

Comments

@jsg91
Copy link

jsg91 commented Oct 24, 2024

Describe the Bug

OpenAPI 3.1 supports Body for DELETE method, if condition in OpenApi.ps1 doesn't allow it:

if (('POST', 'PUT', 'PATCH') -inotcontains $r.Method ) {

Steps To Reproduce

Steps to reproduce the behavior:

  1. Set up a DELETE API requiring a body
  2. Start server
  3. See error in ErrorLog

Expected Behavior

Should work, especially if Enable-PodeOpenApi -OpenApiVersion is defined as "3.1.0"

@mdaneri
Copy link
Contributor

mdaneri commented Oct 24, 2024

According to the OpenAPI 3.x specification, the request body is explicitly supported for POST, PUT, and PATCH methods, but not for GET, DELETE, or HEAD. This limitation isn’t just a constraint of OpenAPI—it’s based on the HTTP standards outlined in various RFCs, particularly RFC 7231.

While HTTP itself does not prohibit sending a body in GET or DELETE requests, RFC 7231 (which defines the semantics and content of HTTP methods) makes no provision for how servers should interpret or handle a body for these methods. As a result, behavior is inconsistent across different implementations, and many server frameworks either ignore or outright reject bodies for GET and DELETE requests.

The HTTP RFCs suggest that GET should retrieve resources, and DELETE should remove resources. Neither of these actions typically requires a body to define the action being performed, hence the lack of a formal specification supporting it. For example:

•	POST is used for creating resources and can have a complex request body.
•	PUT is used to update or replace a resource, which also requires a body to describe the new state of the resource.
•	PATCH allows partial updates and likewise depends on a body to specify the changes.

For DELETE, the common expectation is that the resource to be deleted is identified by the URL alone, without needing additional data in the body. Although some server implementations might permit bodies with DELETE requests, this is not standardized or recommended in the RFCs, leading to potential interoperability issues.

Thus, OpenAPI adheres to these guidelines to maintain compatibility across different servers and implementations, ensuring that request bodies are used only with methods where they are clearly defined by HTTP standards.

For more information, you can refer to the official OpenAPI documentation:
https://swagger.io/docs/specification/v3_0/describing-request-body/describing-request-body/

@jsg91
Copy link
Author

jsg91 commented Oct 24, 2024

From what I've seen, one should avoid using a Body for a DELETE. However, I have a requirement where the delete calls need a few more parameters than I want to put in the URL. For that very reason, probably OpenAPI allows it in their latest standard. Thus it's hindering in my case for Pode to not allow it

@mdaneri
Copy link
Contributor

mdaneri commented Oct 24, 2024

You can pass the body content as a JSON/YAML/XML header.
That is supported

@mdaneri
Copy link
Contributor

mdaneri commented Oct 24, 2024

Do you have a link that says Delete body is supported openapi?

@jsg91
Copy link
Author

jsg91 commented Oct 24, 2024

Do you have a link that says Delete body is supported openapi?

https://spec.openapis.org/oas/v3.1.0.html#operation-object under Field Name requestBody

mdaneri added a commit to mdaneri/Pode that referenced this issue Oct 26, 2024
mdaneri added a commit to mdaneri/Pode that referenced this issue Oct 26, 2024
@Badgerati Badgerati added this to the 2.11.1 milestone Oct 28, 2024
Badgerati added a commit that referenced this issue Oct 28, 2024
Add -AllowNonStandardBody Parameter to Enable Request Bodies for Non-Standard HTTP Methods (Address #1432)
@github-project-automation github-project-automation bot moved this from Backlog to Done in 🚀 Pode Roadmap Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
3 participants