慕田峪4524236
2024-01-05 16:16:27
我在使用 open api v3 $ref 調(diào)用 URL 時遇到問題我編寫了一個開放 API v3 規(guī)范來提供 REST 應(yīng)用程序的文檔。我使用 $ref 來驗證本文檔的輸入?yún)?shù)。這些 $refs 指向 url 中的 json 模式。這是 apen api 文檔的示例:(文檔.yml) /myapi: get: description: Some Description parameters: - name: profile in: query description: Some description required: false schema: $ref: 'http://localhost:8089/refs#/properties/profile'端點http://localhost:8089/refs#/properties/profile正在返回 "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "title": "Some Example", "definitions": {}, "properties": { "profile": { "default": "", "examples": [ "1.0.0" ], "pattern": "^(\\d+\\.\\d+\\.\\d+)$", "type": "string", "title": "This is a version", "$id": "#/properties/profile" } }, "$id": "myid1" }我將 doc.yml 復(fù)制并粘貼到 swagger 中,輸入經(jīng)過驗證,一切都很完美。由于端點的更改(http://localhost:8089/refs)我收到這樣的回復(fù): "oneOf": [ { "$ref": "id1" } ], "$schema": "http://json-schema.org/draft-07/schema#", "description": "Some Description", "type": "object", "$id": "someid", "definitions": { "id1": { "description": "Some description", "additionalProperties": false, "type": "object", "title": "Some Example", "properties": { "profile": { "default": "", "examples": [ "1.0.0" ], "pattern": "^(\\d+\\.\\d+\\.\\d+)$", "type": "string", "title": "The Version Schema", "$id": "#/properties/profile" } }, "$id": "id1" } }}進行此更改后,Swagger 會拋出此錯誤。“無法解析指針#/properties/profile”我的問題是。當(dāng)架構(gòu)使用 oneOf 時,是否可以繼續(xù)使用 #/properties/profile 作為 id?如果 json 模式使用 oneOf,如何讓 open api 驗證輸入?我是否必須使用其他路徑而不是#/properties/profile?
1 回答

藍山帝景
TA貢獻1843條經(jīng)驗 獲得超7個贊
請記住,Open API 使用它自己的 JSON Schema 風(fēng)格。它遺漏了一些東西,添加了一些東西,并修改了一些東西。目前,Open API 不支持$id
/ id
(參考: https: //swagger.io/docs/specification/data-models/keywords/)。好消息是您沒有$id
以任何有意義的方式使用它,因此僅將其忽略并不會改變您的情況。
您的$ref: 'http://localhost:8089/refs#/properties/profile'
路徑不再有效,因為該路徑不再存在。文檔的結(jié)構(gòu)已更改,因此 JSON 指針片段必須使用新的結(jié)構(gòu)。它必須是$ref: 'http://localhost:8089/refs#/definitions/id1/properties/profile'
添加回答
舉報
0/150
提交
取消