swagger-api / swagger-api/swagger-codegen
[JavaScript + Promises] Unhandled Promise Rejection?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
It appears that ApiClient#callApi will return a rejected Promise if an error is present, but API operation methods only have resolution handlers. Furthermore, I'm of the opinion that operation methods should simply return the Promise regardless of its resolved or rejected status so that consumers of the SDK can decide what to do with it.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
http://petstore.swagger.io/v2/swagger.json
Command line used for generation
swagger-codegen generate \
-i http://petstore.swagger.io/v2/swagger.json \
-l javascript \
-o . \
--additional-properties usePromises=true,useES6=true
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
Current:
<operationId>(<vendorExtensions.x-codegen-argList>) {
return this.<operationId>WithHttpInfo(<vendorExtensions.x-codegen-argList>)
.then(function(response_and_data) {
return response_and_data.data;
});
}
Proposed:
<operationId>(<vendorExtensions.x-codegen-argList>) {
return this.<operationId>WithHttpInfo(<vendorExtensions.x-codegen-argList>);
}
// or...
<operationId>(<vendorExtensions.x-codegen-argList>) {
return this.<operationId>WithHttpInfo(<vendorExtensions.x-codegen-argList>)
.then(function(response_and_data) {
return response_and_data.data;
}, function(response_and_error) {
return response_and_error;
});
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/swagger-codegen/src/main/resources/Javascript/es6/ApiClient.mustache and api.mustache, then generate the petstore client using the command shown in the issue. Compare the generated operation methods with ApiClient#callApi and verify that rejected promises remain available to SDK consumers rather than becoming unhandled rejections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100