-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration option to change default "send empty value" to true in form data #6505
Comments
I'm actually trying to set the 'setIsIncludedOptions' in the 'RequestBody' by a plugin as follows: file: request-body.jsx (...)
const RequestBody = ({
(...)
}) => {
const handleFile = (e) => {
onChange(e.target.files[0])
}
const setIsIncludedOptions = (key) => {
let options = {
key,
shouldDispatchInit: false,
defaultValue: false
}
let currentInclusion = requestBodyInclusionSetting.get(key, "no value")
if (currentInclusion === "no value") {
options.shouldDispatchInit = true
// future: can get/set defaultValue from a config setting
}
return options
}
(...)
} Is the current code allowing to change setIsIncludedOptions without forking the swagger-ui project? |
The ability to change the |
updating the issue title, and labeling as a feature request. |
I reported the same issue for .NET's Swashbuckle.AspNetCore and was redirected here. |
@tim-lai when you say this:
Does it mean it's something we can do via custom plugins, or is forking SwaggerUI the only way to change the default right now? For our use case it's rather painful that optional fields are sent as empty by default instead of excluded, since we have a lot of optional fields and the backend doesn't like empty values... Thanks! |
You should be able to do this via custom plugins, via wrapping the targeted component(s). |
Example:
|
how to get rid off "Send Empty Value" checkbox option? |
We are almost in 2024 and this option has not yet been implemented 😧 |
The "Send Empty Value" checkbox was causing a bug for me. When I uploaded a file, removed the file and clicked on the checkbox it would load forever, without it even triggering a breakpoint in the API controller. What I did was disable the "Send Empty Value" with this plugin:
I wonder if someone has encountered this issue before and has a better solution to it! |
Thank you @pdhar-tibco, your plugin works great to disable the Below is an implementation example for people who'd like to integrate it into their Swagger UI: <script>
window.onload = function() {
// Define uncheck empty value plugin
const UncheckSendEmptyValuePlugin = function() {
return {
wrapComponents: {
ParameterIncludeEmpty: (Original, { React }) => (props) => {
props.isIncludedOptions.defaultValue = false;
return React.createElement(Original, props)
},
TryItOutButton: (Original, { React }) => (props) => {
if (props.isOAS3 && props.hasUserEditedBody) { props.hasUserEditedBody = false; }
return React.createElement(Original, props)
}
}
}
}
// Build the Swagger UI
const ui = SwaggerUIBundle({
// ...
plugins: [
// ...
UncheckSendEmptyValuePlugin
],
// ...
})
window.ui = ui
}
</script> |
Hey , @timothee-peron I would like to work on this issue. Please assign it to me. |
/assign |
Hello,
![image](https://user-images.githubusercontent.com/7231341/95671283-62c45a00-0b95-11eb-8b03-13b0d499e7be.png)
In my API, I have some multipart forms, here's a screenshot from the pet store:
I want to have these checkboxes unchecked by default, because of the way my API deals with empty form fields.
So far, I've tried to modify the request-body and the parameter-include-empty components by writing a plug-in, but I'm struggling to have the parameter-include-empty unchecked (by setting isIncluded to false) without breaking the behaviour of request-body.
Is the current version of swagger-ui allowing for this customization?
Sorry for my poor skills in react, any help is welcome!
Related links:
#5830 Allow to skip submitting empty values in form data
#6228 Set default true for 'send empty value'
The text was updated successfully, but these errors were encountered: