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