【问题标题】:swagger failing to parse my parameters招摇未能解析我的参数
【发布时间】:2017-04-05 12:22:36
【问题描述】:

我有一个相对简单的 swagger 文档,它没有被解析,我在验证它时收到的错误消息对我来说没有意义:

以下是我的招摇文档:

---
swagger: '2.0'
info:
  version: 1.0.0
  title: Required APIs for Loan Provider
schemes:
- https
consumes:
- application/json
produces:
- application/json
paths:
  "/loan/{LoanGuid}/":
    post:
      description: initiation api for starting a loan
      operationId: InitLoan
      produces:
      - application/json
      parameters:
      - name: LoanGuid
        in: path
        type: string
        required: 'true'
      - name: body
        in: body
        schema:
          "$ref": "#/definitions/CreditApp"
      responses:
        '200':
          description: successful submittion of a loan
          schema:
            "$ref": "#/definitions/LoanDetails"
        '400':
          description: validation error
          schema:
            "$ref": "#/definitions/Error"
        '500':
          description: unknown exception
          schema:
            "$ref": "#/definitions/Error"
definitions:
  Error:
    title: Non Successful Response
    type: object
    properties:
      LoanGuid:
        description: the unique identifier for the loan
        type: string
      Error:
        type: string
  CreditApp:
    title: Credit Application
    type: object
    properties:
      FirstName:
        type: string
      MiddleName:
        type: string
      LastName:
        type: string
  Address:
    title: Address
    type: object
    properties:
      Street:
        type: string
      Street2:
        type: string
      City:
        type: string
      State:
        type: string
      Zip:
        type: string
  LoanDetails:
    title: Loan Details
    type: object
    properties:
      FirstName:
        type: string
      MiddleName:
        type: string
      LastName:
        type: string

我从http://editor.swagger.io/#/ 收到以下异常

Not a valid parameter definition
Jump to line 19
Details
 Object
code:  "ONE_OF_MISSING"
 params: Array [0]
message:  "Not a valid parameter definition"
 path: Array [5]
0:  "paths"
1:  "/loan/{LoanGuid}/"
2:  "post"
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]
 inner: Array [2]
 1: Object
code:  "OBJECT_MISSING_REQUIRED_PROPERTY"
 params: Array [1]
message:  "Missing required property: $ref"
 path: Array [5]
level: 900
type:  "Swagger Error"
description:  "Not a valid parameter definition"
lineNumber: 19

【问题讨论】:

    标签: yaml swagger openapi swagger-2.0


    【解决方案1】:

    改变

    required: 'true'
    

    required: true
    

    引号中的'true' 是字符串而不是布尔值。

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 1970-01-01
      • 2022-06-21
      • 1970-01-01
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多