Req.params and req.swagger.params, need to duplicate code in controller?
Closed this issue · 4 comments
Hello,
i am trying to use swagger using swagger-tools in a little test project but i have some difficults to use it with express.
When i make a request with curl, in my controller i have to use req.params but when i use swagger, i have to use req.swagger.params.
Is there a way to uniform this like using only req.swagger.params for both or req.params?
If not, do i have to check myself if req.swagger exists ... and duplicate code ?
Sorry for bad english.
No. req.params
is populated by whatever web framework you're using. req.swagger.params
is populated by swagger-tools
and it contains a lot more detail and type-coerced values.
No.
req.params
is populated by whatever web framework you're using.req.swagger.params
is populated byswagger-tools
and it contains a lot more detail and type-coerced values.
Thank you for yout reply.
I'm agree with your response but my problem is:
req.swagger.params
only is filled when executing the request from swagger-uireq.params
only is filled when executing the request from CURL
In other posts of swagger-express-mv i saw whe have to add :
- swagger_params_parser
in a yaml config file to get req.swagger.params filled when calling with CURL or Swagger-ui
Is there a way to use swagger_params_parser with swagger-tools ?
Is there a way to use a config file like in swagger-express-mv SwaggerExpress.create(config, function(err, swaggerExpress) {...
?
Is there another thing to do to get req.swagger.params
filled with both Curl call or Swagger-ui?
swagger-ui
has nothing to do with swagger-tools
. If req.swagger
is not populated, the swagger-metadata
middleware did not match the request to a Swagger operation. It might make sense to turn on debugging to see the request come in, and the swagger-tools
debugging output to verify. (My hunch is if swagger-ui
works but direct API calls don't, it's a basePath
issue.)
You are all right. That was a basePath issue. Thank you so much.