swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Non-body HTTP method cannot contain @Body

Open airshiplay opened this issue 7 years ago • 4 comments

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

Description

generator code @DELETE("device/flexEng/tenant") Call<FlexResultResponse> deviceFlexEngTenantDelete( @retrofit2.http.Body FlexEngTenantDeleteParam flexEngTenantDeleteParam ); Adjust to @HTTP(method = "DELETE",path = "/device/flexEng/tenant",hasBody = true) Call<FlexResultResponse> 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

airshiplay avatar Aug 21 '17 04:08 airshiplay

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

cbornet avatar Aug 21 '17 08:08 cbornet

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.

jbaldassari avatar Oct 18 '18 19:10 jbaldassari

You can override this by using

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

instead of @DELETE

Boydroidnl avatar Oct 03 '22 13:10 Boydroidnl

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

mrudulamrudu avatar Jan 17 '24 19:01 mrudulamrudu