How to define path and formData parameters for the same operation in OpenAPI 2.0?
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.
Related videos on Youtube
JuKe
Updated on September 02, 2022Comments
-
JuKe over 1 year
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?
-
JuKe over 6 yearsthank 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
-
Helen over 6 yearsThose 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
-
Raj about 5 yearsHelped me though I wanted it in the reverse way :) I was on 3.0