Swagger编辑说:不完全是来自<#/ definitions / parameter>,<#/ definitions / jsonReference>

时间:2017-06-12 12:39:20

标签: swagger swagger-editor

我试图为我的API定义一个swagger文档。 Swagger编辑不停地说is not exactly one from <#/definitions/parameter>,<#/definitions/jsonReference> 我检查了规范,参数应该有name, in required, descriptiondefault,如果不是in: body http://swagger.io/specification/#parameterObject

由于

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "semantify.it spec",
    "description": "Semantify.it. The APIs can be used to read, update, create and delete values inside the semantify.it database.",
    "termsOfService": "http://swagger.io/terms/"
  },
  "basePath": "/api",
  "schemes": [
    "http",
    "https"
  ],
  "paths": {
    "/login": {
      "post": {
        "tags": [
          "Login, Register"
        ],
        "consumes": [
          "application/x-www-form-urlencoded"
        ],
        "description": "Login and get a Token",
        "parameters": [
          {
            "name": "identifier",
            "in": "formData",
            "required": true,
            "default": "test-user",
            "description": "username or email"
          },
          {
            "name": "password",
            "in": "formData",
            "required": true,
            "default": "test-pass"
          }
        ],
        "responses": {
          "200": {
            "description": "Login success"
          }
        }
      }
    }
  }
}

1 个答案:

答案 0 :(得分:1)

有两个问题:

1)参数缺少type,例如"type": "string"

2)default未与必需参数一起使用,它仅用于可选参数。默认值是服务器在客户端未发送此参数时使用的值。但是如果需要参数,客户端必须始终发送它,并且永远不会使用默认值。