import Collapsible from '../collapsible' import ResponseObject from '../response-object' import PropertyObject from '../property-object' import { capitalCase } from 'change-case' import useHover from '../../../../lib/hooks/use-hover' import SvgrChevronDown from '../chevron-down/black' import styles from './operation-object.module.css' function OperationObject({ data, path, type, isHighlighted, isCollapsed, setIsCollapsed, }) { const [headerRef, isHeaderHovered] = useHover() // const [isCollapsed, setIsCollapsed] = useState(true) const { operationId, parameters, responses, summary } = data const successResponse = responses['200'] const title = capitalCase(operationId.split('_').slice(1).join()) // Group parameter properties by type const pathParams = parameters.filter((p) => p.in === 'path') const queryParams = parameters.filter((p) => p.in === 'query') const bodyParam = parameters.filter((p) => p.in === 'body')[0] // Note: we only accept a single "in=body" param const bodyProps = bodyParam ? getBodyParamProps(bodyParam) : [] return (
setIsCollapsed(!isCollapsed)} >
{title}
{type.toUpperCase()}{' '} {path}
{isCollapsed ? 'Expand' : 'Collapse'}

{summary}

Request

{pathParams.length > 0 ? ( ) : null} {queryParams.length > 0 ? ( ) : null} {bodyProps.length > 0 ? ( ) : null}
} columnTwo={

Response

{!!successResponse ? (

Successful Response

) : (

No response has been defined.

)}
} />
) } function getBodyParamProps(bodyParam) { // We always expect the bodyParam to be an object, // with a schema which defines the body properties. if (!bodyParam.schema || !bodyParam.schema.properties) return [] // We flatten these properties to avoid showing a // "collapsed object" UI under the "Body Parameters" section, // which would be a bit redundant and annoying to have to expand const bodyPropsObj = bodyParam.schema.properties const bodyProps = Object.keys(bodyPropsObj).reduce((acc, key) => { const data = Object.assign({}, bodyPropsObj[key]) // We need the property name. This is usually be handled by "key" in an object, // but we're flattening the object so we need to make sure it's there data.name = key if (!data.readOnly) acc.push(data) return acc }, []) return bodyProps } function TwoColumnLayout({ columnOne, columnTwo }) { return (
{columnOne}
{columnTwo}
) } function Parameters({ title, params }) { return (

{title}

{params.map((parameter, idx) => { return ( ) })}
) } export default OperationObject