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

Support multiple contentTypes in encoding multipart/form-data #594

Open
mbachircherif opened this issue Jul 17, 2024 · 8 comments
Open

Support multiple contentTypes in encoding multipart/form-data #594

mbachircherif opened this issue Jul 17, 2024 · 8 comments
Labels
area/generator Affects: plugin, CLI, config file. kind/enhacement Improvements to existing feature.
Milestone

Comments

@mbachircherif
Copy link

mbachircherif commented Jul 17, 2024

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:

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 '<type>/<subtype>'. [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 '<type>/<subtype>'. [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 !

@mbachircherif mbachircherif added kind/support Adopter support requests. status/triage Collecting information required to triage the issue. labels Jul 17, 2024
@mbachircherif mbachircherif changed the title How to use multiple encoding in multipart/form-data ? How to use multiple contentType in encoding multipart/form-data ? Jul 17, 2024
@czechboy0
Copy link
Contributor

It seems that we (through using OpenAPIKit) don't currently support a list of contentType, please try again by removing the second content type and just keep one.

cc @mattpolzin If I'm reading this right, this should be valid: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#encoding-object

@czechboy0 czechboy0 added area/generator Affects: plugin, CLI, config file. kind/bug Feature doesn't work as expected. and removed status/triage Collecting information required to triage the issue. kind/support Adopter support requests. labels Jul 18, 2024
@czechboy0 czechboy0 changed the title How to use multiple contentType in encoding multipart/form-data ? Support multiple contentTypes in encoding multipart/form-data Jul 18, 2024
@czechboy0 czechboy0 added this to the Post-1.0 milestone Jul 18, 2024
@mattpolzin
Copy link

Yeah, a comma separated string is indeed valid there according to the spec. I just created a bug ticket to track this here.

@mbachircherif
Copy link
Author

mbachircherif commented Jul 19, 2024

Hi,

Thanks for your prompt response.
Noted, I'll be following till It's fixed ;)

@mattpolzin
Copy link

mattpolzin commented Jul 19, 2024

This has been fixed upstream as of OpenAPIKit 3.2.0. Parsing should be fixed just by updating; actually using multiple content types will require using the new OpenAPIKit.Content.Encoding property contentTypes.

The next alpha release of OpenAPIKit 4.0.0 (in the works right now) will also contain the fix OpenAPIKit 4.0.0-alpha.6 also contains the fix.

@simonjbeaumont
Copy link
Contributor

simonjbeaumont commented Jul 19, 2024

@mbachircherif would you confirm this resolved your issue by running swift package update?

Thanks @mattpolzin! 🙏

Or, I haven't actually checked (just doing drive by here). we might need to update the generator. In which case we'll do that soon.

@mbachircherif
Copy link
Author

mbachircherif commented Jul 20, 2024

@simonjbeaumont I confirm, no more issues after update.
Thanks all for your work !

@czechboy0
Copy link
Contributor

The OpenAPIKit fix should unblock parsing of the OpenAPI doc, and will mostly make this work. But not fully, because I suspect this way we only send the first content type, instead of allowing the adopter to choose from the list.

If we can confirm that's the case, we can use this issue to track adding fuller support.

@czechboy0 czechboy0 added kind/enhacement Improvements to existing feature. and removed kind/bug Feature doesn't work as expected. labels Oct 29, 2024
@czechboy0
Copy link
Contributor

The support in OpenAPIKit landed, for anyone interested in contributing the enhancement, you should be unblocked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/generator Affects: plugin, CLI, config file. kind/enhacement Improvements to existing feature.
Projects
None yet
Development

No branches or pull requests

4 participants