apigee-127 / swagger-node-runner

The heart of Swagger-Node
MIT License
102 stars 123 forks source link

Is there a way to validate requests / responses without using Swagger Router fitting? #114

Open dayuloli opened 6 years ago

dayuloli commented 6 years ago

Background

I have an existing Restify server and I want to retrofit Swagger into the application in order to validate the requests and responses.

Problem

When I use swagger project create command to create a new Restify server wrapped with swagger-restify-mw, it uses the Swagger Router fitting to route the request to the corresponding controller function, as specified through the x-swagger-router-controller and operationId properties.

However, the application I am working on is large and I don't want to change how we structure our application and convert all endpoints to controller functions.

I.e. I want to keep defining how requests are handled normally:

httpServer.get({
  path: 'ping',
  version: "1.0.0"
}, (req, res, next) => {
  res.send(200, 'pong');
  next();
});

My Attempt

Since requests are passed through the swagger_controllers pipe, I tried to take out the swagger_router pipe from the default.yaml file. The API endpoints responds properly as before, but it is no longer carrying any form of validation.

My default.yaml file is as follows:

swagger:
  fittingsDirs: []
  defaultPipe: null
  swaggerControllerPipe: swagger_controllers
  bagpipes:
    _swagger_validate:
      name: swagger_validator
      validateResponse: true
    swagger_controllers:
      - onError: json_error_handler
      - swagger_params_parser
      - cors
      - swagger_security
      - _swagger_validate
      - express_compatibility
    swagger_raw:
      name: swagger_raw

I've been scratching my head for a few days now, looking into the source code of swagger-node-runner, and sway, any pointers in the right direction would be appreciated. 🙇

dayuloli commented 6 years ago

Bump. Any news / advice / update / tip on this? Thanks!

dayuloli commented 6 years ago

Hi, this is still a relevant issue for me, I'd be extremely grateful for any advice / update / tip on this. Thanks!