Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spallister opened this issue Jul 10, 2018 · 3 comments · May be fixed by #8410
Open

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

spallister opened this issue Jul 10, 2018 · 3 comments · May be fixed by #8410
Assignees

Comments

@spallister
Copy link

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();

@someone1
Copy link

Is there any known workaround other than modifying the generated file?

@hypery2k
Copy link

would also like to see the possibility to use http options via generated artifacts. Should I fill a PR?

@frantuma
Copy link
Member

Thanks! a PR is more than welcome

@HugoMario HugoMario self-assigned this May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants