简体   繁体   中英

Not a valid parameter definition

 /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: ''

Here's the snippet. It says that on the line with $ref: '#/definitions/CancelRequest' there is a wrong parameter definition. What might be the problem?

The error is probably misleading, the problem is with other parameters:

  1. The Content-Type header should be defined using the consumes keyword rather than a parameter:

     /cancel: post: consumes: - application/json - application/xml 
  2. Header parameters require a type (not a schema ) and the type must be a simple type and cannot be a $ref . So it should be:

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

    However, in case of the Authorization header you should probably use a security definition instead. For example, if your API uses Basic authentication:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM