2017-03-08 60 views
0

我想爲休息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 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 
+0

請在您的問題中最好以YAML格式包含Swagger/OpenAPI定義。 –

+0

添加示例swagger定義作爲問題的一部分。 – Pravin

回答

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屬性。我看到一個錯誤,直到我刪除它。

+0

謝謝戴夫。有效。 allowMultiple是擾流板。 – Pravin

相關問題