Open sauravpandit opened 6 years ago
Your Swagger path declaration should be along the lines:
"/dog/{id}": {
"x-swagger-router-controller": "dogs",
"x-swagger-router-handle-subpaths": true,
"get":{
"tags": [ "Dog Operations" ],
"operationId": "getAllDogs",
"parameters":[
{
"name": "id",
"in": "path",
"description": "The identifier of the dog",
"type": "number"
},
{
"name": "status",
"in": "query",
"description": "The status to filter by",
"type": "string"
}
],
"summary": "Finds all dogs in the system",
"responses": {
"200": {
"description": "Dog response",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dogprop"
}
}
},
"default": {
"description": "Unexpected error",
"schema": {
"$ref": "#/definitions/Error"
}
}
}
}
}
Access this in your controller as req.swagger.params.id.value
I have seen x-swagger-router-handle-subpaths option in router middleware. It is acting like a wildcard after url. In my swagger json I have defined a path "/dog". If I use url http://localhost:3000/api/dog/3/ it is hitting the proper controller but problem is I am not able fetch argument/parameter from path. req.swagger.params is not giving me the full path. Is there any way I can get the full path or I can fetch the parameter. It will be great if you provide some example of how to use this x option.