【问题标题】:Data does not match any schemas from 'oneOf' - Error数据与“oneOf”中的任何模式都不匹配 - 错误
【发布时间】:2015-09-30 18:39:54
【问题描述】:

我使用 swagger 在线编辑器遇到以下错误 数据与“oneOf”中的任何架构都不匹配

'/tenants/tenant_id/groups/group_id':
get:
  description: 'Returns the group with specific id ( id, name, description, tenant_id... ) along with end point pools ( id, name, description, source, tenant_id... ) associated with this particular groups'
  operationId: getGroupWithKey
  consumes:
    - application/json
    - text/plain, */*
  produces:
    - text/xml
  parameters:
    - in: header
      name: 'X-AuthToken'
      description: authentication token obtained during login
      required: true
      schema:
        $ref: '#/definitions/token_string'
  responses:
    '200':
      description: OK (group with provided id received)
      schema:
        $ref: '#/definitions/getGroupWithKey'
    default:
      description: error
      schema:
        $ref: '#/definitions/errorModel'

definitions:
### Login Definitions ###      
  token_string:
    type: object
    required:
      - 'X-AuthToken'
    properties:
      X-AuthToken: 
        type: string

错误如下所示指向第 206 行,即以“参数”开头的行

✖ Swagger Error

Data does not match any schemas from 'oneOf'   
Jump to line 206
Details
Object
code: "ONE_OF_MISSING"   
message: "Data does not match any schemas from 'oneOf'"
path: Array [5] 
0: "paths"
1: "/tenants/tenant_id/groups/group_id"
2: "get"
3: "parameters"
4: "0"
inner: Array [2]
0: Object
code: "ONE_OF_MISSING"
message: "Data does not match any schemas from 'oneOf'"
path: Array [5]
inner: Array [2]
1: Object
code: "OBJECT_MISSING_REQUIRED_PROPERTY"
message: "Missing required property: $ref"
path: Array [5]
level: 900
type: "Swagger Error"
description: "Data does not match any schemas from 'oneOf'"
lineNumber: 206

我尝试更改类型:定义下的字符串,仍然没有运气。 我很确定我在这里缺少正确的类型值,感谢任何帮助

谢谢你

【问题讨论】:

  • 你解决了这个问题吗?

标签: swagger swagger-2.0 swagger-editor


【解决方案1】:

定义头参数时不能使用schema,只有在使用in: body时才允许。 因此,标头参数只能是原子属性(字符串、数字、...)。

您似乎想定义一个可重用的标头参数,您可以这样做:

  • 在参数部分定义 token_string
  • 然后将它与$refin 操作的参数一起使用

(我还添加了虚拟getGroupWithKeyerrorModel 以使定义有效):

swagger: '2.0'
info:
  version: 1.0.0
  title: Header API
  description: A simple API to learn how you can define headers

paths:
  '/tenants/tenant_id/groups/group_id':
    get:
      description: 'Returns the group with specific id ( id, name, description, tenant_id... ) along with end point pools ( id, name, description, source, tenant_id... ) associated with this particular groups'
      operationId: getGroupWithKey
      consumes:
        - application/json
        - text/plain, */*
      produces:
        - text/xml
      parameters:
        - $ref: '#/parameters/token_string'
      responses:
        '200':
          description: OK (group with provided id received)
          schema:
            $ref: '#/definitions/getGroupWithKey'
        default:
          description: error
          schema:
            $ref: '#/definitions/errorModel'

parameters:
  token_string:
    in: header
    name: X-AuthToken
    type: string
    description: authentication token obtained during login
    required: true

definitions:
### Login Definitions ###      
  errorModel:
    type: string
  getGroupWithKey:
    type: string

如果你愿意,你当然可以定义你的参数内联。 我建议你看一下关于同一主题的另一个问题Define global parameters

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    相关资源
    最近更新 更多