-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
For response body with Content-Type=text/plain, "style" and "explode" are undefined #2926
Comments
Sorry, my original description was a bit confused and I have corrected it. But this issue applies as well to a text/plain request body. I do see that it's incongruous for a general Media Type Object to address concerns for a specific media type. So I'm not sure how best to resolve the serialization ambiguity for text/plain. |
FWIW I don't see how media types can play along with "style" and "explode" at all. Using these keywords makes sense for parameters that don't have a media-type encoding at all, but surely all of the encoding/decoding would be indicated by the media type and there is no need for more. So for request/response bodies, which must always have a media type, it doesn't make sense at all. It would be nice to have some examples showing how these keywords can play together, or otherwise amend the specification to remove the use of style/explode for bodies entirely, and state that either a parameter has a media type, OR it uses style/explode, but not both. |
Consider the example below. In other situations, the API definition can specify an encoding using But in this situation? Bupkis. {
"openapi": "3.0.0",
"info": {
"title": "Text",
"version": "0.0.0"
},
"paths": {
"/object": {
"put": {
"requestBody": {
"content": {
"text/plain": {
"schema": {
"type": "object",
"properties": {
"A": {
"type": "string"
},
"B": {
"type": "number"
},
"C": {
"type": "boolean"
}
}
}
}
}
},
"responses": {
"2XX": {
"description": "Success",
"content": {
"text/plain": {
"schema": {
"type": "object",
"properties": {
"A": {
"type": "string"
},
"B": {
"type": "number"
},
"C": {
"type": "boolean"
}
}
}
}
}
},
"default": {
"description": "Failure",
"content": {
"text/plain": {
"schema": {
"type": "integer"
}
}
}
}
}
}
}
}
} |
Another approach might be to register a new media type: |
It's unlikely we'll get into the business of describing how to serialize non-standard structures. If you want to use a structured request/response - use JSON. If you want to use a different serialized form - you can use an extension to reference it (for example, use XSD). If you're just using plain text - then that's what it is, plain text, not structured data. For what it's worth, we did have a proposal in the past to add support for additional (standard) serialization methods, but we didn't get enough traction to actually have those end up in the spec. That would have not really helped your use case because it seems what you're trying to do is non-standard. |
I wouldn't say the situation described this issue is non-standard, although it is probably atypical. This issue didn't arrive out of an actual API use case. I came to it while building testing tools that use an OpenAPI definition to decode and validate API response data. If we assume that |
I didn't say the situation is non-standard, said you're using a non-standard method of describing serialization. JSON can also be sent using |
That would be my interpretation. text/plain content only produces strings, so the only valid type that you can expect to get when evaluating the schema is "string". Maybe you could argue that if the schema says |
I've added some basic guidance in PR #3840, which mostly just confirms that you're on your own, but that's as far as I think we can go. |
For a response body with Content-Type=text/plain, "style" and "explode" ought to apply. Different API implementations might need to make different choices for how these data values are serialized. But there is no mention of this in the spec.
Shouldn't the spec prescribe optional "style" and "explode" fields for a Media Type Object (similar to those in an Encoding Object)? If not, shouldn't the spec explain the default values that should be assumed?
The text was updated successfully, but these errors were encountered: