Skip to content

feat(RequestBody): set default true for 'send empty value' #6228

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

Merged
merged 3 commits into from
Jul 17, 2020
Merged
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
59 changes: 45 additions & 14 deletions src/core/components/parameter-include-empty.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
import React from "react"
import React, { Component } from "react"
import cx from "classnames"
import PropTypes from "prop-types"

export const ParameterIncludeEmpty = ({ isIncluded, onChange, isDisabled }) => {
const onCheckboxChange = e => {
onChange(e.target.checked)
}
return <label className={cx("parameter__empty_value_toggle", {
"disabled": isDisabled
})}>
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
Send empty value
</label>
}
ParameterIncludeEmpty.propTypes = {

const noop = () => { }

const ParameterIncludeEmptyPropTypes = {
isIncluded: PropTypes.bool.isRequired,
isDisabled: PropTypes.bool.isRequired,
isIncludedOptions: PropTypes.object,
onChange: PropTypes.func.isRequired,
}

export default ParameterIncludeEmpty
const ParameterIncludeEmptyDefaultProps = {
onChange: noop,
isIncludedOptions: {},
}
export default class ParameterIncludeEmpty extends Component {
static propTypes = ParameterIncludeEmptyPropTypes
static defaultProps = ParameterIncludeEmptyDefaultProps

componentDidMount() {
const { isIncludedOptions, onChange } = this.props
const { shouldDispatchInit, defaultValue } = isIncludedOptions
if (shouldDispatchInit) {
onChange(defaultValue)
}
}

onCheckboxChange = e => {
const { onChange } = this.props
onChange(e.target.checked)
}

render() {
let { isIncluded, isDisabled } = this.props

return (
<div>
<label className={cx("parameter__empty_value_toggle", {
"disabled": isDisabled
})}>
<input type="checkbox"
disabled={isDisabled}
checked={!isDisabled && isIncluded}
onChange={this.onCheckboxChange} />
Send empty value
</label>
</div>
)
}
}
16 changes: 15 additions & 1 deletion src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ const RequestBody = ({
const handleFile = (e) => {
onChange(e.target.files[0])
}
const setIsIncludedOptions = (key) => {
let options = {
key,
shouldDispatchInit: false,
defaultValue: true
}
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
}

const Markdown = getComponent("Markdown", true)
const ModelExample = getComponent("modelExample")
Expand Down Expand Up @@ -173,7 +186,8 @@ const RequestBody = ({
{required ? null : (
<ParameterIncludeEmpty
onChange={(value) => onChangeIncludeEmpty(key, value)}
isIncluded={requestBodyInclusionSetting.get(key)}
isIncluded={requestBodyInclusionSetting.get(key) || false}
isIncludedOptions={setIsIncludedOptions(key)}
isDisabled={!isEmptyValue(currentValue)}
/>
)}
Expand Down
Loading