Omit empty and optional values in form data
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:18
- Comments:16 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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…
This doesn’t really solve the problem completely but, in case you didn’t know, you can provide another
required
property underschema
which is a list of required properties e.g.Which will render
*required
next to the required “name” field