Operation parameter is $ref
Closed this issue · 10 comments
I have some parameters defined in the base swagger json object.
"swagger": "2.0",
"basePath": "/docs"
"parameters": {
"id": {
"name": "id",
"in": "path",
"description": "Id of the item to get",
"type": "number",
"required": true,
}
}
And I want to reference it in lots of operations as documented at https://github.com/wordnik/swagger-spec/blob/master/versions/2.0.md#operationObject
Here is my fix in swagger-client.js
At line 428 I added
if (param['$ref']) {
param = parent.parameters[param['$ref']];
this.parameters[i] = param;
}
And to be able to point to parent.parameters I added at line 280
this.parameters = response.parameters || [];
+1 on this one
I'm not sure why this is tagged as a feature and not as a bug. The spec says for a Operation Object
parameters :
[Parameter Object | Reference Object]
The list can use the Reference Object to link to parameters that are defined at the Swagger Object's parameters.
See also the related closed issues, swagger-api/swagger-editor#182
and apigee-127/swagger-tools#79 which claimed to fix $ref for parameters long ago.
Because support for 2.0 is not yet officially released, and that's one of the features that need to be supported.
+1
+1 really need this. since i have lots of common parameters, i use $ref frequently in operation object.
we're getting there, please keep tracking this issue for the fix, which will be in swagger-ui-2.1.0-M2
For anyone that's still affected by this, I've made a simple tool that will work around this until it's resolved: https://github.com/duncanhall/expand-swagger-refs/
It takes a swagger schema as an input and outputs the same schema with $ref values manually expanded.
👍
@duncanhall Thanks for the expand script. Gets me by just fine until it is added to master.