Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define path and formData parameters for the same operation in OpenAPI 2.0?

I have an image upload endpoint that looks like /test/{id}/relationships/image. I want to describe this endpoint using OpenAPI 2.0 (Swagger 2.0).

The endpoint has both path and formData parameters. I tried the following:

swagger: '2.0'
info:
  title: API
  version: 1.0.0
host: api.server.de
schemes:
  - https
produces:
  - application/json
paths:
  '/test/{id}/relationships/image':
    post:
      operationId: addImage
      consumes:
        - multipart/form-data
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
            format: int32
        - in: formData
          name: file
          type: file
          required: true
          description: The file to upload.
        - in: formData
          name: metadata
          type: string
          required: false
          description: Description of file contents.
      responses:
        '202':
          description: Uploaded

But Swagger Editor shows errors:

Schema error at paths['/test/{id}/relationships/image'].post.parameters[0].in should be equal to one of the allowed values allowedValues: body, header, formData, query Jump to line 17

Schema error at paths['/test/{id}/relationships/image'].post.parameters[0] should NOT have additional properties additionalProperty: schema, in, name, required Jump to line 17

What am I doing wrong?

like image 202
JuKe Avatar asked Aug 06 '17 16:08

JuKe


1 Answers

In your path parameter, change

          schema:
            type: integer
            format: int32

to

          type: integer
          format: int32

In OpenAPI/Swagger 2.0, path, header, query and formData parameters use type directly, without a schema. The schema keyword is used for body parameters only.

like image 187
Helen Avatar answered Oct 07 '22 23:10

Helen