path and formData paramter at the same time

雨燕双飞 提交于 2019-12-19 16:50:54

问题


i want to upload a image to my API endpoint. the endpoint should be /test/{id}/relationships/image. i want to describe with swagger path and formData parameters at the same time.

my swagger yaml file looks like this:

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 i got an error:

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 do i wrong?


回答1:


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.



来源:https://stackoverflow.com/questions/45534187/path-and-formdata-paramter-at-the-same-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!