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

Ability to download file #242

Open
dlabs-matic-leva opened this issue Jun 21, 2024 · 0 comments
Open

Ability to download file #242

dlabs-matic-leva opened this issue Jun 21, 2024 · 0 comments

Comments

@dlabs-matic-leva
Copy link

Use case

I'd like to consume endpoint that generates .pdf file. This is OpenAPI schema for such endpoint:

    "/api/transfers/export.pdf": {
      "get": {
        "operationId": "exportPdf",
        "summary": "",
        "parameters": [
          {
            "name": "filter",
            "required": false,
            "in": "query",
            "style": "deepObject",
            "explode": true,
            "schema": {
              "$ref": "#/components/schemas/ExportTransfersFilters"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "description": ""
          }
        },
        "tags": [
          "Transfers"
        ],
        "security": [
          {
            "oauth2": [
              
            ]
          }
        ]
      }
    },

Currently swagger_parser generates such method:

  @GET('/api/transfers/export.pdf')
  Future<String> exportPdf({
    @Query('filter') ExportTransfersFilters? filter,
  });

which in turn generates Dio.fetch call with ResponseType == ResponseType.json. In case of PDF, this yields corrupted file.

Proposal

Such Retrofit definition will generate correct Dio.fetch call:

  @GET('/api/transfers/export.pdf')
  @DioResponseType(ResponseType.bytes)
  Future<HttpResponse> exportPdf({
    @Query('filter') ExportTransfersFilters? filter,
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant