feature: allowEmptyValue controls (#4788)
* add baseline tests * coerce empty strings to null when updating parameter values * add ParameterIncludeEmpty * add redux management for empty parameter value inclusion state * use name+in keying for state management instead of hash keying * update new redux method usages to name+in keying * coerce empty Immutable iterables in onChangeWrapper * OAS3 tests & support * add included empty parameters to requests before dispatching to Swagger Client * make empty inclusion interface prettier * add tests for #4587 * linter fixes * check for truthy value before reaching into property
This commit is contained in:
@@ -14,6 +14,7 @@ export const UPDATE_SPEC = "spec_update_spec"
|
||||
export const UPDATE_URL = "spec_update_url"
|
||||
export const UPDATE_JSON = "spec_update_json"
|
||||
export const UPDATE_PARAM = "spec_update_param"
|
||||
export const UPDATE_EMPTY_PARAM_INCLUSION = "spec_update_empty_param_inclusion"
|
||||
export const VALIDATE_PARAMS = "spec_validate_param"
|
||||
export const SET_RESPONSE = "spec_set_response"
|
||||
export const SET_REQUEST = "spec_set_request"
|
||||
@@ -270,6 +271,18 @@ export const validateParams = ( payload, isOAS3 ) =>{
|
||||
}
|
||||
}
|
||||
|
||||
export const updateEmptyParamInclusion = ( pathMethod, paramName, paramIn, includeEmptyValue ) =>{
|
||||
return {
|
||||
type: UPDATE_EMPTY_PARAM_INCLUSION,
|
||||
payload:{
|
||||
pathMethod,
|
||||
paramName,
|
||||
paramIn,
|
||||
includeEmptyValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function clearValidateParams( payload ){
|
||||
return {
|
||||
type: CLEAR_VALIDATE_PARAMS,
|
||||
@@ -327,7 +340,28 @@ export const executeRequest = (req) =>
|
||||
let { pathName, method, operation } = req
|
||||
let { requestInterceptor, responseInterceptor } = getConfigs()
|
||||
|
||||
|
||||
let op = operation.toJS()
|
||||
|
||||
// ensure that explicitly-included params are in the request
|
||||
|
||||
if(op && op.parameters && op.parameters.length) {
|
||||
op.parameters
|
||||
.filter(param => param && param.allowEmptyValue === true)
|
||||
.forEach(param => {
|
||||
if (specSelectors.parameterInclusionSettingFor([pathName, method], param.name, param.in)) {
|
||||
req.parameters = req.parameters || {}
|
||||
const paramValue = req.parameters[param.name]
|
||||
|
||||
// if the value is falsy or an empty Immutable iterable...
|
||||
if(!paramValue || (paramValue && paramValue.size === 0)) {
|
||||
// set it to empty string, so Swagger Client will treat it as
|
||||
// present but empty.
|
||||
req.parameters[param.name] = ""
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// if url is relative, parseUrl makes it absolute by inferring from `window.location`
|
||||
req.contextUrl = parseUrl(specSelectors.url()).toString()
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
UPDATE_URL,
|
||||
UPDATE_JSON,
|
||||
UPDATE_PARAM,
|
||||
UPDATE_EMPTY_PARAM_INCLUSION,
|
||||
VALIDATE_PARAMS,
|
||||
SET_RESPONSE,
|
||||
SET_REQUEST,
|
||||
@@ -70,6 +71,22 @@ export default {
|
||||
)
|
||||
},
|
||||
|
||||
[UPDATE_EMPTY_PARAM_INCLUSION]: ( state, {payload} ) => {
|
||||
let { pathMethod, paramName, paramIn, includeEmptyValue } = payload
|
||||
|
||||
if(!paramName || !paramIn) {
|
||||
console.warn("Warning: UPDATE_EMPTY_PARAM_INCLUSION could not generate a paramKey.")
|
||||
return state
|
||||
}
|
||||
|
||||
const paramKey = `${paramName}.${paramIn}`
|
||||
|
||||
return state.setIn(
|
||||
["meta", "paths", ...pathMethod, "parameter_inclusions", paramKey],
|
||||
includeEmptyValue
|
||||
)
|
||||
},
|
||||
|
||||
[VALIDATE_PARAMS]: ( state, { payload: { pathMethod, isOAS3 } } ) => {
|
||||
let meta = state.getIn( [ "meta", "paths", ...pathMethod ], fromJS({}) )
|
||||
let isXml = /xml/i.test(meta.get("consumes_value"))
|
||||
|
||||
@@ -311,6 +311,11 @@ export const parameterWithMetaByIdentity = (state, pathMethod, param) => {
|
||||
return mergedParams.find(curr => curr.get("in") === param.get("in") && curr.get("name") === param.get("name"), OrderedMap())
|
||||
}
|
||||
|
||||
export const parameterInclusionSettingFor = (state, pathMethod, paramName, paramIn) => {
|
||||
const paramKey = `${paramName}.${paramIn}`
|
||||
return state.getIn(["meta", "paths", ...pathMethod, "parameter_inclusions", paramKey], false)
|
||||
}
|
||||
|
||||
|
||||
export const parameterWithMeta = (state, pathMethod, paramName, paramIn) => {
|
||||
const opParams = specJsonWithResolvedSubtrees(state).getIn(["paths", ...pathMethod, "parameters"], OrderedMap())
|
||||
|
||||
Reference in New Issue
Block a user