import Param from '~/components/Params' import RefSubLayout from '~/layouts/ref/RefSubLayout' import BodyContentTypeDropdown from '~/components/BodyContentTypeDropdown' import { useState } from 'react' import Options from '~/components/Options' import ApiBodyParam from '~/components/ApiBodyParam' import ApiSchema from '~/components/ApiSchema' const MgmtApiOperationSection = (props) => { const operation = props.spec.operations.find((x: any) => x.operationId === props.funcData.id) const bodyContentTypes = Object.keys(operation?.requestBody?.content ?? {}) const [selectedContentType, setSelectedContentType] = useState(bodyContentTypes[0] || undefined) const hasBodyArray = operation?.requestBody?.content[selectedContentType]?.schema?.type === 'array' const hasBodyArrayObject = operation?.requestBody?.content[selectedContentType]?.schema?.items?.type === 'object' // gracefully return nothing if function does not exist if (!operation) return <> const handleSelectType = (value: string) => { setSelectedContentType(value) } return (
{operation.operation} {operation.path}

{operation.description}

{/* Path Parameters */} {operation.parameters && operation.parameters.filter((parameter) => parameter.in === 'path').length > 0 && (
Path Parameters
    {operation.parameters && operation.parameters .filter((parameter: any) => parameter.in === 'path') .map((parameter: any, index: number) => ( ))}
)} {/* Query Parameters */} {operation.parameters && operation.parameters.filter((parameter) => parameter.in === 'query').length > 0 && (
Query Parameters
    {operation.parameters && operation.parameters .filter((parameter: any) => parameter.in === 'query') .map((parameter: any, index: number) => ( {parameter.schema.enum && ( {parameter.schema.enum.map((value) => { return })} )} {parameter.schema.items?.enum && ( {parameter.schema.items?.enum.map((value) => { return })} )} ))}
)} {/* Header Parameters */} {operation.parameters && operation.parameters.filter((parameter) => parameter.in === 'header').length > 0 && (
Header Parameters
    {operation.parameters && operation.parameters .filter((parameter: any) => parameter.in === 'header') .map((parameter: any, index) => ( ))}
)} {/* Body */} {operation.requestBody && (
Body
    {hasBodyArray ? (
    array of:
    {/*object array*/} {hasBodyArrayObject && operation?.requestBody?.content[selectedContentType]?.schema?.items ?.properties && Object.entries( operation?.requestBody?.content[selectedContentType]?.schema?.items ?.properties ).map(([key, value]) => ( ))} {/*primitive type array*/} {!hasBodyArrayObject && operation?.requestBody?.content[selectedContentType]?.schema?.items?.type && ( )}
    ) : ( operation?.requestBody?.content[selectedContentType]?.schema?.properties && Object.entries( operation?.requestBody?.content[selectedContentType]?.schema?.properties ).map(([key, value]) => ( )) )}
)}
{operation.responseList && operation.responseList.length > 0 && (
Response
{operation.responseList[0] && operation.responseList[0]?.content && operation.responseList[0]?.content['application/json'] ? ( ) : ( [No content] )}
)}
) } export default MgmtApiOperationSection