首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误数据与“oneOf”中的任何模式不匹配

错误数据与“oneOf”中的任何模式不匹配
EN

Stack Overflow用户
提问于 2015-10-11 15:06:17
回答 1查看 10.3K关注 0票数 4

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

数据与“oneOf”中的任何架构不匹配

通过检查内在属性,我发现了一个更具描述性的错误:

OBJECT_MISSING_REQUIRED_PROPERTY 缺少必需的属性:$ref

重新阅读等级库,我发现没有必要在parameters“部分”中添加$ref属性,所以我感到困惑和困扰。

错误在第34行.

代码语言:javascript
复制
{
"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": ""
                }
            }
        }
    }
}

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-13 20:56:31

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

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

代码语言:javascript
复制
---
  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: ""
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33066507

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档