-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Allow multiple examples with optional label #488
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
Comments
+1 I also have an endpoint that can be used in different ways. The |
+1 having a description in addition to the name would be great too examples:
- name: An first example
description: use case
content:
- application/json : <example for media type application/json>
- application/xml: <example for media type application/xml> That could be useful for documentation but I think also for mock API generation |
Based on how Example Object are defined and used in version 3.0.0-rc0, I think that the it could be slightly modified to provide documentation data this way: Current Example Object is a freeform object, array or primitive value. Modified Example Object is an Object with these properties:
Having documented examples, or at least named examples is definitely a must have when documenting an API, especially if you provide various examples: how the readers would know what is the difference between these examples. @webron or @darrelmiller what do you think about this? |
1+, but rather than "just free form object", we should not imply that a JSON object is required; an Example could be a array or even a primitive value. (I htink Example Object is currently named incorrectly since it is not always an Object, but if we adopt your suggestion, the name would be correct.) I suggest |
I wonder if we can kill two birds with one stone here. There has been a question about the redundancy of having |
So we could have something like that:
I really like that! |
I'm wondering if the summary property shouldn't be required? |
summary is not required in other places, even where it is a "good idea". I don't think it should be required here. |
If we keep example, let's not call it Example Object, just Example or Example Value; and for the array use [ Example Object ]; |
Although I am a fan of this idea, be warned that getting any new features into the spec at this point does not have a high probability of success. |
I say we try to increase the probability of success 😁 |
Can we bribe some people? 😋 In current state the
And postponing this modification that billions of people will ask for will lead to a breaking change later 😁 |
an Examples Object should also allow |
Looks like everyone here thinks this is a good idea (though the only one from the @OAI/tdc who said something was @darrelmiller, so it might not be representative for the decision makers) ... who wants to write it up into a pull request? |
Just one other item that was just brought to my attention. With examples as an array and summary/description as optional fields it becomes possible to define multiple examples with no way of identifying or referencing one example vs another. That could make life difficult for tooling. We have a couple of options. We could introduce a |
I've just realized that the proposed structures (see my comment) is not really usable with ProposalSo, I propose this modification (including what @darrelmiller propose for identifying/naming examples):
What the proposal achieveWith this proposal:
Drawbacks:
|
@arno-di-loreto Having either a documented example object or a "simple example object" in the same place gives the problem that you can't decide which one you have – a simple example object, as a free form object, could look just the same as a documented example. (E.g. suppose you want to give an example for the documented example object.) |
I agree that having a I agree with @DavidBiesack that …and not least of the issues is @darrelmiller 's point that changes are trickier at this stage. |
Share an example yaml of your proposal @arno-di-loreto. My concern is that we're adding a zillion levels of objects here, and while some fields are nice to have, they will become a burden for 99% of the use cases. |
My suggestion would be that reusable examples in So, here's my suggestion. response:
200:
description: My cat
content:
application/json:
examples:
minimal:
summary: A minimal cat representation
value:
name: Fluffy
colour: Brown
complete:
ref$ : "#/components/examples/complete-cat-response"
application/xml:
example: "<cat @name='Fluffy' @colour='Brown'></cat>" |
For the cases where the example is at some external URL (like in the Request body examples in RC0) I would use a (This would be especially useful for media types which are not representable as a simple string, like an image.) So the documented example object would have these fields:
It is required to use one of (Edited to use |
@ePaul just colouring the bikeshed a little by saying that URL properties are called |
I'm a bit puzzled by how
'application/xml':
examples:
- "<Users><User name='Bob'/><User name='Diane'/><User name='Mary'/><User name='Bill'/></Users>"
- "<Users/>"
'application/xml':
examples:
- 'http://foo.bar/examples/user-example.xml' The Example Object description do not mention this. @ePaul I like the idea of adding a url to Documented Example Object (at first I thought this URL pointed to external documentation :-) ) and having the value as an Any object. But what about the example object? Do we keep it as it is? |
@MikeRalphson you are right, changed. |
@arno-di-loreto Yes, this is the reason I proposed the I would define the Examples object (in a media type object) as [ Documented Example Object | Reference Object ], with the reference referring to a Documented Example Object in components/examples. I think we should get rid of the Example Object ... it is not even always an object. We could let the singular example: X would be synonym to this: examples:
- value: X Having a reference here would be out, because it can't be distinguished from an example value which just happens to look like a reference – or which is an example for a reference object. |
@fehguy Here's an example of documented example and also the "linking examples thing" based on key https://gist.github.com/arno-di-loreto/a2cec5af36bd34e8921a7c88e2c95adb I think that a map would be better for linking examples together (or we'll need to add a property or use summary). But, I would understand that some people found this feature a little over-engineered :-) |
Well, that was a thrilling read. Interesting to see people are so engaged by something like The good news - unlike my colleagues, I'm not particularly opposed to making such changes at this stage, especially if they are meant to address a burning concern. The bad news - I'm not convinced this is the case. It's going to be difficult to address everything that was raised, so I might miss a few things:
Now for the big thing. This feature will make the specs bloated. It will make them a pain to navigate, a pain to read, and definitely a pain to write. It can easily double and triple the size of a simple spec. It's starting to feel that if this is such an important feature, it might be smarter to have a supporting document, simply linking However, as much as I don't think it's a good idea, I'm likely not to oppose to it if you can come with a relatively clean solution. Of course I'm just one voice in the team, but that's my take. The solution doesn't necessarily have to cover everything you want. Please avoid writing up the actual documentation of the changes, but really provide a set of examples that cover different use cases. This is how we dealt with a lot of the features that made it into the spec. I also ask that you avoid dealing with naming right now (it really isn't important if something is an Object or not, if you use |
@webron Thanks for your feedback.
With the new support of JSON schema's
I guess the point is that the fleshing-out of the features is not yet finished here. |
The fact that the OpenAPI spec uses multiple examples to describe many of the features suggests there is value to providing multiple examples. Not being able to explain to describe each of those examples is a significant shortcoming. One of the primary roles of OpenAPI is to drive documentation. Saying that API documentation can only include one example per request/response body is going to drive people some people to externalize documentation in an ad-hoc way, and cause others to produce less than ideal documentation due to these constraints. I don't think either outcome is in the best interest of OpenAPI. I'm not convinced that adding a identifier and a description to an example is over-engineering. |
Addressing @earth2marsh 's earlier comment: I agree with @ePaul; this is especially true for APIs which use just Good documentation (which includes good examples - emphasis on plural) is key to successful adoption of APIs. This does not mean the API is designed poorly, it just means it is documented well. Restricting metadata on examples will not lead to better API design. There are plenty of request or response bodies which have mutually-exclusive variation/representation -- most notably, when a I don't consider an object of four fields to be a "beast". The real issue is: if we do not do this now, we can never do this - we're shutting a door to future extension that I believe we will regret. |
Just to add to the confusion: Is this whole proposal we are working on about the example(s) in the media type object, the example(s) in the schema objects, or both? |
@ePaul Both. I'm going to try and write up a PR with the proposed changes and then we will beat it into something we can all live with. |
@ePaul : To be consistent, I think that this proposal MUST apply to all examples:
And we also must not forget to impact the @webron Thank you for your feedback.
@darrelmiller Do you need help or have you everything you need for the PR? PS: That proposal MAY be a way to solve #348 (documenting enums) |
Clarify that Examples Object may be used instead of Example Object. Show JSON examples as well as YAML Clarify the $ref values used in examples to remove ambiguity. These are not references to external JSON/XML/TXT resources, but rather are references to reusable examples in the current OpenAPI definition or in an external OpenAPI definition's components/examples This does not yet address issue OAI#488 but cleans up Examples Object a bit, which is needed whether we alter the OAS as per OAI#488 .
There was a PR merged for this in 2017 and no further comments. Closing. |
Hi, for some routes we need multiple examples for a "Response Object" as well as multiple body payload examples in the "Parameter Object".
e.g: our API route returns an object with optional properties and we want to show 2 examples how it could look like ...
In addition we would like to name/label these examples .
In the specification "Example Object"s you can specify different representations of an example for a given MIME-type. I would suggest adding either an optional "name" or "label" property to the "Example Object" which is a string (maybe even an object to allow localized string values for different languages) or to allow custom properties (e.g x-name).
e.g:
If there is any good way to solve it with the current swagger specification, i would love to hear it and it would make this feature request obsolete.
Thanks.
The text was updated successfully, but these errors were encountered: