swagger-api / swagger-node

Swagger module for node.js
http://swagger.io
Apache License 2.0
3.97k stars 585 forks source link

Swagger with custom configuration not loading params #332

Closed nazarhussain closed 8 years ago

nazarhussain commented 8 years ago

Hello,

I had been using swagger with custom configuration and directory structure in node application.

Here is snippet of my app.js

var swaggerConfig = {
  appRoot: config.get('app_root'),
  configDir: 'swagger/config',
  swaggerFile: 'swagger/api.yaml'
};

SwaggerExpress.create(swaggerConfig, function(err, swaggerExpress) {
  if (err) { throw err; }
  swaggerExpress.register(app);
});

Under config swagger/config directory having standard yaml configuration default.yml.

# swagger configuration file

# values in the swagger hash are system configuration for swagger-node
swagger:

  fittingsDirs: [ app/fittings ]
  defaultPipe: null
  swaggerControllerPipe: swagger_controllers  # defines the standard processing pipe for controllers

  # values defined in the bagpipes key are the bagpipes pipes and fittings definitions
  # (see https://github.com/apigee-127/bagpipes)
  bagpipes:

    _router:
      name: swagger_router
      mockMode: false
      mockControllersDirs: [ app/mocks ]
      controllersDirs: [ app/controllers ]

    _swagger_validate:
      name: swagger_validator
      validateResponse: true

    # pipe for all swagger-node controllers
    swagger_controllers:
      - onError: json_error_handler
      - cors
      - swagger_security
      - _swagger_validate
      - express_compatibility
      - _router

    # pipe to serve swagger (endpoint is in swagger.yaml)
    swagger_raw:
      name: swagger_raw

# any other values in this file are just loaded into the config for application access...

Now having issue that on controller req.swagger.params always return null.

Can anyone help me out in figuring out this issue..

nazarhussain commented 8 years ago

Solved the issue by adding swagger_params_parser layer in swagger_controllers under config. This was not mentioned in any guide/wiki. Please update wiki for it.

More details are on: http://stackoverflow.com/questions/34306720/swagger-with-custom-configuration-not-loading-params/34306770#34306770