Swagger错误|数据与' oneOf'中的任何模式都不匹配。

时间:2015-10-11 15:06:17

标签: api swagger

我正在使用Swagger规范设计API。毫无疑问,我面临一个我无法解决的错误。

  

数据与' oneOf'

中的任何架构都不匹配

检查inner property,我发现了一个更具描述性的错误:

  

OBJECT_MISSING_REQUIRED_PROPERTY

     

缺少必需的财产:$ ref

重新阅读spec,我发现无需在$ref"部分"中添加parameters属性,因此我可以困惑和困惑。

错误在第34行。

{
"swagger": "2.0",
"info": {
    "title": "###",
    "version": "0.1.0"
},
"host": "api.###",
"basePath": "/",
"schemes": [
    "https"
],
"produces": [
    "application/json"
],
"paths": {
    "/social-networks": {
        "get": {
            "summary": "Retrieves all social networks.",
            "description": "Retrieves all social networks supported by ### along with the constraints of each one.",
            "responses": {
                "200": {
                    "description": "",
                    "examples": {
                        "application/json": {}
                    }
                }
            }
        }
    },
    "/social-networks/{name}": {
        "get": {
            "summary": "Retrieves a social network.",
            "description": "Retrieves the social network whose name matches with the specified path parameter.",
            "parameters": [
                {
                    "name": "name",
                    "in": "path",
                    "description": "The name of the social network.",
                    "required": "true",
                    "type": "string"
                }
            ],
            "responses": {
                "200": {
                    "description": ""
                }
            }
        }
    }
}

我做错了什么?

1 个答案:

答案 0 :(得分:3)

路径参数的required值应为true。你的是字符串"true"

您的JSON也无效,但您最后错过了一个}。以下是YAML中Swagger的固定版本:

---
  swagger: "2.0"
  info: 
    title: "###"
    version: "0.1.0"
  host: "api.###"
  basePath: "/"
  schemes: 
    - "https"
  produces: 
    - "application/json"
  paths: 
    /social-networks: 
      get: 
        summary: "Retrieves all social networks."
        description: "Retrieves all social networks supported by ### along with the constraints of each one."
        responses: 
          200: 
            description: ""
            examples: 
              application/json: {}
    /social-networks/{name}: 
      get: 
        summary: "Retrieves a social network."
        description: "Retrieves the social network whose name matches with the specified path parameter."
        parameters: 
          - 
            name: "name"
            in: "path"
            description: "The name of the social network."
            required: true
            type: "string"
        responses: 
          200: 
            description: ""