/* ============================================================================ * 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_SCHEMA, 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 ResponseSchemaComponent: React.FC = ({ title, body, style, }): any => { if ( body === undefined || body.content === undefined || Object.keys(body).length === 0 || Object.keys(body.content).length === 0 ) { return null; } // Get all MIME types, including vendor-specific const mimeTypes = Object.keys(body.content); if (mimeTypes && mimeTypes.length) { return ( {mimeTypes.map((mimeType: any) => { const mediaTypeObject = body.content?.[mimeType]; const responseExamples = mediaTypeObject?.examples; const responseExample = mediaTypeObject?.example; const firstBody = mediaTypeObject?.schema; if ( !firstBody || (firstBody.properties && Object.keys(firstBody.properties).length === 0) ) { return ( // @ts-ignore
{translate({ id: OPENAPI_SCHEMA.NO_SCHEMA, message: "No schema", })}
); } return ( // @ts-ignore {/* @ts-ignore */}
{title} {body.required === true && ( {translate({ id: OPENAPI_SCHEMA_ITEM.REQUIRED, message: "required", })} )} } >
{body.description && (
{body.description}
)}
{firstBody && ExampleFromSchema({ schema: firstBody, mimeType: mimeType, })} {responseExamples && ResponseExamples({ responseExamples, mimeType })} {responseExample && ResponseExample({ responseExample, mimeType })}
); })}
); } return undefined; }; const ResponseSchema: React.FC = (props) => { return ( }> {() => { return ; }} ); }; export default ResponseSchema;