multipart/form-data ambiguity #5321
Replies: 2 comments 1 reply
-
Since
I don't think this is necessary because the problem you're trying to solve is one of a header advertising a value instead of needing a schema constraint, and that's one of the core problems we're trying to solve with SAFs (#5310). So I think whatever solution we come up with there is what should be used here. However, I don't really think this needs much of a solution anyway. There's nothing meaningful you can do with |
Beta Was this translation helpful? Give feedback.
-
|
Okay I've gotten deeper into multipart/form-data serialization and what I've come up with is:
[
{ "name": "alpha", "value": "blip" },
{ "name": "beta", "value": "blop" },
]Then, we take a look at the corresponding schema (or itemSchema) and determine whether the desired type is an object or an array. If it's an array, we leave it as-is, and we can go ahead with parsing the individual parts further and use any This somewhat contradicts the spec which says "The prefixEncoding field can be used with any multipart content to require a fixed part order. This includes multipart/form-data, for which the Encoding Object’s headers field MUST be used to provide the Content-Disposition and part name, as no property names exist to provide the names automatically." -- which seems to suggest that the deserialized format (presented to the serializer, as most of the spec is written from the perspective of serialization rather than deserialization) is simply an array of the parts themselves. I find this a bit odd because I would think that the consumer of the deserialized information would actually want to know the part names -- form data is not that useful without the names attached to them. If we just wanted an array of parts, we'd use something like multipart/mixed instead. And also - if we supply the deserialized data to the serializer with names intact, we don't need IMHO, I'd fix all this in Moonwalk. If the desired type is an object, we reshape the data to look just like what it does for application/x-www-form-urlencoded: {
"alpha": "blip",
"beta": "blop"
}or for names with multiple values: {
"alpha": "blip", "blup",
"beta": "blop"
}..and in this case the I've worked out a schema for form objects that will accomodate both a single value and multiple values in a clean way; I'll submit it soonish as an example that can be plopped into the "Encoding by Name" section or perhaps an appendix. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
https://spec.openapis.org/oas/latest#additional-encoding-approaches says that if we want to serialize an object as multipart/form-data but use a fixed part order (e.g. we sort alphabetically by "name"), the way to specify that in the OAD is with:
Now, when I deserialize this message content, and I get data that looks like:
{ alpha => "something-encoded", beta => "something-else-encoded" },..now I need to find the encoding object (
prefixEncodingentry) that corresponds with each property value so it can be appropriately further decoded. The spec suggests that I do this by looking at theheaderskeyword under eachprefixEncodingencoding object and parsing its schema -- this seems far too fragile to be useful as it cannot be expected to be implemented consistently across implementations.I would suggest one of these two alternatives:
when
prefixEncoding(as opposed toencoding) is present in the media-type object (oritemSchemais present instead ofschema), that the form data be decoded directly to an array instead of an object, and thenprefixEncodingobjects can be applied to each array item as normal for array content (after all, why would it be important to keep parts in a specific order in the message body if we're just going to deserialize back to an object anyway, where the ordering is lost? so surely the user wants the data in array form anyway);introduce a "name" property in the encoding object, which is to be used when
prefixEncodingoritemEncodingobjects are used (and ignored inencoding, as it is redundant with the property name for this encoding object). This provides a direct and unambiguous mechanism to find whichprefixEncodingentry corresponds to each value in the deserialized object.As an aside, this would also be a useful application of the parameters-in-headers idea (#2342), as then "name" could be indicated as a parameter under the header:
Beta Was this translation helpful? Give feedback.
All reactions