swagger-api / swagger-api/swagger-codegen

[typescript-fetch] Add support for file (application/octet-stream) response types

Open
#8,409 3 comments 4 reactions 1 assignee View on GitHub

@HugoMario is already working on this.

Since May 8, 2020.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

Currently, swagger attempts to process file (application/octet-stream) response content as JSON. In particular, swagger calls response.json(), which results in an error.

Swagger-codegen version

v2.4.0 - master.

Swagger declaration file content or url
return fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options).then((response) => {
  if (response.status >= 200 && response.status < 300) {
    return response.json();  // Throws "Uncaught (in promise) SyntaxError: Unexpected token % in JSON at position 0"
  } else {
    throw response;
  }
});
Command line used for generation

java -jar ./other_modules/swagger/swagger-codegen-cli.jar generate -i http://localhost:8011/swagger/v1/swagger.json -l typescript-fetch -o ./other_modules/swagger/output

Steps to reproduce

Run swagger-codegen against an API that produces application/octet-stream content.

Suggest a fix/enhancement

Modify the api.mustache file for typescript-fetch as need be (make reference to typescript-angular module where support for file response types has already been added), using the isResponseFile flag. When isResponseFile is true, return the response content as blob -> return response.blob();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.