我想更轻松地将我的路径(相当多)分割成它们自己的文件。
假设我有两条主要路径/user
and /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": {...}
}
}
路径/anotherPath-path.json
{
"/anotherPath": {
"get": {...}
},
"/anotherPath/{id}": {
"get": {...}
}
}
这样,每当我添加另一条路径时/user
or /anotherPath
,我可以简单地编辑它们各自的路径文件,例如路径/用户路径.json。
EDIT1:显然,这个话题已经在讨论了..对于任何感兴趣的人:https://github.com/OAI/OpenAPI-Specification/issues/417。顺便说一下,我知道一个$ref
无效于paths
对象,但一旦弄清楚如何正确拆分,这可能就不再需要了。