question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v3: How to require a multipart form data field?

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
berkantcommented, Jun 18, 2019

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.

0reactions
Feezan-Khattakcommented, Jul 13, 2022

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]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify a multipart form field is optional in OpenAPI ...
Expected: Detail a multipart/form-data requestBody with some fields required and some optional. In the code example above, foo should be a ...
Read more >
Multipart Requests - Swagger
You start with the requestBody/content keyword. Then, you specify the media type of request data. File uploads typically use the multipart/form-data media type, ......
Read more >
Define multipart form data - GeeksforGeeks
Approach: In this example, we are creating a simple HTML form (uploading.html) for uploading an image file to the server. The server will ......
Read more >
Uploads, multipart/form-data & UploadedFile - SymfonyCasts
Create a totally new, temporary endpoint: public function temporaryUploadAction() . We're going to create an HTML form in our template, put an input...
Read more >
withMultiPartFormData - PactumJS
const { spec } = require('pactum'); const FormData = require('form-data-lite'); const form = new FormData(); form.append('file', fs.readFileSync ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found