swagger server should return 204 when it has an empty response body
Currently when running the swift tests, we do an add/get/delete of orders and pets, but some of these calls return a 200 with an empty response body, which on the Swift client causes a failure because it tries to parse out an empty body. The Swift/Alamofire implementation looks specifically for 204 return codes to avoid parsing in these cases - can we modify the backend to do this as well to make the test program not have an error in this situation?
Here is a sample that creates/gets/then deletes an order, the delete returning no data:
curl -i \
-X POST
-H "Content-Type: application/json"
-H "Accept-Language: en-US;q=1.0"
-H "Accept-Encoding: gzip;q=1.0, compress;q=0.5"
-H "User-Agent: SwaggerClient/com.swagger.SwaggerClient (1; OS Version 9.3 (Build 13E5200d))"
-d "{"petId":1000,"shipDate":"2016-02-09","id":1000,"quantity":10,"status":"placed","complete":false}"
"http://petstore.swagger.io/v2/store/order"
HTTP/1.1 200 OK Date: Tue, 09 Feb 2016 20:46:21 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type, api_key, Authorization Content-Type: application/json Connection: close Server: Jetty(9.2.9.v20150224)
{"id":1000,"petId":1000,"quantity":10,"shipDate":"2016-02-09T00:00:00.000+0000","status":"placed","complete":false}Josephs-MacBook-Pro:swagger-codegen-jaz jaz$ Josephs-MacBook-Pro:swagger-codegen-jaz jaz$ Josephs-MacBook-Pro:swagger-codegen-jaz jaz$ curl -i \
-H "Accept-Language: en-US;q=1.0"
-H "Accept-Encoding: gzip;q=1.0, compress;q=0.5"
-H "User-Agent: SwaggerClient/com.swagger.SwaggerClient (1; OS Version 9.3 (Build 13E5200d))"
"http://petstore.swagger.io/v2/store/order/1000"
HTTP/1.1 200 OK Date: Tue, 09 Feb 2016 20:46:27 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type, api_key, Authorization Content-Type: application/json Connection: close Server: Jetty(9.2.9.v20150224)
{"id":1000,"petId":1000,"quantity":10,"shipDate":"2016-02-09T00:00:00.000+0000","status":"placed","complete":false}Josephs-MacBook-Pro:swagger-codegen-jaz jaz$ Josephs-MacBook-Pro:swagger-codegen-jaz jaz$ curl -i \
-X DELETE
-H "Accept-Language: en-US;q=1.0"
-H "Accept-Encoding: gzip;q=1.0, compress;q=0.5"
-H "User-Agent: SwaggerClient/com.swagger.SwaggerClient (1; OS Version 9.3 (Build 13E5200d))"
"http://petstore.swagger.io/v2/store/order/1000" HTTP/1.1 200 OK Date: Tue, 09 Feb 2016 20:46:32 GMT Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, DELETE, PUT Access-Control-Allow-Headers: Content-Type, api_key, Authorization Content-Type: application/json Connection: close Server: Jetty(9.2.9.v20150224)
Thanks for the details in showing the issue with the Swift API client.
Instead of updating the backend, I think we should update Swift API client as it's just a matter of time someone reports the same issue with their REST API backend that we do not have any control.
Is the issue you mentioned the same as this one: https://github.com/Alamofire/Alamofire/issues/852 ?
Can we ignore the parse error if there's no return type {{^returnType}} ... {{/returnType}} ?
yes that's the same issue as related to that Alamofire issue. ok let me look into how to better handle this in the swift client implementation.
In my project I worked around this issue by checking explicitly for the error code given in this situation, it would be great if the client will handle this correctly. It seems that in Alamofire 3.1.1 support for 204 responses was improved. We can probably make use of this.