带有必需路径参数的OpenAPI定义错误

时间:2018-09-17 15:18:16

标签: swagger swagger-2.0 openapi

我刚刚开始创建我的第一个OpenAPI定义(2.0版),但我一直陷于这个错误:

  

无效的OpenAPI文件。请修复模式错误:\ n \“ / parameters / categoryParam \”:域:验证;关键字:oneOf;消息:实例不完全匹配一个模式;匹配:0“

这只是一个简单的查询,例如“ / cat / count”,它将返回存在的猫数的整数-“ cat”是必需的path参数。我的参数定义到底有什么问题?

swagger: '2.0'
info:
  description: "xxx"
  title: "xxx"
  version: "1.0.0"
host: "xxx"
consumes:
- "application/json"
produces:
- "application/json"
schemes:
- "https"
parameters:
  categoryParam:
    in: path
    name: category
    required: true
    schema:
      type: string
    description: "xxx"
paths:
  "/{category}/count":
    get:
      operationId: "get_category_count"
      parameters:
        - $ref: "#/parameters/categoryParam"
      produces:
        - application/json
      responses:
        '200':
          description: "xxx"
          schema:
            $ref: '#/definitions/Model0'
definitions:
  Model0:
    properties:
      count:
        type: string

1 个答案:

答案 0 :(得分:1)

没关系,愚蠢的错误。我需要更改:

schema:
  type: string

只是:

type:string