Swagger:请求验证失败:参数验证模式验证失败”

时间:2019-07-11 07:46:37

标签: node.js mongodb mongoose swagger

我正在为我的项目创建一个api。我在用招摇。但是当我通过邮递员发布数据时,我不断收到“ SCHEMA_VALIDATION_FAILED”错误。

我的项目计划是

var projectSchema =  new mongoose.Schema({
  project_id: {
    type: String, 
    unique: true
  },
  project_name: {
    type: String, 
    unique : true
  },
  tasks: [{
        id: String,
        task_name: String
  }]
});

我发布的输入是

{
    "project_id": "afgnfgn",
    "project_name": "BLACKT",
    "tasks": [{
        "id": "aabfghfghjgj",
        "task_name": "LOGIN PAGE"
    }]
}

  /projectadd:
    post:
      summary: Project add
      operationId: projectadd
      consumes:
        - application/json
      parameters:
        - in: body
          name: project
          description: Project Title
          schema:
            type: array
            items:
              type: string       
      responses:
          200:
            description: Project Successfully Added
            schema:
              type: string
          400:
            description: Project addition Unsuccessful
            schema:
              type: string
    x-swagger-router-controller: project_add

当我摆放数据时会显示此错误

{
    "message": "Request validation failed: Parameter (project) failed schema validation",
    "code": "SCHEMA_VALIDATION_FAILED",
    "failedValidation": true,
    "results": {
        "errors": [
            {
                "code": "INVALID_TYPE",
                "message": "Expected type string but found type array",
                "path": [
                    "2"
                ]
            }
        ],
        "warnings": []
    },
    "path": [
        "paths",
        "/projectadd",
        "post",
        "parameters",
        "0"
    ],
    "paramName": "project"
}

我认为错误与招摇有关。 我是招摇和MongoDB的新手。

0 个答案:

没有答案