我正在尝试创建 swagger json 并尝试检查它的有效性http://editor.swagger.io
验证 json 后,上述编辑器给出以下错误:
Schema error should NOT have additional properties
additionalProperty: components
Jump to line 0
如果由于某种原因我无法在根级别定义一个名为 Components 的元素,在根级别我将拥有某种 json 模式,那么按照我的意图在 requestBody 的模式上执行 $ref 以进行 API 操作的正确方法是什么正如我下面的示例所示。另外,你发现我的 swagger json 有什么问题吗?
我的 swagger2.0 的 swagger json 看起来像这样。
{
"swagger": "2.0",
"info": {
"version": "1.0",
"title": "My swagger API",
"contact": {
"name": "myName",
"email": "[email protected]"
}
},
"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"
}
}
}
}
}
}