Created by: locosmac
When calling an api that returns an optional result, the generated swift 5 client with url session implementation tries to unwrap nil and crashes, in cases where the called endpoint actually returns no data. I think that this is due to the fact that it is never possible to cast Optional < T >.none to T. The solution implemented here is stolen from https://stackoverflow.com/questions/41492153/how-to-produce-a-nil-of-a-generic-type and it works for me.
You can reproduce this, for example, using the MoWeSta Api (https://www.mowesta.com/api/mowesta.json) using the api call that returns the nearest weather station for a city (/cities/{id}/station). If you call this with a city id that does not lie near Germany (e.g. Essen in Belgium, id: 81211), the api responds with 201 (success, no data) and no data (i.e. no weather station). As a result, the client will try to return a nil value which will cause the process to crash.
With the change applied, the client works as expected.
@jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @d-date (2018/03)
PR checklist
-
Read the contribution guidelines. -
Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community. -
Run the following to build the project and update samples: ./mvnw clean package ./bin/generate-samples.sh ./bin/utils/export_docs_generators.sh
./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH. -
File the PR against the correct branch: master
(6.1.0) (minor release - breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks) -
If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.