Skip to content
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

feat: Implement a configuration option for the initial "send empty value" checkbox state. #10274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker/configurator/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ const standardVariables = {
type: "string",
name: "defaultModelRendering"
},
DEFAULT_SEND_EMPTY_VAlUE: {
type: "boolean",
name: "defaultSendEmptyValue"
},
DISPLAY_REQUEST_DURATION: {
type: "boolean",
name: "displayRequestDuration"
Expand Down
8 changes: 8 additions & 0 deletions docs/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ Parameter name | Docker variable | Description
Value' links.)
</td>
</tr>
<tr>
<td><a name="user-content-defaultsendemptyvalue"></a><code>defaultSendEmptyValue</code>
</td>
<td><code>DEFAULT_SEND_EMPTY_VAlUE</code></td>
<td><code>Boolean=true</code>. Controls the initial state of the "Send empty value" checkbox in "Try it out"
forms. The default is <code>true</code> (checked).
</td>
</tr>
<tr>
<td><a name="user-content-displayrequestduration"></a><code>displayRequestDuration</code>
</td>
Expand Down
3 changes: 3 additions & 0 deletions flavors/swagger-ui-react/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SwaggerUI = ({
defaultModelExpandDepth = config.defaults.defaultModelExpandDepth,
defaultModelsExpandDepth = config.defaults.defaultModelsExpandDepth,
defaultModelRendering = config.defaults.defaultModelRendering,
defaultSendEmptyValue = config.defaults.defaultSendEmptyValue,
presets = config.defaults.presets,
deepLinking = config.defaults.deepLinking,
showExtensions = config.defaults.showExtensions,
Expand Down Expand Up @@ -59,6 +60,7 @@ const SwaggerUI = ({
layout,
defaultModelsExpandDepth,
defaultModelRendering,
defaultSendEmptyValue,
presets: [SwaggerUIConstructor.presets.apis, ...presets],
requestInterceptor,
responseInterceptor,
Expand Down Expand Up @@ -153,6 +155,7 @@ SwaggerUI.propTypes = {
defaultModelExpandDepth: PropTypes.number,
defaultModelsExpandDepth: PropTypes.number,
defaultModelRendering: PropTypes.oneOf(["example", "model"]),
defaultSendEmptyValue: PropTypes.bool,
presets: PropTypes.arrayOf(PropTypes.func),
deepLinking: PropTypes.bool,
showExtensions: PropTypes.bool,
Expand Down
1 change: 1 addition & 0 deletions src/core/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultOptions = Object.freeze({
defaultModelRendering: "example",
defaultModelExpandDepth: 1,
defaultModelsExpandDepth: 1,
defaultSendEmptyValue: true,
showExtensions: false,
showCommonExtensions: false,
withCredentials: false,
Expand Down
4 changes: 4 additions & 0 deletions src/core/config/type-cast/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const mappings = {
typeCaster: numberTypeCaster,
defaultValue: defaultOptions.defaultModelsExpandDepth,
},
defaultSendEmptyValue: {
typeCaster: booleanTypeCaster,
defaultValue: defaultOptions.defaultSendEmptyValue,
},
displayOperationId: {
typeCaster: booleanTypeCaster,
defaultValue: defaultOptions.displayOperationId,
Expand Down
8 changes: 4 additions & 4 deletions src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const RequestBody = ({
const handleFile = (e) => {
onChange(e.target.files[0])
}
const setIsIncludedOptions = (key) => {
const setIsIncludedOptions = (key, defaultSendEmptyValue) => {
let options = {
key,
shouldDispatchInit: false,
Expand All @@ -63,7 +63,7 @@ const RequestBody = ({
let currentInclusion = requestBodyInclusionSetting.get(key, "no value")
if (currentInclusion === "no value") {
options.shouldDispatchInit = true
// future: can get/set defaultValue from a config setting
options.defaultValue = defaultSendEmptyValue
}
return options
}
Expand All @@ -76,7 +76,7 @@ const RequestBody = ({
const Example = getComponent("Example")
const ParameterIncludeEmpty = getComponent("ParameterIncludeEmpty")

const { showCommonExtensions } = getConfigs()
const { showCommonExtensions, defaultSendEmptyValue } = getConfigs()

const requestBodyDescription = requestBody?.get("description") ?? null
const requestBodyContent = requestBody?.get("content") ?? new OrderedMap()
Expand Down Expand Up @@ -223,7 +223,7 @@ const RequestBody = ({
<ParameterIncludeEmpty
onChange={(value) => onChangeIncludeEmpty(key, value)}
isIncluded={included}
isIncludedOptions={setIsIncludedOptions(key)}
isIncludedOptions={setIsIncludedOptions(key, defaultSendEmptyValue)}
isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)}
/>
)}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/docker/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ describe("docker: env translator", function() {
DEFAULT_MODELS_EXPAND_DEPTH: "0",
DEFAULT_MODEL_EXPAND_DEPTH: "1",
DEFAULT_MODEL_RENDERING: "example",
DEFAULT_SEND_EMPTY_VAlUE: "false",
DISPLAY_REQUEST_DURATION: "true",
DOC_EXPANSION: "full",
FILTER: "wowee",
Expand All @@ -264,6 +265,7 @@ describe("docker: env translator", function() {
defaultModelsExpandDepth: 0,
defaultModelExpandDepth: 1,
defaultModelRendering: "example",
defaultSendEmptyValue: false,
displayRequestDuration: true,
docExpansion: "full",
filter: "wowee",
Expand Down Expand Up @@ -294,6 +296,7 @@ describe("docker: env translator", function() {
DEFAULT_MODELS_EXPAND_DEPTH: "0",
DEFAULT_MODEL_EXPAND_DEPTH: "1",
DEFAULT_MODEL_RENDERING: "example",
DEFAULT_SEND_EMPTY_VAlUE: "false",
DISPLAY_REQUEST_DURATION: "true",
DOC_EXPANSION: "full",
FILTER: "wowee",
Expand Down Expand Up @@ -328,6 +331,7 @@ describe("docker: env translator", function() {
defaultModelsExpandDepth: 0,
defaultModelExpandDepth: 1,
defaultModelRendering: "example",
defaultSendEmptyValue: false,
displayRequestDuration: true,
docExpansion: "full",
filter: "wowee",
Expand Down