Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dayuloli opened this issue Nov 14, 2017 · 2 comments

Comments

@dayuloli
Copy link

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
Copy link
Author

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

@dayuloli
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant