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][Swift5 client] bug with filename for binary downloads #9990

Closed
5 tasks done
gretzki opened this issue Jul 20, 2021 · 1 comment
Closed
5 tasks done

[BUG][Swift5 client] bug with filename for binary downloads #9990

gretzki opened this issue Jul 20, 2021 · 1 comment

Comments

@gretzki
Copy link
Contributor

gretzki commented Jul 20, 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?
Description

When a file download is handled within URLSessionImplementations,
the filename is retrieved via the header Content-Disposition part of the response.
The header is looked for an entry starting with filename=.
But the search is skipped too early, since the loop is exited if the first iteration does not match.

Example:
Try to download a file with a swift5 client for a spec like this:

  /PublicDocument/Download:
    get:
      tags:
        - Public Area
      description: 'Document Download for Public Documents. Login not Required'
      parameters:
        - $ref: '#/components/parameters/queryId'
      responses:
        '200':
          description: 'OK'
          content:
            application/pdf:
              schema:
                type: string
                format: binary

When downloading from a server, the response header could have an answer like so:

Content-Disposition: attachment; filename=downloaded.pdf; filename*=UTF-8''downloaded.pdf

There, the server says to use downloaded.pdf as filename. But the actual implementation of the swift5 client will exit after checking attachment and won't find filename= in the next section (separated by semicolon).

openapi-generator version

5.2.0

OpenAPI declaration file content or url
  /PublicDocument/Download:
    get:
      tags:
        - Public Area
      description: 'Document Download for Public Documents. Login not Required'
      parameters:
        - $ref: '#/components/parameters/queryId'
      responses:
        '200':
          description: 'OK'
          content:
            application/pdf:
              schema:
                type: string
                format: binary
Generation Details
java openapi-generator-cli-5.2.0.jar generate -g swift5 -i $apiSpecificationFile -c $configFile -o gen-ios

with apiSpecificationFile as listed above
with configeFile as follows

{
  "disallowAdditionalPropertiesIfNotPresent": false,
  "projectName": "MyApi",
  "readonlyProperties": true,
  "responseAs": "Combine",
  "swiftUseApiNamespace": "MyAPI",
  "useBacktickEscapes": true,
  "useSPMFileStructure": true,
  "generateAliasAsModel": true
}
Steps to reproduce
  1. Build the client
  2. use PublicDocumentDownload method against random server that responds as stated above
  3. the file is downloaded but without the proposed filename (including .pdf as file ending)
Related issues/PRs

none

Suggest a fix

See #9989

@gretzki
Copy link
Contributor Author

gretzki commented Jul 22, 2021

Closed by merging #9989

@gretzki gretzki closed this as completed Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant