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] binary upload (application/octet-stream) are not working #17421

Closed
4 of 5 tasks
Stormshield-robinc opened this issue Dec 18, 2023 · 0 comments
Closed
4 of 5 tasks

Comments

@Stormshield-robinc
Copy link
Contributor

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

The swift5 generator is broken for API endpoint that should upload binary data (request body with a "application/octet-stream" content).

Currently, the generated code ask for a swift Url.
I would expect this to read the request body's data from the file at Url, but instead, it send the Url as is in the request body.
(Note: I find surprising to ask for a file Url instead of a Data, since we could want to generate the binary blob on the fly without using any file.)

I saw that there is an option named mapFileBinaryToData which replace the Url type with a Data one (but it is marked as deprecated).
With this option I am able to give the binary blob directly to the function, but instead of being send as is, it get base64 encoded.

Looking into the code I can see that this is a bug, as there is no piece of code to read a file, and as we never add the "application/octet-stream" content-type (which explain the base64 encoding since we default to json)

openapi-generator version

master

OpenAPI declaration file content or url

Here is a minimalist file for reproduction

{
  "openapi": "3.0.0",
  "info": {
    "title": "Test",
    "description": "Test",
    "version": "6.2.1"
  },
  "paths": {
    "/send_binary_blob": {
      "post": {
        "tags": [
          "Test"
        ],
        "description": "Test the upload of a file (or binary blob)",
        "operationId": "test",
        "parameters": [],
        "requestBody": {
          "description": "Byte stream",
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              },
              "example": ""
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Return some message",
            "content": {
              "text/plain; charset=utf-8": {
                "example": "upload successful"
              }
            }
          },
          "403": {
            "description": "Access forbidden.",
            "content": {
              "text/plain; charset=utf-8": {
                "example": "access denied"
              }
            }
          },
          "422": {
            "description": "Unprocessable entity.",
            "content": {
              "text/plain; charset=utf-8": {
                "example": "unprocessable entity"
              }
            }
          },
          "500": {
            "description": "Internal server error.",
            "content": {
              "text/plain; charset=utf-8": {
                "example": "internal server error"
              }
            }
          }
	}
      }
    }
  }
}
Generation Details

No special option, just generate the API with -g swift5

Steps to reproduce

Generate the swift code from the above json and try to use the endpoint with a Url.
See that it is not sending the binary data

Related issues/PRs

Very similar problem
#14268

PR that introduced file upload
#16299
With its issue
#16300

Suggest a fix

PR incoming

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

2 participants