-
Notifications
You must be signed in to change notification settings - Fork 9.1k
v3.2: Allow Media Type Object re-use #4728
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
base: v3.2-dev
Are you sure you want to change the base?
Conversation
b925823
to
5055496
Compare
Accidentally pushed an intermediate commit, had to force-push to fix. This should be correct now- also fixed the title as this is proposed for 3.2 based on trying to use new 3.2 features in non-trivial ways. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, minor nits
Hmm... I have run into a problem with Examples of individual form fields include the name (e.g. The Header Object would have the same problem, except header examples do not include the header name (see PR #4800 for why). So it's fine to But at the moment, it feels like we can either Of course it is possible to just do an example of the whole query string or |
I'd be in favour of adding the extra components field for just media types if that's simpler? It seems like it would have the widest use case too (at least the way I write OpenAPI!) |
@lornajane given the potential confusion with Encoding Objects I'm leaning that way. I will update this PR. There are also always Overlays if people really want to re-use Encoding Objects and can manage the name-vs-example thing in their own way. |
Add the Media Type Object to the Components Object, and allow a Reference Object anywhere it is allowed. To ensure that re-usable Objects can be documented clearly, add a `description` field.
5055496
to
747ccc8
Compare
With apologies for the rebase, it was easier to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, minor nit
Co-authored-by: Ralf Handl <ralf.handl@sap.com>
[NOTE: See this later comment for a why this PR has been changed to only support
$ref
-ing Media Type Objects, and not Encoding Objects.]Add the Media Type Object
and Encoding Objectto the Components Object, and allow a Reference Object anywhere they are allowed. To ensure that re-usable Objects can be documented clearly, add adescription
fieldto both Objects. [Note: If addingdescription
is more controversial than just supporting re-use, I could be persuaded to drop it.]One important thing to do as a release approaches is to try to use the new features more. As I have done this, I've realized that our increased usage and functionality of Media Type and Encoding Objects (which now handle streaming JSON, and are expected to handle a wider variety of multipart media types and be more useful with XML) make re-use of those objects a much more compelling prospect. While your average
application/json
Media Type Object is trivial, once you start using more complex media types, the duplication becomes substantial.Explanation and Examples
One use case might come from @jeremyfiel who, IIRC, works with an API where
multipart/mixed
usage that combines JSON metadata with binary data is common. Depending on how complex and common that format is, the media type object might be worth re-using in many places. We're expanding the support formultipart
a lot, and in generalmultipart
Media Type Objects are quite complex, with many Encoding Objects (which may have substantial commonality themselves if similar parts are used in differentmultipart
configurations) plus Example Objects.But to bring things back to a concrete example, here is a pattern that was at one time fairly common- allowing querying either through the URL query string, or through putting the query contents in the body of a POST in case the URL got too long (although here I am showing QUERY instead of POST).
Assume both of the examples to follow start with these components (I pulled them out to make the length comparisons more obvious):
Here it is with re-use, at 50 additional lines:
Without re-use, it takes 66 additional lines.
However, there is another wrinkle if we wanted to put in some descriptive text, which we'll look at afterwards[without Encoding Object re-use included, the descriptive text issue is no longer relevant]: