0

,我發現了以下錯誤:揚鞭YAML查詢(對象類型)參數定義錯誤

Schema error at paths./cards/count.get.parameters[0] is not exactly one from <#/definitions/parameter>,<#/definitions/jsonReference>

這裏是我的定義:

/cards/count: 
    get: 
     tags: 
     - "cards" 
     summary: "Number of Cards available" 
     description: "Excludes cards which the user has answered correctly in the past." 
     operationId: "countCards" 
     produces: 
     - "application/json" 
     parameters: 
     - name: "tagFilter" 
     in: "query" 
     description: "Input is optional - left blank will return all tags and a count" 
     type: "object" 
     properties: 
      tags_any: 
      type: "array" 
      items: 
       type: "integer" 
       format: "int64" 
       enum: [1,2,3] 
      tags_all: 
      type: "array" 
      items: 
       type: "integer" 
       format: "int64" 
       enum: [4,5,6] 
      tags_not: 
      type: "array" 
      items: 
       type: "integer" 
       format: "int64" 
       enum: [4,5,6] 

我明白你不能用一個模式定義按照這個問題:Swagger: Reusing an enum definition as query parameter

我需要修改,以使YAML編譯沒有錯誤?

回答

1

OpenAPI/Swagger 2.0不支持查詢參數中的對象,但在OpenAPI 3.0中受支持。

如果你堅持的OpenAPI 2.0,您需要將對象分成單獨的參數,就像這樣:

 parameters: 
     - in: query 
      name: tags_any 
      type: array 
      items: 
      type: integer 
      format: int64 
      enum: [1,2,3] 
     - in: query 
      name: tags_all 
      type: array 
      items: 
      type: integer 
      format: int64 
      enum: [4,5,6] 
     - in: query 
      name: tags_not 
      type: array 
      items: 
      type: integer 
      format: int64 
      enum: [4,5,6] 

在OpenAPI的3.0,你可以定義參數作爲對象,並使用style and explode關鍵字指定應如何序列化此對象。

 parameters: 
     - name: tagFilter 
      in: query 
      description: Input is optional - left blank will return all tags and a count 

      # Send the object as ?prop1=value1&prop2=value2 
      # This is the default serialization method for objects in query parameters 
      style: form 
      explode: true 

      schema: 
      type: object 
      properties: 
       tags_any: 
       type: array 
       items: 
        type: integer 
        format: int64 
        enum: [1,2,3] 
       tags_all: 
       type: array 
       items: 
        type: integer 
        format: int64 
        enum: [4,5,6] 
       tags_not: 
       type: array 
       items: 
        type: integer 
        format: int64 
        enum: [4,5,6] 
+0

完美無缺 - 謝謝! –

+0

是否可以在Swaggerhub中使用開放API 3? –

+1

@AllanBowe目前沒有,但我會假設它在路線圖上。 – Helen