node.js - 如何在nodejs应用程序的swagger-ui中指定多个基本路径
问题描述
我有一个在端口 8080 上运行的 Node.js 服务器。我正在使用 swagger,它允许设置基本路径。我想为不同的端点设置多个基本路径。我正在使用swagger-ui-express
服务器招摇 ui 文件。
我浏览了 swagger 的文档并尝试使用服务器属性,但它没有用。我的端点是:
- 端点:
/users/movies
应作为:http://localhost:9090/cinema-mgr-api/users/movies
- 端点:
/aws-mgr-api/storage
应作为:http://localhost:9090/aws-mgr-api/storage
如何定义多个基本路径swagger-ui-express
?
解决方案
下面的代码是我的项目。我已经使用了swagger-tools
依赖项,版本是0.10.4
.
招摇.json
{
"swagger": "2.0",
"info": {
"title": "Node JS APP",
"description": "Node JS APP",
"version": "1.0.0"
},
"produces": [
"application/json"
],
"host": "localhost:9000",
"basePath": "/api",
"paths": {
"/cinema-mgr-api/users/movies":{
"post": {
"tags": ["controller"],
"description": "movies",
"x-swagger-router-controller": "controller",
"operationId": "movies",
"parameters": [
{
"name": "body",
"in": "body",
"description": "movies",
"required": true,
"schema": {
"$ref": "#/definitions/movies"
}
}
],
"responses": {
"200": {
"description": "search successful"
}
}
}
},
"/aws-mgr-api/storage": {
"post": {
"tags": ["aws-controller"],
"description": "storage",
"x-swagger-router-controller": "aws-controller",
"operationId": "storage",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/storage"
}
}
],
"responses": {
"200": {
"description": "stored Successfully"
}
}
}
}
},
"definitions": {
"movies": {
"type": "object",
"required": [
"movieName"
],
"properties": {
"movieId": {
"type": "string"
},
"movieName": {
"type": "string"
},
"filters": {
"type": "object",
"properties": {
"period": {
"type": "string"
},
"year": {
"type": "array"
},
"language": {
"type": "array"
}
}
}
}
},
"storage": {
"type":"object"
}
}
}
推荐阅读
- pdf - Ghostscript:保留注释(保持打印/非打印区分)?
- go - 了解 golang 通道:死锁
- javascript - 迭代一个 JSON 对象并将其追加到 DIV
- kotlin - Kotlin 反应式通道:嵌套发布者在父级完成后不会启动?
- php - SQL QUERY如何通过其他约束选择列
- c# - 如何总结从sql中的数据到gridview的总时间
- javascript - SignUp Button HTML CSS JavaScript
- php - 使用雄辩的关系
- javascript - Why `HTMLelement.innerText` adds newline (\n)?
- c++ - 模板类中的静态模板变量