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

Restify req.params is empty

Open fyodorvi opened this issue 8 years ago • 8 comments

Swagger.yaml

  /basket/products/{productId}:
    x-swagger-router-controller: basket-controller
    delete:
      description: Removes product from a basket
      operationId: removeProduct
      parameters:
        - name: productId
          description: Product Id
          in: path
          type: string
          required: true
      responses:
        "200":
          description: Success

Controller:

    function removeProduct(req, res, next) {
        console.log(req.params); // outputs {}
    }

Expected to req.params to be { productId: <product id> }.

Am I not using it right? Using Restify.

fyodorvi avatar Jun 13 '16 06:06 fyodorvi

First, put your x-swagger-router-controller under the http operation (delete).

Next, you should have res.params['productId'].value as the value being passed in.

fehguy avatar Jun 14 '16 17:06 fehguy

First, put your x-swagger-router-controller under the http operation (delete).

Doc says to put it there. Right in main README.md on front page of this repo.

Next, you should have res.params['productId'].value as the value being passed in.

res is a response object, it doesn't have params property on it. Request object has params property, but it's empty.

Do you want full code sample to try it?

fyodorvi avatar Jun 15 '16 00:06 fyodorvi

Any updates on this? It is a terrible bug.

fyodorvi avatar Jul 11 '16 20:07 fyodorvi

Okay, so it tuns out that these params are sitting in req.swagger.params.<param>.value. Why not assign them to req.params? Query params are there.

fyodorvi avatar Jul 13 '16 01:07 fyodorvi

Please report this with bigger priority!

sky-philipalmeida avatar Mar 21 '17 20:03 sky-philipalmeida

I as well have hit this issue. I was able to use fyodorvi's work around for the moment.

sorvis avatar Aug 14 '17 16:08 sorvis

Also use fyodorvi's workaround as a temporary solution. Any progress on fixing this bug?

DmytroMysak avatar Feb 05 '18 10:02 DmytroMysak

Also use @fyodorvi 's workaround as a temporary solution. Any progress on fixing this bug?

Beleren avatar Mar 22 '22 16:03 Beleren