/* ============================================================================ * Copyright (c) Palo Alto Networks * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * ========================================================================== */ import React from "react"; import BrowserOnly from "@docusaurus/BrowserOnly"; import { translate } from "@docusaurus/Translate"; import Details from "@theme/Details"; import Markdown from "@theme/Markdown"; import MimeTabs from "@theme/MimeTabs"; // Assume these components exist import { ExampleFromSchema, ResponseExample, ResponseExamples, } from "@theme/ResponseExamples"; import SchemaNode from "@theme/Schema"; import SchemaTabs from "@theme/SchemaTabs"; import SkeletonLoader from "@theme/SkeletonLoader"; import TabItem from "@theme/TabItem"; import { OPENAPI_REQUEST, OPENAPI_SCHEMA_ITEM } from "@theme/translationIds"; import type { MediaTypeObject } from "docusaurus-plugin-openapi-docs/src/openapi/types"; interface Props { style?: React.CSSProperties; title: string; body: { content?: { [key: string]: MediaTypeObject; }; description?: string; required?: string[] | boolean; }; } const RequestSchemaComponent: React.FC = ({ title, body, style }) => { if ( body === undefined || body.content === undefined || Object.keys(body).length === 0 || Object.keys(body.content).length === 0 ) { return null; } const mimeTypes = Object.keys(body.content); if (mimeTypes.length > 1) { return ( {mimeTypes.map((mimeType) => { const mediaTypeObject = body.content![mimeType]; const firstBody = mediaTypeObject?.schema; const requestExamples = mediaTypeObject?.examples; const requestExample = mediaTypeObject?.example; if ( firstBody === undefined || (firstBody.properties && Object.keys(firstBody.properties).length === 0) ) { return null; } return ( // @ts-ignore {/* @ts-ignore */}

{translate({ id: OPENAPI_REQUEST.BODY_TITLE, message: title, })} {body.required === true && ( {translate({ id: OPENAPI_SCHEMA_ITEM.REQUIRED, message: "required", })} )}

} >
{body.description && (
{body.description}
)}
{firstBody && !requestExample && !requestExamples && ExampleFromSchema({ schema: firstBody, mimeType: mimeType, })} {requestExamples && ResponseExamples({ responseExamples: requestExamples, mimeType, })} {requestExample && ResponseExample({ responseExample: requestExample, mimeType, })}
); })}
); } const randomFirstKey = mimeTypes[0]; const mediaTypeObject = body.content[randomFirstKey]; const firstBody = mediaTypeObject?.schema ?? body.content![randomFirstKey]; const requestExamples = mediaTypeObject?.examples; const requestExample = mediaTypeObject?.example; if (firstBody === undefined) { return null; } return ( {/* @ts-ignore */} {/* @ts-ignore */}

{translate({ id: OPENAPI_REQUEST.BODY_TITLE, message: title, })} {firstBody.type === "array" && ( array )} {body.required && ( {translate({ id: OPENAPI_SCHEMA_ITEM.REQUIRED, message: "required", })} )}

} >
{body.description && (
{body.description}
)}
{firstBody && !requestExample && !requestExamples && ExampleFromSchema({ schema: firstBody, mimeType: randomFirstKey, })} {requestExamples && ResponseExamples({ responseExamples: requestExamples, mimeType: randomFirstKey, })} {requestExample && ResponseExample({ responseExample: requestExample, mimeType: randomFirstKey, })}
); }; const RequestSchema: React.FC = (props) => { return ( }> {() => { return ; }} ); }; export default RequestSchema;