OpenAPI-Specification
OpenAPI-Specification copied to clipboard
v3: How to require a multipart form data field?
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?
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.
@webron is this sort of thing a spec clarification candidate or would it better live in tutorial per OAI/Outreach#34?
Probably...
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.
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]