Closed spacether closed 5 months ago
Form here in the spec:
To upload multiple files, a multipart media type MUST be used:
requestBody:
content:
multipart/form-data:
schema:
properties:
# The property name 'file' will be used for all files.
file:
type: array
items: {}
It looks like explode=True for multipart form arrays of files.
explode=True is not working for multipart/form-data request
The style
field in the Encoding Object is only valid for application/x-www-form-urlencoded
, so it cannot be used with multipart
media types.
I'm fairly certain that means that the cases asked about in this issue are all invalid.
style is defined as Describes how a specific property value will be serialized depending on its type. See [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject) for details on the [style](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterStyle) property. The behavior follows the same values as query parameters, including default values. This property SHALL be ignored if the request body media type is not application/x-www-form-urlencoded or multipart/form-data. If a value is explicitly defined, then the value of [contentType](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#encodingContentType) (implicit or explicit) SHALL be ignored.
So isn't multipart/form-data
explicitly covered by style?
Also this issue asks for clarification when style is unset. If the answer is to point to an RFC that is fine, but the RFCs that I looked at lacked these examples.
@spacether I see what's going on here. In OAS 3.0, style
and explode
apply only to application/x-www-form-urlencode
, but in OAS 3.1 they apply to both application/x-www-form-urlencoded
and multipart/form-data
.
So if @MHamzaRajput is using OAS 3.0, that would explain why explode: true
is not working for them.
Regarding your questions (in the context of OAS 3.1):
explode
. If I am reading this right, exploding the array just means making a part of the multipart
for each element, and that's no more or less complicated for any of the options you raise, including binary application/octet-stream
(it's arguably less complicated, as I have no idea what you'd do with an unexploded array of binary data - you can't stuff it in a JSON array, for example)application/json
for an empty array if you would have been sending application/json
for a non-empty one. An empty array shouldn't change the nature of the data, just the amount.At minimum, a bit of clarification on the expected string form of boolean and null values is probably worth including in a patch release, so I'm labeling this appropriately. Even if that clarification ends up being "do whatever works for your environment." For example, Perl does not have a boolean type, so it's not always possible to round-trip JSON-like booleans.
PR merged for 3.0.4 and ported to 3.1.1 via PR #3921! This is addressed in the new Appendix B.
Can we get clarification on how to post multipart form data with an array of items of type X? Here is an example requestBody:
1 What if x is a boolean?
It looks like this PR is related: https://github.com/OAI/OpenAPI-Specification/pull/2066