fix(oas31): render Callback operations only (#8507)
Before this fix, other Path Item fields were included into rendering of Operation Objects under a specific Callback Object. Refs #8504
This commit is contained in:
@@ -1,54 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import ImPropTypes from "react-immutable-proptypes"
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
import { fromJS } from "immutable"
|
|
||||||
|
|
||||||
const Callbacks = (props) => {
|
const Callbacks = ({ callbacks, specPath, specSelectors, getComponent }) => {
|
||||||
let { callbacks, getComponent, specPath } = props
|
const operationDTOs = specSelectors.callbacksOperations({
|
||||||
// const Markdown = getComponent("Markdown", true)
|
callbacks,
|
||||||
|
specPath,
|
||||||
|
})
|
||||||
|
const callbackNames = Object.keys(operationDTOs)
|
||||||
|
|
||||||
const OperationContainer = getComponent("OperationContainer", true)
|
const OperationContainer = getComponent("OperationContainer", true)
|
||||||
|
|
||||||
if(!callbacks) {
|
if (callbackNames.length === 0) return <span>No callbacks</span>
|
||||||
return <span>No callbacks</span>
|
|
||||||
}
|
|
||||||
|
|
||||||
let callbackElements = callbacks.entrySeq().map(([callbackName, callback]) => {
|
return (
|
||||||
return <div key={callbackName}>
|
<div>
|
||||||
<h2>{callbackName}</h2>
|
{callbackNames.map((callbackName) => (
|
||||||
{ callback.entrySeq().map(([pathItemName, pathItem]) => {
|
<div key={`${callbackName}`}>
|
||||||
if(pathItemName === "$$ref") {
|
<h2>{callbackName}</h2>
|
||||||
return null
|
|
||||||
}
|
{operationDTOs[callbackName].map((operationDTO) => (
|
||||||
return <div key={pathItemName}>
|
<OperationContainer
|
||||||
{ pathItem.entrySeq().map(([method, operation]) => {
|
key={`${callbackName}-${operationDTO.path}-${operationDTO.method}`}
|
||||||
if(method === "$$ref") {
|
op={operationDTO.operation}
|
||||||
return null
|
tag=""
|
||||||
}
|
method={operationDTO.method}
|
||||||
let op = fromJS({
|
path={operationDTO.path}
|
||||||
operation
|
specPath={operationDTO.specPath}
|
||||||
})
|
|
||||||
return <OperationContainer
|
|
||||||
{...props}
|
|
||||||
op={op}
|
|
||||||
key={method}
|
|
||||||
tag={""}
|
|
||||||
method={method}
|
|
||||||
path={pathItemName}
|
|
||||||
specPath={specPath.push(callbackName, pathItemName, method)}
|
|
||||||
allowTryItOut={false}
|
allowTryItOut={false}
|
||||||
/>
|
/>
|
||||||
}) }
|
))}
|
||||||
</div>
|
</div>
|
||||||
}) }
|
))}
|
||||||
</div>
|
</div>
|
||||||
})
|
)
|
||||||
return <div>
|
|
||||||
{callbackElements}
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Callbacks.propTypes = {
|
Callbacks.propTypes = {
|
||||||
getComponent: PropTypes.func.isRequired,
|
getComponent: PropTypes.func.isRequired,
|
||||||
|
specSelectors: PropTypes.shape({
|
||||||
|
callbacksOperations: PropTypes.func.isRequired,
|
||||||
|
}).isRequired,
|
||||||
callbacks: ImPropTypes.iterable.isRequired,
|
callbacks: ImPropTypes.iterable.isRequired,
|
||||||
specPath: ImPropTypes.list.isRequired,
|
specPath: ImPropTypes.list.isRequired,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { Map } from "immutable"
|
/**
|
||||||
import { isSwagger2 as isSwagger2Helper, isOAS30 as isOAS30Helper } from "../helpers"
|
* @prettier
|
||||||
|
*/
|
||||||
|
import { List, Map } from "immutable"
|
||||||
|
|
||||||
|
import {
|
||||||
|
isSwagger2 as isSwagger2Helper,
|
||||||
|
isOAS30 as isOAS30Helper,
|
||||||
|
} from "../helpers"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helpers
|
* Helpers
|
||||||
@@ -23,18 +29,54 @@ export const isOAS3 = () => (system) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onlyOAS3(selector) {
|
function onlyOAS3(selector) {
|
||||||
return () => (system, ...args) => {
|
return (state, ...args) =>
|
||||||
const spec = system.getSystem().specSelectors.specJson()
|
(system) => {
|
||||||
if(system.specSelectors.isOAS3(spec)) {
|
if (system.specSelectors.isOAS3()) {
|
||||||
const result = selector(...args)
|
const selectedValue = selector(state, ...args)
|
||||||
return typeof result === "function" ? result(system, ...args) : result
|
return typeof selectedValue === "function"
|
||||||
} else {
|
? selectedValue(system)
|
||||||
return null
|
: selectedValue
|
||||||
|
} else {
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const servers = onlyOAS3(() => (system) => {
|
export const servers = onlyOAS3(() => (system) => {
|
||||||
const spec = system.specSelectors.specJson()
|
const spec = system.specSelectors.specJson()
|
||||||
return spec.get("servers", map)
|
return spec.get("servers", map)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const callbacksOperations = onlyOAS3(
|
||||||
|
(state, { callbacks, specPath }) =>
|
||||||
|
(system) => {
|
||||||
|
const validOperationMethods = system.specSelectors.validOperationMethods()
|
||||||
|
|
||||||
|
if (!Map.isMap(callbacks)) return {}
|
||||||
|
|
||||||
|
return callbacks
|
||||||
|
.reduce((allOperations, callback, callbackName) => {
|
||||||
|
if (!Map.isMap(callback)) return allOperations
|
||||||
|
|
||||||
|
return callback.reduce((callbackOperations, pathItem, expression) => {
|
||||||
|
if (!Map.isMap(pathItem)) return callbackOperations
|
||||||
|
|
||||||
|
const pathItemOperations = pathItem
|
||||||
|
.entrySeq()
|
||||||
|
.filter(([key]) => validOperationMethods.includes(key))
|
||||||
|
.map(([method, operation]) => ({
|
||||||
|
operation: Map({ operation }),
|
||||||
|
method,
|
||||||
|
path: expression,
|
||||||
|
callbackName,
|
||||||
|
specPath: specPath.concat([callbackName, expression, method]),
|
||||||
|
}))
|
||||||
|
|
||||||
|
return callbackOperations.concat(pathItemOperations)
|
||||||
|
}, List())
|
||||||
|
}, List())
|
||||||
|
.groupBy((operationDTO) => operationDTO.callbackName)
|
||||||
|
.map((operations) => operations.toArray())
|
||||||
|
.toObject()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|||||||
@@ -27,9 +27,13 @@ export const selectWebhooksOperations = createSelector(
|
|||||||
(state, system) => system.specSelectors.webhooks(),
|
(state, system) => system.specSelectors.webhooks(),
|
||||||
(state, system) => system.specSelectors.validOperationMethods(),
|
(state, system) => system.specSelectors.validOperationMethods(),
|
||||||
(state, system) => system.specSelectors.specResolvedSubtree(["webhooks"]),
|
(state, system) => system.specSelectors.specResolvedSubtree(["webhooks"]),
|
||||||
(webhooks, validOperationMethods) =>
|
(webhooks, validOperationMethods) => {
|
||||||
webhooks
|
if (!Map.isMap(webhooks)) return {}
|
||||||
|
|
||||||
|
return webhooks
|
||||||
.reduce((allOperations, pathItem, pathItemName) => {
|
.reduce((allOperations, pathItem, pathItemName) => {
|
||||||
|
if (!Map.isMap(pathItem)) return allOperations
|
||||||
|
|
||||||
const pathItemOperations = pathItem
|
const pathItemOperations = pathItem
|
||||||
.entrySeq()
|
.entrySeq()
|
||||||
.filter(([key]) => validOperationMethods.includes(key))
|
.filter(([key]) => validOperationMethods.includes(key))
|
||||||
@@ -42,9 +46,10 @@ export const selectWebhooksOperations = createSelector(
|
|||||||
|
|
||||||
return allOperations.concat(pathItemOperations)
|
return allOperations.concat(pathItemOperations)
|
||||||
}, List())
|
}, List())
|
||||||
.groupBy((operation) => operation.path)
|
.groupBy((operationDTO) => operationDTO.path)
|
||||||
.map((operations) => operations.toArray())
|
.map((operations) => operations.toArray())
|
||||||
.toObject()
|
.toObject()
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
export const license = () => (system) => {
|
export const license = () => (system) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user