Har*_*ary 7 swagger-2.0 swagger-editor
我正在尝试创建 swagger json 并尝试在http://editor.swagger.io 中检查它的有效性
验证json后,上面提到的编辑器给出了以下错误:
Schema error should NOT have additional properties
additionalProperty: components
Jump to line 0
Run Code Online (Sandbox Code Playgroud)
如果由于某种原因我无法在根级别定义一个名为 components 的元素,我将在其中拥有某种 json 模式,那么按照我的意图对 requestBody 的模式执行 $ref 的正确方法是什么如下例所示。另外,你看到我的 swagger json 有什么问题吗?
我的 swagger2.0 的 swagger json 看起来像这样。
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "My swagger API",
"contact": {
"name": "myName",
"email": "abc@gmail.com"
}
},
"host": "localhost:1234",
"basePath": "/",
"tags": [{
"name": "someTagName",
"description": "this is a try"
}],
"components":{"schemas": {"myEndPoint": ""}},
"paths": {
"/myEndPoint": {
"post": {
"tags": ["some-tag"],
"summary": "myEndPoint endpoint will give you something",
"description": "some description will go here",
"operationId": "getMyEndPoint",
"consumes": ["application/json"],
"produces": ["application/json"],
"parameters": [{
"in": "body",
"name": "somePayload",
"description": "somePayload is what this is",
"required": true,
"schema": {
"$ref": "#components/schemas/myEndPoint"
}
},
{
"in": "header",
"name": "Authorization",
"description": "auth token goes here",
"required": true,
"type": "string"
}],
"responses": {
"200": {
"description": "Success",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
Hel*_*len 14
您正在混淆 OpenAPI 3.0 和 2.0 语法。该components关键字用于 OpenAPI 3.0。在 OpenAPI/Swagger 2.0 中,可重用模式位于definitions:
"definitions": {
"myEndPoint": {
...
}
}
Run Code Online (Sandbox Code Playgroud)
确保也将更$ref改为
"$ref": "#/definitions/myEndPoint"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10997 次 |
| 最近记录: |