【问题标题】:Swagger error | Data does not match any schemas from 'oneOf'招摇错误 |数据与“oneOf”中的任何模式都不匹配
【发布时间】:2015-10-14 04:56:31
【问题描述】:

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

数据与“oneOf”中的任何模式都不匹配

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

OBJECT_MISSING_REQUIRED_PROPERTY

缺少必需的属性:$ref

重读spec,发现不需要在parameters“部分”中添加$ref属性,所以我很困惑,卡住了。

错误在第 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": ""
                }
            }
        }
    }
}

我做错了什么?

【问题讨论】:

  • @bish 第 34 行恰恰是 parameters 部分。

标签: api swagger


【解决方案1】:

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

【讨论】:

  • 非常感谢!正如您所说,错误是“引用的true 值”。
猜你喜欢
  • 1970-01-01
  • 2020-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-15
相关资源
最近更新 更多