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.

Omit empty and optional values in form data

See original GitHub issue

I have this request body:

...
requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                name:
                  type: string
                nick:
                  type: string
...

If I send a request wihin Swagger UI with some name but with empty value in the nick field, the UI evaluates the request like this:

curl -X POST "address" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "name=vaclav&nick="

But I need not to have the nick field contained in the request body if the field is empty, like this:

curl -X POST "address" -H "accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -d "name=vaclav"

Can I mark a property field as optional and not sending if the field is empty? Unfortunately, my API does not accept empty values, but it is able to omit some post field if it is not included in a request.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:18
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
propicommented, May 6, 2019

I would vote for adding a checkbox to all optional parameters within the Swagger UI (it could be checked by default). But, I need to have the option to uncheck this checbox and tell Swagger UI, that I don’t want to send this parameter in the HTTP request…

5reactions
leggsimoncommented, Apr 19, 2019

This doesn’t really solve the problem completely but, in case you didn’t know, you can provide another required property under schema which is a list of required properties e.g.

      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                name:
                  type: string
                nick:
                  type: string
+              required:
+                - name

Which will render *required next to the required “name” field localhost_3230__url=_documents_bugs_5303 yaml

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to omit empty/null field's before submitting form with Formik
1 Answer 1. Sorted by: Reset to default. Highest score (default) ...
Read more >
Golang Omitempty Explained - < Soham Kamani />
This post will explain what exactly the omitempty tag means, ... Now, if WeightKg is set to it's default value (which is 0...
Read more >
Go's Omitempty - Medium
The “omitempty” option specifies that the field should be omitted from the encoding if the field has an empty value, defined as false,...
Read more >
Should empty optional field displayed in form overview before ...
1 Answer. Save this answer. Show activity on this post. It would be better usability on the Review screen to show the optional...
Read more >
FormData() - Web APIs - MDN Web Docs - Mozilla
form Optional ... The following line creates an empty FormData object: ... You could add a key/value pair to this using append() :....
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