-
Notifications
You must be signed in to change notification settings - Fork 762
[develop_2.0] Response Example Not Displaying #300
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
Since this is a regression, I've added it to the M2 milestone. |
Oops! I meant to post this issue in the swagger-ui project. Does that project pull in this library? If not, I can re-post this issue in the correct project. 🙈 |
swagger-ui uses swagger-js to generate some of its UI. Weird, I know, but for the next release of swagger-js and swagger-ui, this will be the case. We'll be cleaning this up in a future release. |
This should be fixed if I understand it. Basically, swagger-ui uses swagger-js's |
Wow, ultra-quick turnaround! Thanks @whitlockjc, awesome job! |
@whitlockjc OK, so, I just got around to retrying this functionality, and I am still seeing no examples get spit out. I literally just built swagger-js and swagger-ui for an edge release (as described here). My JSON still looks similar to the above, but there is nothing rendered where the Model/Model Schema normally would be. Did it regress again? Are there tests written around this feature? EDIT: Just checked the merged PR and it looks like there are indeed tests around this. So now I'm just vexed that it isn't rendering, lol. |
I also checked with a JSON string, e.g.
...to no avail. =[ |
I've no idea. I know that swagger-ui has been under constant development so it wouldn't surprise me if there was some regression. Let me go look around and see if swagger-ui is indeed still using this. |
It seems that your response definition is wrong. You provide an example but do not provide an actual schema to describe your response. A schema-less response is considered to be a void response, which means no response. |
As for how swagger-ui is using swagger-js to render the operation view, check this out: |
@whitlockjc Ahhhhh ok! Yup, once I added a schema the example showed up as expected! I suppose the only action item that could come from this excursion is to add some documentation to the swagger-spec showing how to add an example and clearly stating that a schema is required if examples are to be used. =] Thanks for the clarification! |
Well, what good is an example for a void response? So it's less that you need a schema for the response example to be displayed and more that you've provided a superfluous example for a void response when you don't have a schema. Make sense? |
@Smolations - The specification will not specify it because it's not a constraint. Choosing to display or not is a tooling decision. Logically, it doesn't make sense to display an example for something that doesn't exist. |
My original interpretation was that i could provide Anyway, time has been taken in the spec to point out which properties on objects are required, either always or conditionally based on values of other properties. Given the spec for a Response Object, only a description is required which implies that any combination of the other properties could be provided and the UI should render correctly. I totally get what you are saying, and I pretty much agree with you, but if I experienced confusion when I felt like I was following the spec, then surely someone else will too. Or perhaps I'm an anomaly. 👼 lol |
A void response is a response that returns nothing, be it a JSON payload, a number, yaml, html, xml or anything else. This would normally be alongside a 204 HTTP status code, for example. Please take a moment to read the description of the |
@webron Thanks for the clarification. And to answer the question posed by @whitlockjc, I agree that it doesn't make sense for an example to accompany a void response. I suppose it amounts to common [technological] sense, I just was paying more attention to the Required text in descriptions, as well as any info in those descriptions around conditional requirements. As we've been having this conversation, I believe I have uncovered a bug around this feature (or perhaps with the newly-implemented "allOf" support in schemas): #459 |
This was working on
master
, but I have since switched to thedevelop_2.0
branch for features/fixes and it appears to be broken now. I verified that my JSON schema is valid, and that my produces/consumes (at the swagger object level) only include the'application/json'
mime type:Only the response code and description show up in the UI, but no example. I thought that maybe the response rows were clickable/expandable (which would be a feature request for me because, say, 4 responses with examples showing the entire "Model | Model Schema" view would take up a lot of vertical space), but no dice.
The text was updated successfully, but these errors were encountered: