-
Notifications
You must be signed in to change notification settings - Fork 9.1k
x-examples for post examples #1980
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
In specification I found following about vendor extensions:
Unfortunately this doesn't look clear. @fehguy @webron could you please give me more background on vendor extensions? Thank you in advance! |
Almost all objects in the spec allow you to define vendor extensions to them, including parameters - https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#patterned-fields-2. The value of the vendor extensions is undefined and can be any valid JSON - based on the user preferences. A few months ago @fehguy added support for Keep in mind that |
The following generic spec correctly pre-populates my POST body examples, but doesn't actually pre-populate the textbox for submission under the latest swagger UI. It took me some time to figure this out, but it works. I haven't yet tried
I felt the need to share this here because the issue description seems to imply that there is no such feature in the latest Swagger UI. Well, it works for me :-) It would be better if the user didn't have to click the Example Value in order to populate the textbox, but maybe this illustrates that the required fix may not be as much work as it seems. |
@mkrufky - fwiw, that's not a valid array definition. definitions:
postBodyObj:
type: object
default:
postBodyObj: [ 1,2,3 ]
properties:
postBodyObj:
type: array
items:
type: number |
Apparently it's very forgiving :-) The validator does complain about it, but the functionality seems to work regardless:
Despite failing the validator, the functionality seems to work. I have a different POST endpoint using this instead for a default example block:
The functionality seems to work properly even though the validator complains with a similar error as the other endpoint:
After fixing the array in my original snippet, the validator gives the same error as above ^ while all seems to be functioning properly. I'd hate to deter too much from the topic of this issue, but again, I only bring it up because it seems to work regardless of what the validator says. |
This doesn't seem to be implemented as of v 2.1.5, using x-examples is parsed as a vendor extension but it has no effect on swagger-ui, I can't see any of my x-example values. Check this sample definition:
|
I also tried to add request body example by using "x-examples", it didn't show up in UI, either. I just wonder how to add request body example. Anyone can help with this? |
I would like to document the rate limits for each operation.
It would be nice if Swagger UI can show this info in a friendly format. |
We're seeing that Swagger-UI does show the value of But it doesn't show the value of
Was |
I think it only works for media-type |
@webron , yes, you're right. It works with
Thanks for that tip. Other limitations:
|
@fehguy You mention "In the 1.2 swagger-spec, we had support for example post bodies", can you point me towards this? Unfortunately, I'm working on a NodeJS application that works with Swagger 1.2 and generates documentation from code. It is my understanding you're currently advocating the other way around. But that would probably take me too far, so I'm continueing with Swagger 1.2, and actually converting the resulting spec to Swagger 2.0 on the fly. But I would like to add example jsons to my requests and responses. You mention it is possible, but I can't seem to find any reference to it in the Swagger 1.2 specification. |
My solution and it worked fine for me:
|
In the 1.2 swagger-spec, we had support for example post bodies. This was controversially removed in 2.0 as we expected the model schema to be enough for examples. That proved to be a mistake as the values, even in the same schema, might need to vary between requests.
To work around in the mean time, and provide backwards support, we added an
x-examples
support in the post body:Note the
x-examples
may be a string or an object. The UI should determine if it can be parsed as an object based on the content-type in the key.During the transition to rendering on the UI side, this was lost.
@bodnia can you see about adding it back?
The text was updated successfully, but these errors were encountered: