OpenAPI-Specification icon indicating copy to clipboard operation
OpenAPI-Specification copied to clipboard

v3: How to require a multipart form data field?

Open berkant opened this issue 5 years ago • 7 comments

It is possible to require a specific field in multipart form data in v2 but I don't see any notion of this in v3 spec and Swagger docs.

v2: https://swagger.io/docs/specification/2-0/file-upload/, Upload a File + Other Data title has a sample.

v3: https://swagger.io/docs/specification/describing-request-body/multipart-requests/, https://swagger.io/docs/specification/describing-request-body/file-upload/, none includes the word require.

Am I looking for it in the wrong place or is it something not put intentionally or even forgotten?

berkant avatar Jun 17 '19 17:06 berkant

Aha, I found it. We need to set an array required and put the required fields' name there.

          multipart/form-data:
            schema:
              type: object
              properties:
                pre:
                  type: string
                  format: binary
                script:
                  type: string
                  format: binary
                post:
                  type: string
                  format: binary
                webhook:
                  type: string
                  format: uri
              required:
                - script

But this is not explicitly cited in docs. I better propose a change for it.

berkant avatar Jun 18 '19 04:06 berkant

@webron is this sort of thing a spec clarification candidate or would it better live in tutorial per OAI/Outreach#34?

handrews avatar Jan 21 '20 01:01 handrews

Probably...

webron avatar Jan 23 '20 00:01 webron

Aha, I found it. We need to set an array required and put the required fields' name there.

          multipart/form-data:
            schema:
              type: object
              properties:
                pre:
                  type: string
                  format: binary
                script:
                  type: string
                  format: binary
                post:
                  type: string
                  format: binary
                webhook:
                  type: string
                  format: uri
              required:
                - script

But this is not explicitly cited in docs. I better propose a change for it.

Could you describe it how to make a field of form displayed as required? In the form I have an upload and some fields too.

lmpampaletakis avatar Oct 21 '20 06:10 lmpampaletakis

Could you describe it how to make a field of form displayed as required? In the form I have an upload and some fields too.

You just need to provide the the 'required as'

          multipart/form-data:
            schema:
              type: object
              properties:
                pre:
                  type: string
                  format: binary
                script:
                  type: string
                  format: binary
                post:
                  type: string
                  format: binary
                webhook:
                  type: string
                  format: uri
              required: [script]

Feezan-Khattak avatar Jul 13 '22 07:07 Feezan-Khattak