-
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
Allow providing sample requests and responses #39
Comments
HI, I see this a very useful feature for our project documentation. Any idea when this can be included in the spec? |
We're working on this for the 2.0 spec right now. |
and thanks @vlcinsky for putting down all these thoughts. |
Awesome. thanks! Any idea when 2.0 spec will be out? |
july :) |
Hi, I wanted to ping and check on the status of 2.0 spec since we are getting near the end of july. Are you guys still planning on releasing this july? Appreciate your help. BTW we already started using the spec recently. You guys are doing great job with spec and it really helped us a lot on documenting our services. great work. Kudos!!! |
Hi, we're just about there--might be a week behind but it's worth the wait. |
Great thank you!!! |
This has been added to Swagger 2.0. |
I don't understand how to use this... I don't see any reference in the specification |
@vad - for responses, check out https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#responseExamples. For requests, watch out for a more elaborate explanation in the upcoming weeks. |
@fehguy is there any news regarding this issue it's seems to be closed but the functionality isn't available |
@foragerr it's not supported explicitly at the current version but is under discussion for the next version. We introduced a vendor extension in swagger-ui to support it, but it's not an official part of the spec. |
No, that's just derived from the 'example' in model definitions that exists today. For |
Just to get this right, describing request examples is not part of the 2.0 spec? |
@marians You can put an example on a schema that is used by a |
Sometime it is handy to have sample request or response example. Working with integration of larger project SUPERHUB, we go from API design over samples, validating them and finally implementing. Samples are key component in communication about API.
Option "tree": agreed tree structure with
basePathExamples
parameterAPI declaration would get new attribute "basePathExamples".
Default value for
basePathExamples
could be<basePath>/_examples
Real examples would be available at url build from
<basePathExamples>/<resourcePath>/<operationNickname>/request/<requestExampleName>
and similarly<basePathExamples>/<resourcePath>/<operationNickname>/response/<responseExampleName>
Option "index": Index of sample files within agreed tree structure
Option "tree" has a disadvantage, that collecting all sample file names/urls might not be always easy or even possible. To resolve that, we would put into path
<basePathExamples>/<resourcePath>/<operationNickname>
a file calledindex.json
. This would be an object with two propertiesrequests
andresponses
, each holding list of path names for sample request/responses. The path shall be relative to given directory withindex.json
file as it is easier to fill it in (e.g. usingfind
) and also easy to check by using an editor (usegf
invim
, standing for "go file" - you either succeed and see the sample file, or hit a problem, if the path is invalid). We could also completely relax from requirement to use namesrequest
orresponse
for directories and leave it up to the developer.Option "links": Explicit links from operation items to examples
We could reuse the concept of
basePathExamples
above plus allowing two new attributes within operation objects.exampleRequests
would be a list of urls, pointing to request examples.exampleResponses
would be a list of urls, pointing to response examples.However, as such an option seems too intrusive to me, I will not detail on it.
How to start
Starting with agreed tree structure shall be rather easy, as in the simplest situation (using agreed default value for
basePathExamples
), there is no need to modify any of existing structures.Allowing non-default values for
basePathExamples
sounds practical to me and relatively easy.If we feel a need to extend it, I would prefer the "index" solution as it is much less intrusive comparing "links" option.
How to follow up
(this is out of scope of this ticket)
Swagger UI showing sample files
Swagger UI shall be able to show sample requests and responses.
Test suite for evaluating sample files
Having all the information proposed at hand, we shall be able writing a test suite, which would detect following problems:
The text was updated successfully, but these errors were encountered: