【发布时间】:2020-08-04 01:02:27
【问题描述】:
我想更轻松地将我的路径(很多)拆分为它们自己的文件。
假设我有两条主要路径 /user 和 /anotherPath 以及几个子路径。现在我有一个 OpenApi 规范文件,它的路径被引用到一个索引文件,该文件包含对每个路径的引用。用它的参考定义每条路径,但写起来很笨拙。
我想要这样的东西:
openapi.json
{
...
"paths": {
"$ref": "paths/index.json"
}
...
}
路径/index.json
{
"/user": { // and everything that comes after user, e.g. /user/{userId}
"$ref": "./user-path.json"
},
"/anotherPath": { // and everything that comes after anotherPath, e.g. /anotherPath/{id}
"$ref": "./anotherPath-path.json"
}
}
路径/用户路径.json
{
"/user": {
"get": {...}
},
"/user/{userId}": {
"get": {...}
}
}
paths/anotherPath-path.json
{
"/anotherPath": {
"get": {...}
},
"/anotherPath/{id}": {
"get": {...}
}
}
这样,每当我向/user 或/anotherPath 添加另一个路径时,我都可以简单地编辑它们各自的路径文件,例如路径/用户路径.json。
EDIT1:显然,这个话题已经在讨论了。对于任何感兴趣的人:https://github.com/OAI/OpenAPI-Specification/issues/417。顺便说一句,我知道$ref 对paths 对象无效,但是一旦弄清楚如何正确拆分,这可能就不再需要了。
【问题讨论】:
标签: json swagger-2.0 openapi