Swagger-codegen: Non-body HTTP method cannot contain @Body

Created on 21 Aug 2017  路  2Comments  路  Source: swagger-api/swagger-codegen

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

Most helpful comment

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings