Swagger错误 - 描述:"不是有效的参数定义"

时间:2017-03-08 18:42:23

标签: swagger swagger-editor

我正在尝试为rest api定义一个简单的swagger定义。我的所有参数部分都出错了。

我在swagger编辑器中听到了swagger定义错误,我不知道我错了什么。请指教。

Swagger定义:

paths:
'/customer/{customerId}/accountlist':
get:
  responses:
    '200':
      description: ''
  parameters:
    - name: customerId
      in: path
      allowMultiple: false
      required: true
      type: string
  x-auth-type: None
  x-throttling-tier: Unlimited
  produces:
    - application/json
  x-scope: InternalUse
  swagger: '2.0'
  info:
  title: Sample
  description: API for Sample

Swagger错误:

Swagger Error
Not a valid parameter definition
Jump to line 7
Details
Object
code:  "ONE_OF_MISSING"
params: Array [0]
message:  "Not a valid parameter definition"
path: Array [5]
0:  "paths"
1:  "/customer/{customerId}/accountlist"
2:  "get"
3:  "parameters"
4:  "0"
schemaId:  "http://swagger.io/v2/schema.json#"
inner: Array [2]
0: Object
code:  "ONE_OF_MISSING"
params: Array [0]
message:  "Data does not match any schemas from 'oneOf'"
path: Array [5]
0:  "paths"
1:  "/customer/{customerId}/accountlist"
2:  "get"
3:  "parameters"
4:  "0"
inner: Array [2]
0: Object
code:  "OBJECT_MISSING_REQUIRED_PROPERTY"
params: Array [1]
0:  "schema"
message:  "Missing required property: schema"
path: Array [0]
1: Object
code:  "ONE_OF_MISSING"
params: Array [0]
message:  "Data does not match any schemas from 'oneOf'"
path: Array [0]
inner: Array [4]
1: Object
code:  "OBJECT_MISSING_REQUIRED_PROPERTY"
params: Array [1]
0:  "$ref"
message:  "Missing required property: $ref"
path: Array [5]
0:  "paths"
1:  "/customer/{customerId}/accountlist"
2:  "get"
3:  "parameters"
4:  "0"
level: 900
type:  "Swagger Error"
description:  "Not a valid parameter definition"
lineNumber: 7

1 个答案:

答案 0 :(得分:2)

我重写了你的OpenAPI规范。此版本有效:

swagger: '2.0'

info:
  title: Sample
  version: 1.0.0
  description: API for Sample

paths:
  '/customer/{customerId}/accountlist':
    get:
      responses:
        '200':
          description: ''
      parameters:
        - name: customerId
          in: path
          required: true
          type: string
      x-auth-type: None
      x-throttling-tier: Unlimited
      produces:
        - application/json
      x-scope: InternalUse

有关原始版本的一些评论:

  • 缩进很糟糕。例如,get:行需要从前一行缩进。但也许这只是一个副本和粘贴问题。

  • info对象需要version属性。

  • customerId参数包含allowMultiple属性。我发现错误,直到我删除它。