小编pro*_*hit的帖子

版本 ^1.68.0 中 VS Code 扩展警告中的元架构功能

所以基本上我有一个 VS Code 扩展,它提供基于内置 JSON 验证器的JSON 文件验证。我正在验证的模式(OpenAPI 3.1.x)使用​​元模式功能,即$dynamicRef,我也需要使用它,因为我引用了 OpenAPI 模式。

当定义如下所示的自定义架构时,我收到一条警告,指出验证器尚不支持元架构功能。不用说,验证确实不起作用。当使用正常时$ref,大多数架构都可以工作,但使用的属性却不起作用$dynamicRef$dynamicRef所以我也被迫引用架构。

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "OpenApiPathObject",
  "type": "object",
  "additionalProperties": {
    "$dynamicRef": "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json#/$defs/path-item-or-reference"
  }
}
Run Code Online (Sandbox Code Playgroud)
The schema uses meta-schema features ($dynamicRef) that are not yet supported by the validator.
Run Code Online (Sandbox Code Playgroud)

我使用的是 VS Code 1.69.0,并将扩展所需的引擎更改为 ^1.68.0,其中应包括对架构版本的支持,如2022 年 5 月发行说明Draft 2020-12中所述。我有什么选择以及如何解决此警告?

这是扩展的摘录package.json

The schema uses meta-schema features ($dynamicRef) that are not yet supported by the validator.
Run Code Online (Sandbox Code Playgroud)

json visual-studio-code openapi

13
推荐指数
0
解决办法
3329
查看次数

将 OpenApi 路径拆分为多个路径定义文件

我想更轻松地将我的路径(相当多)分割成它们自己的文件。

假设我有两条主路径/user/anotherPath几条子路径。现在我有了一个 OpenApi 规范文件,其路径被引用到一个索引文件,该索引文件保存对每个路径的引用。用其参考定义每条路径是可行的,但写起来很笨拙。

我想要这样的东西:

openapi.json

{
...
  "paths": {
    "$ref": "paths/index.json"
  }
...
}

Run Code Online (Sandbox Code Playgroud)

路径/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"
  }
}

Run Code Online (Sandbox Code Playgroud)

路径/用户路径.json

{
  "/user": {
    "get": {...}
  },
  "/user/{userId}": {
    "get": {...}
  }
}
Run Code Online (Sandbox Code Playgroud)

路径/anotherPath-path.json

{
  "/anotherPath": {
    "get": {...}
  },
  "/anotherPath/{id}": {
    "get": {...}
  }
}
Run Code Online (Sandbox Code Playgroud)

这样,每当我向/user或添加另一个路径时/anotherPath …

json swagger-2.0 openapi

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

json ×2

openapi ×2

swagger-2.0 ×1

visual-studio-code ×1