fix(oas3): expand Callback operation without browser error (#8510)

Refs #7465
This commit is contained in:
Vladimír Gorej
2023-03-23 15:35:46 +01:00
committed by GitHub
parent b0ab561879
commit cb15dbb6e5

View File

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