【问题标题】:Not a valid parameter definition不是有效的参数定义
【发布时间】:2017-08-30 21:06:48
【问题描述】:
 /cancel:
    post:
      description: ''
      summary: Cancel
      operationId: Cancel
      produces:
      - application/json
      parameters:
      - name: Body
        in: body
        required: true
        description: ''
        schema:
          $ref: '#/definitions/CancelRequest'
      - name: Authorization
        in: header
        required: true
        description: ''
        schema: 
          $ref: '#/definitions/Authorization'
      - name: Content-Type
        in: header
        required: true
        type: string
        description: ''

这里是sn-p。它说在$ref: '#/definitions/CancelRequest' 行有一个错误的参数定义。可能是什么问题?

【问题讨论】:

    标签: yaml swagger


    【解决方案1】:

    错误可能是误导,问题出在其他参数上:

    1. Content-Type 标头应该使用consumes 关键字而不是参数来定义:

      /cancel:
          post:
            consumes:
            - application/json
            - application/xml
      
    2. 标头参数需要type(不是schema),并且type 必须是简单类型且不能是$ref。所以应该是:

          - name: Authorization
            in: header
            required: true
            description: ''
            type: string    # <-------
      

      但是,对于 Authorization 标头,您可能应该改用 security definition。例如,如果您的 API 使用基本身份验证:

      securityDefinitions:
        BasicAuth:
          type: basic
      
      paths:
        /cancel:
          post:
            security:
            - BasicAuth: []
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-19
      相关资源
      最近更新 更多