swagger-api / swagger-api/swagger-codegen
[JAVASCRIPT] NodeJS undefined result when calling endpoints that return blob
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When generating a Javascript client for an API that returns a byte stream, the client is documented to receive a "Blob" type. In ApiClient.js's deserialize method, there is a check to see if response.body is either null or an object with no keys, and if so, response.text will be returned as-is. It turns out that response.body is an empty object when running under NodeJS. This causes the logic to use response.text which is undefined, because the incoming stream should be read from response.res, which is not handled at all by the deserialize method.
Swagger-codegen version
2.4.0, not a regression.
Swagger declaration file content or url
{
"responses": {
"200": {
"description": "successful operation",
"schema": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
}
}
}
}
Command line used for generation
config:
{
"usePromises": true,
"useES6": false
}
command-line:
$SWAGGER_CODEGEN generate \
-l javascript \
-i $SWAGGER_URL \
-c js-config.json \
-o $OUTPUT_DIR
Steps to reproduce
Call the client code as normal. It actually makes a successful request to the remote endpoint, but it returns a Promise that resolves to undefined.
Related issues/PRs
This one is similar but not completely related:
https://github.com/swagger-api/swagger-codegen/issues/3297
Suggest a fix/enhancement
For NodeJS, it would be possible to check if response.res is a readable stream, and use it. I don't know how this will affect browsers though.
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 in the generated JavaScript client's ApiClient.js and inspect the deserialize method, especially its handling of response.body, response.text, and response.res. Reproduce the byte-stream endpoint case under NodeJS and verify that the returned Promise resolves to the response data rather than undefined, while checking the browser behavior described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100