大摇大摆的错误 |数据与 'oneOf' 中的任何模式都不匹配

Swagger error | Data does not match any schemas from 'oneOf'

我正在使用 Swagger 规范设计 API。不幸的是,我遇到了一个我无法解决的错误。

Data does not match any schemas from 'oneOf'

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

OBJECT_MISSING_REQUIRED_PROPERTY

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": ""
                }
            }
        }
    }
}

我做错了什么?

路径参数的 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: ""