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)) { if (isOAS3Helper(spec)) {
return selector(...args) 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,13 +87,28 @@ 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([
"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)) { if (Map.isMap(userEditedRequestBody)) {
// context is not application/json media-type // context is not application/json media-type
userEditedRequestBody = stringify(userEditedRequestBody.mapEntries((kv) => Map.isMap(kv[1]) ? [kv[0], kv[1].get("value")] : kv).toJS()) userEditedRequestBody = stringify(userEditedRequestBody.mapEntries((kv) => Map.isMap(kv[1]) ? [kv[0], kv[1].get("value")] : kv).toJS())
@@ -97,7 +118,7 @@ export const hasUserEditedBody = (state, path, method) => (system) => {
} }
if (currentMediaType) { if (currentMediaType) {
const currentMediaTypeDefaultBodyValue = getDefaultRequestBodyValue( const currentMediaTypeDefaultBodyValue = getDefaultRequestBodyValue(
specSelectors.specResolvedSubtree(["paths", path, method, "requestBody"]), requestBody,
currentMediaType, currentMediaType,
oas3Selectors.activeExamplesMember( oas3Selectors.activeExamplesMember(
path, method, path, method,
@@ -108,10 +129,8 @@ export const hasUserEditedBody = (state, path, method) => (system) => {
userHasEditedBody = !!userEditedRequestBody && userEditedRequestBody !== currentMediaTypeDefaultBodyValue userHasEditedBody = !!userEditedRequestBody && userEditedRequestBody !== currentMediaTypeDefaultBodyValue
} }
return userHasEditedBody return userHasEditedBody
} else {
return null })
}
}
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()