9

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?

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much, that's helps. it's weird because the docs said something different swagger.io/docs/specification/paths-and-operations look at the '/users/{id}:' example and on this example also it uses the schema paramter swagger.io/docs/specification/describing-parameters
Those docs are for OpenAPI 3.0, as indicated by the note at the top. The 2.0 versions are swagger.io/docs/specification/2-0/paths-and-operations/ and swagger.io/docs/specification/2-0/describing-parameters
Helped me though I wanted it in the reverse way :) I was on 3.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.