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

[BUG][typescript-angular] PDF Response Type Treated As JSON #11021

Closed
5 of 6 tasks
oaklandcorp-jkaiser opened this issue Dec 2, 2021 · 0 comments · Fixed by #11085
Closed
5 of 6 tasks

[BUG][typescript-angular] PDF Response Type Treated As JSON #11021

oaklandcorp-jkaiser opened this issue Dec 2, 2021 · 0 comments · Fixed by #11085

Comments

@oaklandcorp-jkaiser
Copy link
Contributor

oaklandcorp-jkaiser commented Dec 2, 2021

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

A runtime exception occurs when invoking a service method using options
{httpHeaderAccept: 'application/pdf'} when that route supports multiple media
types because it appears to be treated as JSON in the generated service code.

openapi-generator version

<= 5.3.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
    version: '1.0'
    title: Document API
paths:
    /document:
        get:
            summary: Returns a document.
            responses:
                '200':
                    description: Found a document.
                    content:
                        text/plain:
                            schema:
                                type: string
                        application/pdf:
                            schema:
                                type: string
                                format: binary
Generation Details
openapi-generator generate -g typescript-angular -i example.yaml
Steps to reproduce

Generate a client using the provided OpenAPI spec and command. Invoke the
documentGet method of default.service.ts.

service.documentGet('body', false, {httpHeaderAccept: 'application/pdf'});
Related issues/PRs

None.

Suggest a fix

A minimal fix would be to expand the logic to decide the response type found in
the api.service.mustache template to include blob MIME types.

diff --git a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache
index b7dd7cbd94b..f33a19132e4 100644
--- a/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache
+++ b/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache
@@ -349,9 +349,13 @@ export class {{classname}} {

 {{/hasFormParams}}
     {{^isResponseFile}}
-        let responseType_: 'text' | 'json' = 'json';
-        if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
-            responseType_ = 'text';
+        let responseType_: 'text' | 'json' | 'blob' = 'json';
+        if (localVarHttpHeaderAcceptSelected) {
+            if (localVarHttpHeaderAcceptSelected.startsWith('text')) {
+                responseType_ = 'text';
+            } else if (!localVarHttpHeaderAcceptSelected.includes('json')) {
+                responseType_ = 'blob';
+            }
         }

     {{/isResponseFile}}
@oaklandcorp-jkaiser oaklandcorp-jkaiser changed the title [BUG] Description [BUG][typescript-angular] PDF Response Type Treated As JSON Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant