refactor(oas31): disable try it out mechanism explicitly for webhooks (#8485)
Refs #8474
This commit is contained in:
@@ -6,13 +6,13 @@ import { getCommonExtensions, getSampleSchema, stringify, isEmptyValue } from "c
|
|||||||
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
|
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
|
||||||
|
|
||||||
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey) => {
|
export const getDefaultRequestBodyValue = (requestBody, mediaType, activeExamplesKey) => {
|
||||||
const mediaTypeValue = requestBody?.getIn(["content", mediaType])
|
const mediaTypeValue = requestBody.getIn(["content", mediaType])
|
||||||
const schema = mediaTypeValue?.get("schema").toJS()
|
const schema = mediaTypeValue.get("schema").toJS()
|
||||||
|
|
||||||
const hasExamplesKey = mediaTypeValue?.get("examples") !== undefined
|
const hasExamplesKey = mediaTypeValue.get("examples") !== undefined
|
||||||
const exampleSchema = mediaTypeValue?.get("example")
|
const exampleSchema = mediaTypeValue.get("example")
|
||||||
const mediaTypeExample = hasExamplesKey
|
const mediaTypeExample = hasExamplesKey
|
||||||
? mediaTypeValue?.getIn([
|
? mediaTypeValue.getIn([
|
||||||
"examples",
|
"examples",
|
||||||
activeExamplesKey,
|
activeExamplesKey,
|
||||||
"value"
|
"value"
|
||||||
|
|||||||
@@ -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.
|
* selector when spec is OpenAPI 3.1.0., null otherwise.
|
||||||
*
|
*
|
||||||
* @param selector
|
* @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
|
* Creates selector that provides system as the
|
||||||
* second argument. This allows to create memoized
|
* second argument. This allows to create memoized
|
||||||
|
|||||||
@@ -32,9 +32,10 @@ import {
|
|||||||
selectWebhooksOperations,
|
selectWebhooksOperations,
|
||||||
} from "./spec-extensions/selectors"
|
} from "./spec-extensions/selectors"
|
||||||
import {
|
import {
|
||||||
isOAS3 as isOAS3Wrapper,
|
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,
|
||||||
@@ -94,10 +95,15 @@ const OAS31Plugin = ({ fn }) => {
|
|||||||
selectWebhooksOperations: createOnlyOAS31Selector(createSystemSelector(selectWebhooksOperations)), // prettier-ignore
|
selectWebhooksOperations: createOnlyOAS31Selector(createSystemSelector(selectWebhooksOperations)), // prettier-ignore
|
||||||
},
|
},
|
||||||
wrapSelectors: {
|
wrapSelectors: {
|
||||||
isOAS3: isOAS3Wrapper,
|
isOAS3: isOAS3SelectorWrapper,
|
||||||
selectLicenseUrl: selectLicenseUrlWrapper,
|
selectLicenseUrl: selectLicenseUrlWrapper,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
oas3: {
|
||||||
|
wrapSelectors: {
|
||||||
|
hasUserEditedBody: hasUserEditedBodySelectorWrapper,
|
||||||
|
},
|
||||||
|
},
|
||||||
oas31: {
|
oas31: {
|
||||||
selectors: {
|
selectors: {
|
||||||
selectLicenseUrl: createOnlyOAS31Selector(createSystemSelector(selectOAS31LicenseUrl)), // prettier-ignore
|
selectLicenseUrl: createOnlyOAS31Selector(createSystemSelector(selectOAS31LicenseUrl)), // prettier-ignore
|
||||||
|
|||||||
14
src/core/plugins/oas31/oas3-extensions/wrap-selectors.js
Normal file
14
src/core/plugins/oas31/oas3-extensions/wrap-selectors.js
Normal 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])
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -2,21 +2,7 @@
|
|||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
import { createOnlyOAS31SelectorWrapper } from "../fn"
|
||||||
* 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isOAS3 =
|
export const isOAS3 =
|
||||||
(oriSelector, system) =>
|
(oriSelector, system) =>
|
||||||
@@ -25,6 +11,8 @@ export const isOAS3 =
|
|||||||
return isOAS31 || oriSelector(...args)
|
return isOAS31 || oriSelector(...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const selectLicenseUrl = onlyOAS31Wrap(() => (system) => {
|
export const selectLicenseUrl = createOnlyOAS31SelectorWrapper(
|
||||||
|
() => (system) => {
|
||||||
return system.oas31Selectors.selectLicenseUrl()
|
return system.oas31Selectors.selectLicenseUrl()
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user