swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Operation response is $ref

Open ruhley opened this issue 12 years ago • 10 comments

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 || [];

ruhley avatar Sep 29 '14 06:09 ruhley

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 avatar Oct 08 '14 17:10 gyllen

@gyllen - it's difficult to merge it in as it's not a PR ;) but I'm sure it'll be handled soon.

webron avatar Oct 08 '14 17:10 webron

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?

watnotte avatar Oct 08 '14 20:10 watnotte

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.

webron avatar Oct 08 '14 20:10 webron

I see. Makes sense. Thanks for the enlightenment.

watnotte avatar Oct 08 '14 20:10 watnotte

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 avatar Oct 08 '14 20:10 webron

@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 avatar Oct 08 '14 22:10 ruhley

@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.

webron avatar Oct 09 '14 08:10 webron

Any news on this issue?

gyllen avatar Oct 22 '14 17:10 gyllen

Hi, the models section will only hold model references. Each reference section in the spec has it's own type.

fehguy avatar Dec 30 '14 01:12 fehguy