我在使用 open api v3 $ref 調用 URL 時遇到問題我編寫了一個開放 API v3 規范來提供 REST 應用程序的文檔。我使用 $ref 來驗證本文檔的輸入參數。這些 $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 復制并粘貼到 swagger 中,輸入經過驗證,一切都很完美。由于端點的更改(http://localhost:8089/refs)我收到這樣的回復: "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 會拋出此錯誤?!盁o法解析指針#/properties/profile”我的問題是。當架構使用 oneOf 時,是否可以繼續使用 #/properties/profile 作為 id?如果 json 模式使用 oneOf,如何讓 open api 驗證輸入?我是否必須使用其他路徑而不是#/properties/profile?
打開Api $ref以使用url
慕田峪4524236
2024-01-05 16:16:27