fix(oas3): expand Callback operation without browser error (#8509)
Refs #8508
This commit is contained in:
@@ -9,16 +9,19 @@ import { stringify } from "../../utils"
|
|||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
|
|
||||||
function onlyOAS3(selector) {
|
const onlyOAS3 =
|
||||||
return (...args) =>
|
(selector) =>
|
||||||
|
(state, ...args) =>
|
||||||
(system) => {
|
(system) => {
|
||||||
if (system.getSystem().specSelectors.isOAS3()) {
|
if (system.getSystem().specSelectors.isOAS3()) {
|
||||||
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) =>
|
return (...args) =>
|
||||||
@@ -98,13 +101,28 @@ export const selectDefaultRequestBodyValue =
|
|||||||
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
|
||||||
|
|
||||||
if (specSelectors.isOAS3()) {
|
|
||||||
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 = stringify(
|
||||||
@@ -118,14 +136,10 @@ export const hasUserEditedBody = (state, path, method) => (system) => {
|
|||||||
if (List.isList(userEditedRequestBody)) {
|
if (List.isList(userEditedRequestBody)) {
|
||||||
userEditedRequestBody = stringify(userEditedRequestBody)
|
userEditedRequestBody = stringify(userEditedRequestBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentMediaType) {
|
if (currentMediaType) {
|
||||||
const currentMediaTypeDefaultBodyValue = getDefaultRequestBodyValue(
|
const currentMediaTypeDefaultBodyValue = getDefaultRequestBodyValue(
|
||||||
specSelectors.specResolvedSubtree([
|
requestBody,
|
||||||
"paths",
|
|
||||||
path,
|
|
||||||
method,
|
|
||||||
"requestBody",
|
|
||||||
]),
|
|
||||||
currentMediaType,
|
currentMediaType,
|
||||||
oas3Selectors.activeExamplesMember(
|
oas3Selectors.activeExamplesMember(
|
||||||
path,
|
path,
|
||||||
@@ -139,10 +153,7 @@ export const hasUserEditedBody = (state, path, method) => (system) => {
|
|||||||
userEditedRequestBody !== currentMediaTypeDefaultBodyValue
|
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()
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import {
|
|||||||
isOAS3 as isOAS3SelectorWrapper,
|
isOAS3 as isOAS3SelectorWrapper,
|
||||||
selectLicenseUrl as selectLicenseUrlWrapper,
|
selectLicenseUrl as selectLicenseUrlWrapper,
|
||||||
} from "./spec-extensions/wrap-selectors"
|
} from "./spec-extensions/wrap-selectors"
|
||||||
import { hasUserEditedBody as hasUserEditedBodySelectorWrapper } from "./oas3-extensions/wrap-selectors"
|
|
||||||
import { selectLicenseUrl as selectOAS31LicenseUrl } from "./selectors"
|
import { selectLicenseUrl as selectOAS31LicenseUrl } from "./selectors"
|
||||||
import {
|
import {
|
||||||
isOAS31 as isOAS31Fn,
|
isOAS31 as isOAS31Fn,
|
||||||
@@ -112,11 +111,6 @@ const OAS31Plugin = ({ fn }) => {
|
|||||||
selectLicenseUrl: selectLicenseUrlWrapper,
|
selectLicenseUrl: selectLicenseUrlWrapper,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
oas3: {
|
|
||||||
wrapSelectors: {
|
|
||||||
hasUserEditedBody: hasUserEditedBodySelectorWrapper,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
oas31: {
|
oas31: {
|
||||||
selectors: {
|
selectors: {
|
||||||
selectLicenseUrl: createOnlyOAS31Selector(createSystemSelector(selectOAS31LicenseUrl)), // prettier-ignore
|
selectLicenseUrl: createOnlyOAS31Selector(createSystemSelector(selectOAS31LicenseUrl)), // prettier-ignore
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
/**
|
|
||||||
* @prettier
|
|
||||||
*/
|
|
||||||
import { createOnlyOAS31SelectorWrapper } from "../fn"
|
|
||||||
|
|
||||||
export const hasUserEditedBody = createOnlyOAS31SelectorWrapper(
|
|
||||||
(state, path, method) => (oriSelector, system) => {
|
|
||||||
const webhooks = system.specSelectors.webhooks()
|
|
||||||
|
|
||||||
if (webhooks.hasIn([path, method])) {
|
|
||||||
// try it out functionality is disabled for webhooks
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return oriSelector(path, method)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user