我正在 IntelliJ 中編輯 OpenAPI JSON 規范。自動驗證和代碼完成作業非常好。
使用的 OpenAPI 版本是 IntelliJ 正確檢測到的 3.0.3。似乎它在內部使用“openapi30.json”進行驗證,一切都很好。
但是,檔案變得非常大,是時候使用$ref.
這就是事情破裂的地方。主要規格如下所示(片段):
{
"openapi": "3.0.3",
"info": {
"title": "Cars REST API",
"description": "Calls, Responses and DTOs for REST",
"version": "1.0.0"
},
"components": {
"schemas": {
"car": {
"$ref": "car.json"
},
"car-group": {
"$ref": "car-group.json"
}
并且在編輯它時,IntelliJ 將其識別為“openapi30”。
但是,無法識別參考的檔案。例如,該car.json檔案如下所示:
{
"car": {
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
}
}
它被簡單地識別為 JSON 檔案,而不是 OpenAPI 檔案,因此沒有適當的驗證和代碼完成等。
How does one tell IntelliJ that the file is part of an OpenAPI specification, to be validated as such? One should think this could be inferred from begin $ref'ed from the main spec, but this doesn't work.
Trying to add a $schema value in the referenced file had no effect (and probably isn't in line with the OpenAPI spec anyway).
Manually selecting the OpenAPI 3.0 file type for car.json is not helpful, because then validation (rightly) fails - as it doesn't have the top-level structure required (info, openapi, paths).
Perhaps some specific JSON schema mapping needs to be added in IntelliJ preferences? If that's the case, it would be actually a sub-schema or some tag in the main OpenAPI spec, how can that be done?
IntelliJ版本為:IntelliJ IDEA 2021.3.2(終極版)
任何幫助將不勝感激。
uj5u.com熱心網友回復:
羅恩!
尚不支持此類功能。請投票給https://youtrack.jetbrains.com/issue/IDEA-284305
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427783.html
標籤:json 智能理念 开放API jsonschema
上一篇:java找不到符號類生成
