swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.74k stars 6.02k forks source link

Non-body HTTP method cannot contain @Body #6344

Open airshiplay opened 6 years ago

airshiplay commented 6 years ago

java.lang.IllegalArgumentException: Non-body HTTP method cannot contain @Body.

Description

generator code @DELETE("device/flexEng/tenant") Call deviceFlexEngTenantDelete( @retrofit2.http.Body FlexEngTenantDeleteParam flexEngTenantDeleteParam ); Adjust to @HTTP(method = "DELETE",path = "/device/flexEng/tenant",hasBody = true) Call deviceFlexEngTenantDelete( @retrofit2.http.Body FlexEngTenantDeleteParam flexEngTenantDeleteParam );

Swagger-codegen version

2.2.3 version

Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
cbornet commented 6 years ago

DELETE ops shouldn't have a request body. The entity to delete should be fully identified in the URL.

jbaldassari commented 5 years ago

DELETE ops shouldn't have a request body.

The HTTP spec does not explicitly forbid request bodies in DELETE requests. See https://tools.ietf.org/html/rfc7231#section-4.3.5

The entity to delete should be fully identified in the URL.

This is fine if your endpoint is designed to delete a single entity, but I need to perform a bulk delete of many entities within a single transaction. I'm not going to jam a potentially large number of entity IDs into the path or query string. It would be very handy to be able to send a DELETE request with a JSON body like:

[ "id-1", "id-2", "id-3", ..., "id-1000" ]

Since I can't do this I'll have to use a POST with an endpoint like /entity/type/bulkRemove which is not very RESTy. Swagger/retrofit should be less opinionated on this topic.

Boydroidnl commented 1 year ago

You can override this by using

@HTTP(method = "DELETE", path = "v1/...", hasBody = true)

instead of @DELETE

mrudulamrudu commented 5 months ago

Hi I am facing the similar issue with Android Retrofit Client.

@Headers({"Content-Type:application/json"}) @DELETE("account/delete/") Completable accountDeleteMe(@Body LoginRequest var1); is throwing IllegalParameter Exception because of the request body with delete. I am using swagger for generating DefaultApi.class.

I tried different things but I couldn't adjust @delete("some/api/call") TO @http(method = "DELETE",path = "/some/api/call",hasBody = true) in swagger. Can somebody let me know how to do it ? Thanks