fix(oas3): expand Callback operation without browser error (#8510)
Refs #7465
This commit is contained in:
@@ -5,16 +5,22 @@ import { stringify } from "../../utils"
|
||||
|
||||
// Helpers
|
||||
|
||||
function onlyOAS3(selector) {
|
||||
return (...args) => (system) => {
|
||||
const onlyOAS3 =
|
||||
(selector) =>
|
||||
(state, ...args) =>
|
||||
(system) => {
|
||||
const spec = system.getSystem().specSelectors.specJson()
|
||||
if(isOAS3Helper(spec)) {
|
||||
return selector(...args)
|
||||
|
||||
if (isOAS3Helper(spec)) {
|
||||
const selectedValue = selector(state, ...args)
|
||||
return typeof selectedValue === "function"
|
||||
? selectedValue(system)
|
||||
: selectedValue
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function validateRequestBodyIsRequired(selector) {
|
||||
return (...args) => (system) => {
|
||||
@@ -81,37 +87,50 @@ export const selectDefaultRequestBodyValue = (state, path, method) => (system) =
|
||||
return null
|
||||
}
|
||||
|
||||
export const hasUserEditedBody = (state, path, method) => (system) => {
|
||||
export const hasUserEditedBody = onlyOAS3((state, path, method) => (system) => {
|
||||
const {oas3Selectors, specSelectors} = system.getSystem()
|
||||
const spec = specSelectors.specJson()
|
||||
if(isOAS3Helper(spec)) {
|
||||
let userHasEditedBody = false
|
||||
const currentMediaType = oas3Selectors.requestContentType(path, method)
|
||||
let userEditedRequestBody = oas3Selectors.requestBodyValue(path, method)
|
||||
if (Map.isMap(userEditedRequestBody)) {
|
||||
// context is not application/json media-type
|
||||
userEditedRequestBody = stringify(userEditedRequestBody.mapEntries((kv) => Map.isMap(kv[1]) ? [kv[0], kv[1].get("value")] : kv).toJS())
|
||||
}
|
||||
if(List.isList(userEditedRequestBody)) {
|
||||
userEditedRequestBody = stringify(userEditedRequestBody)
|
||||
}
|
||||
if (currentMediaType) {
|
||||
const currentMediaTypeDefaultBodyValue = getDefaultRequestBodyValue(
|
||||
specSelectors.specResolvedSubtree(["paths", path, method, "requestBody"]),
|
||||
currentMediaType,
|
||||
oas3Selectors.activeExamplesMember(
|
||||
path, method,
|
||||
"requestBody",
|
||||
"requestBody",
|
||||
)
|
||||
)
|
||||
userHasEditedBody = !!userEditedRequestBody && userEditedRequestBody !== currentMediaTypeDefaultBodyValue
|
||||
}
|
||||
return userHasEditedBody
|
||||
} else {
|
||||
return null
|
||||
|
||||
let userHasEditedBody = false
|
||||
const currentMediaType = oas3Selectors.requestContentType(path, method)
|
||||
let userEditedRequestBody = oas3Selectors.requestBodyValue(path, method)
|
||||
const requestBody = specSelectors.specResolvedSubtree([
|
||||
"paths",
|
||||
path,
|
||||
method,
|
||||
"requestBody",
|
||||
])
|
||||
|
||||
/**
|
||||
* The only request body that can currently be edited is for Path Items that are direct values of OpenAPI.paths.
|
||||
* Path Item contained within the Callback Object or OpenAPI.webhooks (OpenAPI 3.1.0) have `Try it out`
|
||||
* disabled and thus body cannot be edited.
|
||||
*/
|
||||
if (!requestBody) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if (Map.isMap(userEditedRequestBody)) {
|
||||
// context is not application/json media-type
|
||||
userEditedRequestBody = stringify(userEditedRequestBody.mapEntries((kv) => Map.isMap(kv[1]) ? [kv[0], kv[1].get("value")] : kv).toJS())
|
||||
}
|
||||
if(List.isList(userEditedRequestBody)) {
|
||||
userEditedRequestBody = stringify(userEditedRequestBody)
|
||||
}
|
||||
if (currentMediaType) {
|
||||
const currentMediaTypeDefaultBodyValue = getDefaultRequestBodyValue(
|
||||
requestBody,
|
||||
currentMediaType,
|
||||
oas3Selectors.activeExamplesMember(
|
||||
path, method,
|
||||
"requestBody",
|
||||
"requestBody",
|
||||
)
|
||||
)
|
||||
userHasEditedBody = !!userEditedRequestBody && userEditedRequestBody !== currentMediaTypeDefaultBodyValue
|
||||
}
|
||||
return userHasEditedBody
|
||||
|
||||
})
|
||||
|
||||
export const requestBodyInclusionSetting = onlyOAS3((state, path, method) => {
|
||||
return state.getIn(["requestData", path, method, "bodyInclusion"]) || Map()
|
||||
|
||||
Reference in New Issue
Block a user