openapi-typescript-codegen icon indicating copy to clipboard operation
openapi-typescript-codegen copied to clipboard

Pdf file request with response headers

Open bertramr opened this issue 3 years ago • 1 comments

We have a similar problems like #829 and #981, when trying to access an endpoint with a pdf file and the filename in the header.

Therefore I started working on this branch and fixed it (at least for our problem). Please be aware that this pull request at the moment would introduce breaking change and I doubt it is in the sense of the original design. So in effect I don't expect this to be merged but I still hope it might be useful for someone.

  • ApiResult is now a Generic with body and header.
  • During getOperation both the header and the content from the responses are pushed to the list, handled to create the necessary entries and finally the header is dropped, in order to not polluting the types.
  • A new request function is added, which is chosen, when a responseHeader is included in the options. With that it only includes still only one header

Known short comings:

  • Still only handles one header
  • It is always expected that the first entry is the entry with the binary type, which is not guaranteed to best of my knowledge
  • If a responseHeader is set, the return type is now always a ApiResult and no longer a string.
  • It's missing additional test cases to verify the added behavior

This branch includes other than stated in the contribution guideline merge commits from the two open pull requests (#1037 and #986 )

Would be happy about any feedback.

Best regards and thank you very much for this neat code generator

bertramr avatar May 17 '22 21:05 bertramr

nice

ufon avatar May 24 '22 09:05 ufon