Swagger 自定义配置不加载参数
Swagger with custom configuration not loading params
我一直在节点应用程序中使用带有自定义配置和目录结构的 Swagger。
这是我的 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);
});
在具有标准 YAML 配置 default.yml
的配置 swagger/config
目录下。
# 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...
现在控制器 req.swagger.params
总是 return null
出现问题。
文档中并不清楚这一点,但您还需要将 swagger_params_parser
添加到 default.yaml
中的 swagger_controllers
部分。
bagpipes:
_router:
name: swagger_router
mockMode: false
mockControllersDirs: [ api/mocks ]
controllersDirs: [ api/controllers ]
_swagger_validate:
name: swagger_validator
validateResponse: true
# pipe for all swagger-node controllers
swagger_controllers:
- swagger_params_parser
- cors
- swagger_security
- _swagger_validate
- _router
我一直在节点应用程序中使用带有自定义配置和目录结构的 Swagger。
这是我的 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);
});
在具有标准 YAML 配置 default.yml
的配置 swagger/config
目录下。
# 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...
现在控制器 req.swagger.params
总是 return null
出现问题。
文档中并不清楚这一点,但您还需要将 swagger_params_parser
添加到 default.yaml
中的 swagger_controllers
部分。
bagpipes:
_router:
name: swagger_router
mockMode: false
mockControllersDirs: [ api/mocks ]
controllersDirs: [ api/controllers ]
_swagger_validate:
name: swagger_validator
validateResponse: true
# pipe for all swagger-node controllers
swagger_controllers:
- swagger_params_parser
- cors
- swagger_security
- _swagger_validate
- _router