【发布时间】:2017-11-14 19:32:47
【问题描述】:
我正在尝试创建 swagger json 并尝试检查它的有效性 http://editor.swagger.io
在验证 json 时,上述编辑器给出以下错误:
Schema error should NOT have additional properties
additionalProperty: components
Jump to line 0
如果由于某种原因我无法在根级别定义一个名为 components 的元素,我将在其中拥有某种 json 架构,那么在 API 操作的 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"
}
}
}
}
}
}
【问题讨论】:
标签: swagger-2.0 swagger-editor