我正在使用swagger与节点,我需要在节点启动时动态设置控制器的路径。例如,路径可以是/api/controllers/foo/
或/api/controllers/bar/
。
swagger-node documentation描述了swagger配置对象。我可以定义要搜索控制器的目录或用于解析控制器的路由器,但是覆盖现有的/ default swagger-tools router似乎有点过分,并且设置控制器目录不起作用,因为我需要该目录foo
或bar
,而不是两者。
# swagger configuration file
# values in the swagger hash are system configuration for swagger-node
swagger:
fittingsDirs: [ api/fittings, node_modules ]
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: [ api/mocks ]
controllersDirs: [ api/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...
我无法找到任何明确简洁的方法来做到这一点。好像我错过了什么。有没有人有动态动态设置控制器目录的经验?这里最好的方法是什么?