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 for multipart/mixed Content-Type #303

Closed
grokify opened this issue Mar 10, 2015 · 18 comments
Closed

Support for multipart/mixed Content-Type #303

grokify opened this issue Mar 10, 2015 · 18 comments

Comments

@grokify
Copy link

grokify commented Mar 10, 2015

I have a use case to support the multipart/mixed content type as defined in RFC 2049. Use of this content type includes support for:

  • multiple parts in sequence
  • each part with its own content type and data
  • each part separated by a boundary value included in the HTTP request Content-Type header

It seems like it would be ideal if Swagger could enable defining each part as a parameter with content type and, on submission, have Swagger UI create the MIME boundary, add the boundary to the HTTP request Content-Type header, and assemble the multipart parameters into a multi-part request body using the boundary.

It would be great to support this in Swagger natively.

@yonderblue
Copy link

👍 for implementing this :)

@yonderblue
Copy link

Is there some way that a work around to at least allow a user to hand enter (or use the example to enter) the http body (including sub requests with their headers etc) and get them all back for multipart/mixed request/response?

@grokify
Copy link
Author

grokify commented Jun 1, 2015

As a workaround for a multipart/mixed request, I'm currently hardcoding a boundary value in the consumes MIME type and as example text in the body. It's not very flexible but it's straightforward and has been used by lots of people successfully so far. For example:

"consumes" : ["multipart/mixed; boundary=Boundary-----1234567890"],
"parameters" : {
     "in": "body",
     "default" : "--Boundary-----1234567890\n ... EXAMPLE HERE ... \n--Boundary-----1234567890--"
}

@yonderblue
Copy link

@grokify that's good to know thanks i'll try this out first thing tomorrow, how about the response though? So far I haven't been able to get it to show a response with multipart/mixed at all.

@yonderblue
Copy link

The above doesn't pass the validator, you have to add "schema": { "type": "string" } for that, and then the default field is at odds with the validator too, looks like a bug.

If only the default would work and a simple string example response I think most would be in business with at least a workaround.

@webron
Copy link
Member

webron commented Jun 3, 2015

@Gaillard - when you say 'allow the user to hand enter', do you mean via swagger-ui or in general?

@yonderblue
Copy link

Yes I mean in the UI. It would be great if the user could choose content type, body and headers of each multi part, but as a work around if we could let the user hand enter that like @grokify showed it would help tremendously. His way works unless you also want it to run through the validator, can that bug be fixed?

@webron
Copy link
Member

webron commented Jun 3, 2015

@Gaillard you have to add schema to the parameter. While I'd normally discourage the following definition, as a workaround you can try this:

"consumes" : ["multipart/mixed; boundary=Boundary-----1234567890"],
"parameters" : {
     "in": "body",
     "schema": { "type": "object" },
     "default" : "--Boundary-----1234567890\n ... EXAMPLE HERE ... \n--Boundary-----1234567890--"
}

@yonderblue
Copy link

That does not pass the validator though. I'm running the validator locally.

@webron
Copy link
Member

webron commented Jun 3, 2015

What error do you get from the validator?

@yonderblue
Copy link

That the schema doesn't match. [{"level":"error","domain":"validation","keyword":"oneOf","message":"instance failed to match exactly one schema (matched 0 out of 2)","schema":{"loadingURI":"http://swagger.io/v2/schema.json#","pointer":"/definitions/parametersList/items"},"instance":{"pointer":"/paths/~1{version}~1batch/post/parameters/1"}}]

@yonderblue
Copy link

Also an example of the response does not work. Just like for this to be useful without full multipart/mixed support, we need a default to show the user in and out. It works with object schema type for the response but then shows in the example model like

{
  "multipart/mixed; boundary=test": "TODO the example"
}

which doesn't make any sense and why I was trying to use type string. So if the way it works with object could be there for string, it would be a decent workaround.

@webron
Copy link
Member

webron commented Jun 3, 2015

@Gaillard - let's take this to the google group as it's not directly related to the issue (this is just a workaround we're trying to employ, it won't change the issue at hand). There, just provide me with the definition of the POST /{version}/batch path, what you expect to see in the ui and what you actually experience.

@yonderblue
Copy link

Ok posted, thanks

@tleyden
Copy link

tleyden commented Dec 3, 2015

Feature request: multipart/related (merging #520 into this)

@perotom
Copy link

perotom commented Sep 16, 2016

Any updates on Content-Type and boundary?

@fehguy
Copy link
Contributor

fehguy commented Feb 1, 2017

See #878

@handrews
Copy link
Member

Has anyone involved in this thread used multipart/mixed with OpenAPI 3? If so, how did you correlate the parts with the named properties in the schema? This has come up several times recently without any clear answer, which led me to essentially re-file this issue as #3721. But if there is a pattern that works as-is, even if it's only in some circumstances, we should document that in the 3.0.4 and 3.1.1 patch releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants