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.98k stars 6.03k forks source link

[typescript-fetch] HTTP 204 - Client leave exception #10470

Open Ealenn opened 4 years ago

Ealenn commented 4 years ago

Hello ! If I have time, I would propose PR, otherwise someone will do it (I hope ❤)

Describe the bug In the case of a REST call that returns a 204 (No-Content)

https://github.com/swagger-api/swagger-codegen/blob/b821aab2df0ce93ca26953ab46d01d11521af0fa/modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache#L269

The client leave exception here :

https://github.com/swagger-api/swagger-codegen/blob/b821aab2df0ce93ca26953ab46d01d11521af0fa/modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache#L270

Expected behavior The client must be return promise with null response

ntoljic commented 3 years ago

Hi!

I just hit this issue as well. When the server returns 204 and correctly omits the response body the generated client code fails as it still attempts to parse a JSON response.

This also affected the typescript-angular2 generator, (https://github.com/swagger-api/swagger-codegen/issues/3129) although it has been fixed. The fix for the typescript-fetch generator should be similar.