apple / apple/swift-openapi-generator

Support multiple contentTypes in encoding multipart/form-data

Open
#594 8 comments 0 reactions 0 assignees View on GitHub
area/generator kind/enhancement
Dominant language
Swift
Stars
2k
Forks
182
Avg merge
13h 28m
Merged PRs (30d)
5

Description

### Question

Hi !

I have tried to upload an image that can be either a png or a jpeg, but It didn't work for me.

Here's a demo of a requestBody that I used to achieve the following according to [OpenAPI encoding specification](https://spec.openapis.org/oas/v3.1.0#encoding-object):
```
requestBody:
description: The avatar file
required: true
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
encoding:
file:
contentType: image/png, image/jpeg
```

Unfortunatly, I'm getting this error:

`Validation warning: Inconsistency encountered when parsing ``: 'image/png, image/jpeg' could not be parsed as a Content Type. Content Types should have the format '/'. [context: codingPath=.paths['/profiles/{id}/avatar'].post.requestBody.content['multipart/form-data'].encoding.file.contentType, contextString=, subjectName=]warning: Validation warning: Inconsistency encountered when parsing ``: 'image/png, image/jpeg' could not be parsed as a Content Type. Content Types should have the format '/'. [context: codingPath=.paths['/profiles/{id}/avatar'].post.requestBody.content['multipart/form-data'].encoding.file.contentType, contextString=, subjectName=]Error: Invalid content type string: 'image/png, image/jpeg', must have 2 components separated by a slash.`

Can you tell me what I did wrong ?

Thanks !

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied OpenAPI document and trace validation of encoding.file.contentType from the reported parsing error. Check the OpenAPI encoding specification for the expected representation, then add or update focused validation coverage so multiple media types are accepted without warnings or errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, swift
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.