OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Swift6] Binary file uploads not working as expected
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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
Setup is with cocoapods currently (if this matters).
We have a problem making binary uploads work with our Backend (Java Spring Boot), as per definition appended here, this seems to be the most best practice to define a file upload. The generated code can't seem to differentiate between a binary file upload (mapFileBinaryToData: true) and a fileURL upload, it packs everything that is Data into an encoded base64 string.
The generated code generates this for file uploads:
This will encode it asParameter and as it is Data he will then encode it to base64 string.
When the upload happens, it will then correctly create a FormDataEncoding-Object:
But on the switch of key value, it will then go into the string part (as it is base64 encoded) instead of being Data as it is a binary upload.
We didn't found a way to determine if we have binary data in this switch and all deterministic functions that help to get information if this base64 string is actually only Data seem not solid enough.
So is there any way that we can make "normal" application/json base64encoded Data uploads and uploads with
mapFileBinaryToData: true work in the same generated code?
openapi-generator version
7.13.0 with latest swif6 templates
OpenAPI declaration file content or url
openapi: 3.0.3
info:
contact:
email: foo@bar.com
name: name
description: none
title: test api
version: 1.0.0
externalDocs:
description: ''
url: ''
servers:
- url: '{protocol}://{environment}:{port}/someapi/v1'
paths:
/test_request/upload_file:
post:
description: upload files
operationId: uploadAttachements
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/uploadAttachements_request'
required: true
responses:
'200':
content: {}
description: Success
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorInformation'
description: Error
'500':
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorInformation'
description: Error
summary: upload files
components:
schemas:
ErrorInformation:
description: ErrorInformation.
properties:
code:
description: code.
example: 1002
format: int32
type: integer
message:
description: text.
example: Required value in FileMetaData is missing.
type: string
required:
- code
- message
type: object
uploadAttachements_request:
properties:
attachments:
items:
description: something.
format: binary
type: string
type: array
type: object
Generation Details
java -Dlog.level=warn \
-jar openapi-generator-cli-7.13.0.jar generate \
-g swift6 \
--global-property skipFormModel=false \
--ignore-file-override "${myDir}/Config/openapi-generator-ignore.txt"
openapi-generator-ignore.txt
**/*
!**/OpenAPIs/APIHelper.swift
!**/OpenAPIs/CodableHelper.swift
!**/OpenAPIs/Configuration.swift
!**/OpenAPIs/Extensions.swift
!**/OpenAPIs/JSONDataEncoding.swift
!**/OpenAPIs/JSONEncodingHelper.swift
!**/OpenAPIs/Models.swift
!**/OpenAPIs/OpenISO8601DateFormatter.swift
!**/OpenAPIs/OpenAPIDateWithoutTime.swift
!**/OpenAPIs/SynchronizedDictionary.swift
!**/OpenAPIs/URLSessionImplementations.swift
!**/OpenAPIs/APIs.swift
!**/OpenAPIs/APIs/*
!**/OpenAPIs/Models/*
!**/OpenAPIs/Infrastructure/*
Config
{
"swiftUseApiNamespace": true,
"nonPublicApi": true,
"readonlyProperties" : true,
"useJsonEncodable": false,
"validatable": false,
"interfaceModuleName" : "NetworkService",
"useCustomDateWithoutTime": true,
"enumUnknownDefaultCase": true,
"useSPMFileStructure": false
}
Steps to reproduce
- generated code
- upload file via api
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the supplied OpenAPI YAML, Swift6 generator command, and configuration, then inspect the generated FormDataEncoding path and the Swift6 templates involved. Compare multipart/form-data binary handling with JSON Data encoding. Done means binary uploads remain binary while ordinary JSON Data continues to use base64 encoding, with coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, swift
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100