Skip to content

Commit 1b6cb7d

Browse files
committed
revert: feat: Allow to skip submitting empty values in form data (swagger-api#5830)
This reverts commit b9b32c9. Refs swagger-api#6203 swagger-api#5830
1 parent e3b3bf0 commit 1b6cb7d

File tree

10 files changed

+27
-75
lines changed

10 files changed

+27
-75
lines changed

src/core/components/parameter-include-empty.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import React from "react"
22
import cx from "classnames"
33
import PropTypes from "prop-types"
4+
import ImPropTypes from "react-immutable-proptypes"
45

5-
export const ParameterIncludeEmpty = ({ isIncluded, onChange, isDisabled }) => {
6+
export const ParameterIncludeEmpty = ({ param, isIncluded, onChange, isDisabled }) => {
67
const onCheckboxChange = e => {
78
onChange(e.target.checked)
89
}
9-
return <label className={cx("parameter__empty_value_toggle", {
10+
if(!param.get("allowEmptyValue")) {
11+
return null
12+
}
13+
return <div className={cx("parameter__empty_value_toggle", {
1014
"disabled": isDisabled
1115
})}>
1216
<input type="checkbox" disabled={isDisabled} checked={!isDisabled && isIncluded} onChange={onCheckboxChange} />
1317
Send empty value
14-
</label>
18+
</div>
1519
}
1620
ParameterIncludeEmpty.propTypes = {
21+
param: ImPropTypes.map.isRequired,
1722
isIncluded: PropTypes.bool.isRequired,
1823
isDisabled: PropTypes.bool.isRequired,
1924
onChange: PropTypes.func.isRequired,

src/core/components/parameter-row.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Map, List } from "immutable"
33
import PropTypes from "prop-types"
44
import ImPropTypes from "react-immutable-proptypes"
55
import win from "core/window"
6-
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify, isEmptyValue } from "core/utils"
6+
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify } from "core/utils"
77
import getParameterSchema from "../../helpers/get-parameter-schema.js"
88

99
export default class ParameterRow extends Component {
@@ -343,11 +343,12 @@ export default class ParameterRow extends Component {
343343
}
344344

345345
{
346-
!bodyParam && isExecute && param.get("allowEmptyValue") ?
346+
!bodyParam && isExecute ?
347347
<ParameterIncludeEmpty
348348
onChange={this.onChangeIncludeEmpty}
349349
isIncluded={specSelectors.parameterInclusionSettingFor(pathMethod, param.get("name"), param.get("in"))}
350-
isDisabled={!isEmptyValue(value)} />
350+
isDisabled={value && value.size !== 0}
351+
param={param} />
351352
: null
352353
}
353354

src/core/components/parameters/parameters.jsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ export default class Parameters extends Component {
196196
specPath={specPath.slice(0, -1).push("requestBody")}
197197
requestBody={requestBody}
198198
requestBodyValue={oas3Selectors.requestBodyValue(...pathMethod)}
199-
requestBodyInclusionSetting={oas3Selectors.requestBodyInclusionSetting(...pathMethod)}
200199
isExecute={isExecute}
201200
activeExamplesKey={oas3Selectors.activeExamplesMember(
202201
...pathMethod,
@@ -223,13 +222,6 @@ export default class Parameters extends Component {
223222
}
224223
oas3Actions.setRequestBodyValue({ value, pathMethod })
225224
}}
226-
onChangeIncludeEmpty={(name, value) => {
227-
oas3Actions.setRequestBodyInclusion({
228-
pathMethod,
229-
value,
230-
name,
231-
})
232-
}}
233225
contentType={oas3Selectors.requestContentType(...pathMethod)}/>
234226
</div>
235227
</div>

src/core/plugins/oas3/actions.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
export const UPDATE_SELECTED_SERVER = "oas3_set_servers"
55
export const UPDATE_REQUEST_BODY_VALUE = "oas3_set_request_body_value"
6-
export const UPDATE_REQUEST_BODY_INCLUSION = "oas3_set_request_body_inclusion"
76
export const UPDATE_ACTIVE_EXAMPLES_MEMBER = "oas3_set_active_examples_member"
87
export const UPDATE_REQUEST_CONTENT_TYPE = "oas3_set_request_content_type"
98
export const UPDATE_RESPONSE_CONTENT_TYPE = "oas3_set_response_content_type"
@@ -23,13 +22,6 @@ export function setRequestBodyValue ({ value, pathMethod }) {
2322
}
2423
}
2524

26-
export function setRequestBodyInclusion ({ value, pathMethod, name }) {
27-
return {
28-
type: UPDATE_REQUEST_BODY_INCLUSION,
29-
payload: { value, pathMethod, name }
30-
}
31-
}
32-
3325
export function setActiveExamplesMember ({ name, pathMethod, contextType, contextName }) {
3426
return {
3527
type: UPDATE_ACTIVE_EXAMPLES_MEMBER,

src/core/plugins/oas3/components/request-body.jsx

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react"
22
import PropTypes from "prop-types"
33
import ImPropTypes from "react-immutable-proptypes"
44
import { Map, OrderedMap, List } from "immutable"
5-
import { getCommonExtensions, getSampleSchema, stringify, isEmptyValue } from "core/utils"
5+
import { getCommonExtensions, getSampleSchema, stringify } from "core/utils"
66

77
function getDefaultRequestBodyValue(requestBody, mediaType, activeExamplesKey) {
88
let mediaTypeValue = requestBody.getIn(["content", mediaType])
@@ -37,7 +37,6 @@ function getDefaultRequestBodyValue(requestBody, mediaType, activeExamplesKey) {
3737
const RequestBody = ({
3838
requestBody,
3939
requestBodyValue,
40-
requestBodyInclusionSetting,
4140
getComponent,
4241
getConfigs,
4342
specSelectors,
@@ -46,7 +45,6 @@ const RequestBody = ({
4645
isExecute,
4746
specPath,
4847
onChange,
49-
onChangeIncludeEmpty,
5048
activeExamplesKey,
5149
updateActiveExamplesKey,
5250
}) => {
@@ -60,7 +58,6 @@ const RequestBody = ({
6058
const HighlightCode = getComponent("highlightCode")
6159
const ExamplesSelectValueRetainer = getComponent("ExamplesSelectValueRetainer")
6260
const Example = getComponent("Example")
63-
const ParameterIncludeEmpty = getComponent("ParameterIncludeEmpty")
6461

6562
const { showCommonExtensions } = getConfigs()
6663

@@ -158,26 +155,17 @@ const RequestBody = ({
158155
</td>
159156
<td className="parameters-col_description">
160157
<Markdown source={ description }></Markdown>
161-
{isExecute ? <div>
162-
<JsonSchemaForm
163-
fn={fn}
164-
dispatchInitialValue={!isFile}
165-
schema={prop}
166-
description={key}
167-
getComponent={getComponent}
168-
value={currentValue === undefined ? initialValue : currentValue}
169-
onChange={(value) => {
170-
onChange(value, [key])
171-
}}
172-
/>
173-
{required ? null : (
174-
<ParameterIncludeEmpty
175-
onChange={(value) => onChangeIncludeEmpty(key, value)}
176-
isIncluded={requestBodyInclusionSetting.get(key)}
177-
isDisabled={!isEmptyValue(currentValue)}
178-
/>
179-
)}
180-
</div> : null }
158+
{isExecute ? <div><JsonSchemaForm
159+
fn={fn}
160+
dispatchInitialValue={!isFile}
161+
schema={prop}
162+
description={key}
163+
getComponent={getComponent}
164+
value={currentValue === undefined ? initialValue : currentValue}
165+
onChange={(value) => {
166+
onChange(value, [key])
167+
}}
168+
/></div> : null }
181169
</td>
182170
</tr>
183171
})
@@ -255,15 +243,13 @@ const RequestBody = ({
255243
RequestBody.propTypes = {
256244
requestBody: ImPropTypes.orderedMap.isRequired,
257245
requestBodyValue: ImPropTypes.orderedMap.isRequired,
258-
requestBodyInclusionSetting: ImPropTypes.Map.isRequired,
259246
getComponent: PropTypes.func.isRequired,
260247
getConfigs: PropTypes.func.isRequired,
261248
fn: PropTypes.object.isRequired,
262249
specSelectors: PropTypes.object.isRequired,
263250
contentType: PropTypes.string,
264251
isExecute: PropTypes.bool.isRequired,
265252
onChange: PropTypes.func.isRequired,
266-
onChangeIncludeEmpty: PropTypes.func.isRequired,
267253
specPath: PropTypes.array.isRequired,
268254
activeExamplesKey: PropTypes.string,
269255
updateActiveExamplesKey: PropTypes.func,

src/core/plugins/oas3/reducers.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
UPDATE_SELECTED_SERVER,
33
UPDATE_REQUEST_BODY_VALUE,
4-
UPDATE_REQUEST_BODY_INCLUSION,
54
UPDATE_ACTIVE_EXAMPLES_MEMBER,
65
UPDATE_REQUEST_CONTENT_TYPE,
76
UPDATE_SERVER_VARIABLE_VALUE,
@@ -17,10 +16,6 @@ export default {
1716
let [path, method] = pathMethod
1817
return state.setIn( [ "requestData", path, method, "bodyValue" ], value)
1918
},
20-
[UPDATE_REQUEST_BODY_INCLUSION]: (state, { payload: { value, pathMethod, name } } ) =>{
21-
let [path, method] = pathMethod
22-
return state.setIn( [ "requestData", path, method, "bodyInclusion", name ], value)
23-
},
2419
[UPDATE_ACTIVE_EXAMPLES_MEMBER]: (state, { payload: { name, pathMethod, contextType, contextName } } ) =>{
2520
let [path, method] = pathMethod
2621
return state.setIn( [ "examples", path, method, contextType, contextName, "activeExample" ], name)

src/core/plugins/oas3/selectors.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OrderedMap, Map } from "immutable"
1+
import { OrderedMap } from "immutable"
22
import { isOAS3 as isOAS3Helper } from "./helpers"
33

44

@@ -26,11 +26,6 @@ export const requestBodyValue = onlyOAS3((state, path, method) => {
2626
}
2727
)
2828

29-
export const requestBodyInclusionSetting = onlyOAS3((state, path, method) => {
30-
return state.getIn(["requestData", path, method, "bodyInclusion"]) || Map()
31-
}
32-
)
33-
3429
export const activeExamplesMember = onlyOAS3((state, path, method, type, name) => {
3530
return state.getIn(["examples", path, method, type, name, "activeExample"]) || null
3631
}

src/core/plugins/spec/actions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import serializeError from "serialize-error"
55
import isString from "lodash/isString"
66
import debounce from "lodash/debounce"
77
import set from "lodash/set"
8-
import { isJSONObject, paramToValue, isEmptyValue } from "core/utils"
8+
import { isJSONObject, paramToValue } from "core/utils"
99

1010
// Actions conform to FSA (flux-standard-actions)
1111
// {type: string,payload: Any|Error, meta: obj, error: bool}
@@ -401,12 +401,11 @@ export const executeRequest = (req) =>
401401
req.requestContentType = oas3Selectors.requestContentType(pathName, method)
402402
req.responseContentType = oas3Selectors.responseContentType(pathName, method) || "*/*"
403403
const requestBody = oas3Selectors.requestBodyValue(pathName, method)
404-
const requestBodyInclusionSetting = oas3Selectors.requestBodyInclusionSetting(pathName, method)
405404

406405
if(isJSONObject(requestBody)) {
407406
req.requestBody = JSON.parse(requestBody)
408407
} else if(requestBody && requestBody.toJS) {
409-
req.requestBody = requestBody.filter((value, key) => !isEmptyValue(value) || requestBodyInclusionSetting.get(key)).toJS()
408+
req.requestBody = requestBody.toJS()
410409
} else{
411410
req.requestBody = requestBody
412411
}

src/core/utils.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -956,15 +956,3 @@ function b64toB64UrlEncoded(str) {
956956
.replace(/\//g, "_")
957957
.replace(/=/g, "")
958958
}
959-
960-
export const isEmptyValue = (value) => {
961-
if (!value) {
962-
return true
963-
}
964-
965-
if (isImmutable(value) && value.isEmpty()) {
966-
return true
967-
}
968-
969-
return false
970-
}

src/style/_table.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ table
157157
}
158158

159159
.parameter__empty_value_toggle {
160-
display: block;
161160
font-size: 13px;
162161
padding-top: 5px;
163162
padding-bottom: 12px;

0 commit comments

Comments
 (0)