refactor(oas31): disable try it out mechanism explicitly for webhooks (#8485)

Refs #8474
This commit is contained in:
Vladimír Gorej
2023-03-20 09:44:22 +01:00
committed by GitHub
parent d7099793a4
commit d837b2b511
5 changed files with 54 additions and 26 deletions

View File

@@ -6,13 +6,13 @@ import { getCommonExtensions, getSampleSchema, stringify, isEmptyValue } from "c
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey) => {
const mediaTypeValue = requestBody?.getIn(["content", mediaType])
const schema = mediaTypeValue?.get("schema").toJS()
const mediaTypeValue = requestBody.getIn(["content", mediaType])
const schema = mediaTypeValue.get("schema").toJS()
const hasExamplesKey = mediaTypeValue?.get("examples") !== undefined
const exampleSchema = mediaTypeValue?.get("example")
const hasExamplesKey = mediaTypeValue.get("examples") !== undefined
const exampleSchema = mediaTypeValue.get("example")
const mediaTypeExample = hasExamplesKey
? mediaTypeValue?.getIn([
? mediaTypeValue.getIn([
"examples",
activeExamplesKey,
"value"

View File

@@ -11,7 +11,7 @@ export const isOAS31 = (jsSpec) => {
}
/**
* Creates selector that returns value of the original
* Creates selector that returns value of the passed
* selector when spec is OpenAPI 3.1.0., null otherwise.
*
* @param selector
@@ -31,6 +31,26 @@ export const createOnlyOAS31Selector =
}
}
/**
* Creates selector wrapper that returns value of the passed
* selector when spec is OpenAPI 3.1.0., calls original selector otherwise.
*
*
* @param selector
* @returns {function(*, *): function(*, ...[*]): (*)}
*/
export const createOnlyOAS31SelectorWrapper =
(selector) =>
(oriSelector, system) =>
(state, ...args) => {
if (system.getSystem().specSelectors.isOAS31()) {
const result = selector(state, ...args)
return typeof result === "function" ? result(system) : result
} else {
return oriSelector(...args)
}
}
/**
* Creates selector that provides system as the
* second argument. This allows to create memoized

View File

@@ -32,9 +32,10 @@ import {
selectWebhooksOperations,
} from "./spec-extensions/selectors"
import {
isOAS3 as isOAS3Wrapper,
isOAS3 as isOAS3SelectorWrapper,
selectLicenseUrl as selectLicenseUrlWrapper,
} from "./spec-extensions/wrap-selectors"
import { hasUserEditedBody as hasUserEditedBodySelectorWrapper } from "./oas3-extensions/wrap-selectors"
import { selectLicenseUrl as selectOAS31LicenseUrl } from "./selectors"
import {
isOAS31 as isOAS31Fn,
@@ -94,10 +95,15 @@ const OAS31Plugin = ({ fn }) => {
selectWebhooksOperations: createOnlyOAS31Selector(createSystemSelector(selectWebhooksOperations)), // prettier-ignore
},
wrapSelectors: {
isOAS3: isOAS3Wrapper,
isOAS3: isOAS3SelectorWrapper,
selectLicenseUrl: selectLicenseUrlWrapper,
},
},
oas3: {
wrapSelectors: {
hasUserEditedBody: hasUserEditedBodySelectorWrapper,
},
},
oas31: {
selectors: {
selectLicenseUrl: createOnlyOAS31Selector(createSystemSelector(selectOAS31LicenseUrl)), // prettier-ignore

View File

@@ -0,0 +1,14 @@
import { createOnlyOAS31SelectorWrapper } from "../fn"
export const hasUserEditedBody = createOnlyOAS31SelectorWrapper(
(state, path, method) => (system) => {
const webhooks = system.specSelectors.webhooks()
if (webhooks.hasIn([path, method])) {
// try it out functionality is disabled for webhooks
return false
}
return system.oas3Selectors.hasUserEditedBody([path, method])
}
)

View File

@@ -2,21 +2,7 @@
* @prettier
*/
/**
* Selector wrapper maker the only wraps the passed selector
* when spec is of OpenAPI 3.1.0 version.
*/
const onlyOAS31Wrap =
(selector) =>
(oriSelector, system) =>
(state, ...args) => {
if (system.getSystem().specSelectors.isOAS31()) {
const result = selector(state, ...args)
return typeof result === "function" ? result(system) : result
} else {
return oriSelector(...args)
}
}
import { createOnlyOAS31SelectorWrapper } from "../fn"
export const isOAS3 =
(oriSelector, system) =>
@@ -25,6 +11,8 @@ export const isOAS3 =
return isOAS31 || oriSelector(...args)
}
export const selectLicenseUrl = onlyOAS31Wrap(() => (system) => {
return system.oas31Selectors.selectLicenseUrl()
})
export const selectLicenseUrl = createOnlyOAS31SelectorWrapper(
() => (system) => {
return system.oas31Selectors.selectLicenseUrl()
}
)