apigee-127 / swagger-tools

A Node.js and browser module that provides tooling around Swagger.
MIT License
701 stars 373 forks source link

Req.params and req.swagger.params, need to duplicate code in controller? #588

Closed pascal-mormin closed 5 years ago

pascal-mormin commented 5 years ago

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.

whitlockjc commented 5 years ago

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.

pascal-mormin commented 5 years ago

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.

Thank you for yout reply.

I'm agree with your response but my problem is:

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?

whitlockjc commented 5 years ago

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

pascal-mormin commented 5 years ago

You are all right. That was a basePath issue. Thank you so much.