Operation response is $ref
I have some responses defined in the base swagger json object.
"swagger": "2.0",
"basePath": "/docs"
"responses": {
"200": {
"description": "The call was successful",
"schema": {}
}
}
And I want to reference them in lots of operations as documented at https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#swaggerResponses
Here is my fix in swagger-client.js
At line 440 I added
for (response in responses) {
if (responses[response]['$ref']) {
responses[response] = parent.responses[responses[response]['$ref']];
}
}
And to be able to point to parent.responses I added at line 280
this.responses = response.responses || [];
The responses and parameters fields in the swagger object are really useful. But needs to be supported correctly in the viewer. Please merge this code to master.
@gyllen - it's difficult to merge it in as it's not a PR ;) but I'm sure it'll be handled soon.
I was having trouble with this and https://github.com/wordnik/swagger-ui/issues/621 yesterday so I'm glad it's already noted as an issue.
Not sure if there is any public transcripts of spec discussions but is there a rationale for not just including these references to parameters and responses in the definitions section and referencing them just like the other models in there?
Validation purposes really. The "definitions" property is used strictly for schema/model definitions. Parameters and responses have a different structure and we want to make sure you don't mix one with the other.
I see. Makes sense. Thanks for the enlightenment.
I admit that in a future version of the spec I'd rather change the name of "definitions" to "schemaDefinitions" alongside "parameterDefinitions" and "responseDefinitions" to have a sort of a standard, but time will tell if that'll happen.
@webron I didn't submit a PR becuase i wasn't sure this is how you wanted to solve it. There are probably better ways, but this was a quick fix I found. Would you like me to submit a PR for this and #621?
@ruhley - I apologize if it sounded like criticism, it really wasn't. I was just explaining that there's no 'merging' to be done here. I'm not familiar with swagger-ui's code enough to tell you whether that's a proper solution or not.
I suspect the solution to it would be derived from swagger-js though as it needs to support it as well.
Any news on this issue?
Hi, the models section will only hold model references. Each reference section in the spec has it's own type.