swagger-api/swagger-codegen-generators

[typescript-angular] isFileResponse cannot be used

bender316 opened this issue · 2 comments

Hi,

I came across some odd behavior. I want to generate code for typescript-angular in which a Blob should be returned.

The operation is correctly recognized as a file response as the following expression is true:
https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java#L1688

The problem now is that one this line (an its following lines):
https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java#L2348

The IS_STRING_EXT_NAME expression always wins as it is set on line 1691.

Or am I wrong and I can change this behavior on the definiton side? This is how the Operation (or its response) is currently defined:

        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "*/*": { "schema": { "type": "string", "format": "binary" } }
            }
          }
        }

Hi @bender316
Can you tell what generated code are you expecting? I don't see any conflict in the line of code you point

Hi @HugoMario

sorry, I left out what was obvious for me 😁

The main problem arises in the lines 356-358:
https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/resources/handlebars/typescript-angular/api.service.mustache#L356

Because isFileResponse is always set to false the response type is never set to blob. As a result the server returns a binary stream whereas angular tries to parse it as JSON which fails.