swagger-codegen
swagger-codegen copied to clipboard
Non-body HTTP method cannot contain @Body
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
DELETE ops shouldn't have a request body. The entity to delete should be fully identified in the URL.
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.
You can override this by using
@HTTP(method = "DELETE", path = "v1/...", hasBody = true)
instead of @DELETE
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