diff --git a/packages/react-openapi/src/OpenAPIOperation.tsx b/packages/react-openapi/src/OpenAPIOperation.tsx index f91cdc339..493341b59 100644 --- a/packages/react-openapi/src/OpenAPIOperation.tsx +++ b/packages/react-openapi/src/OpenAPIOperation.tsx @@ -12,10 +12,11 @@ import { Markdown } from './Markdown'; * Display an interactive OpenAPI operation. */ export function OpenAPIOperation(props: { + className?: string; data: OpenAPIOperationData; context: OpenAPIContextProps; }) { - const { data, context } = props; + const { className, data, context } = props; const { operation, servers, method, path } = data; const clientContext: OpenAPIClientContext = { @@ -24,7 +25,7 @@ export function OpenAPIOperation(props: { }; return ( -
+

{operation.summary}

{operation.description ? ( diff --git a/src/components/DocumentView/OpenAPI/OpenAPI.tsx b/src/components/DocumentView/OpenAPI/OpenAPI.tsx index 0bd1bab53..d4b99d64a 100644 --- a/src/components/DocumentView/OpenAPI/OpenAPI.tsx +++ b/src/components/DocumentView/OpenAPI/OpenAPI.tsx @@ -50,13 +50,18 @@ async function OpenAPIBody(props: BlockProps) { CodeBlock: PlainCodeBlock, defaultInteractiveOpened: context.mode === 'print', }} + className="openapi-block" /> ); } function OpenAPIFallback() { return ( -
+
diff --git a/src/lib/document.ts b/src/lib/document.ts index 8b2613acb..05c36da1d 100644 --- a/src/lib/document.ts +++ b/src/lib/document.ts @@ -21,20 +21,17 @@ export interface DocumentSection { /** * Check if the document contains one block that should be rendered in full-width mode. */ -export function hasFullWidthBlock(document: JSONDocument): { apiBlock: boolean } | false { - let fullWidth = false; - +export function hasFullWidthBlock(document: JSONDocument): boolean { for (const node of document.nodes) { if (node.data && 'fullWidth' in node.data && node.data.fullWidth) { - fullWidth = true; + return true; } - if (node.type === 'swagger') { - return { apiBlock: true }; + return true; } } - return fullWidth ? { apiBlock: false } : false; + return false; } /** diff --git a/src/lib/openapi.ts b/src/lib/openapi.ts index 365654b72..9c7cbf27a 100644 --- a/src/lib/openapi.ts +++ b/src/lib/openapi.ts @@ -67,14 +67,23 @@ const fetcher: OpenAPIFetcher = { // @ts-ignore if (data && data.swagger) { - // Convert Swagger 2.0 to OpenAPI 3.0 - // @ts-ignore - const result = (await swagger2openapi.convertObj(data, { - resolve: false, - resolveInternal: false, - })) as ConvertOutputOptions; + try { + // Convert Swagger 2.0 to OpenAPI 3.0 + // @ts-ignore + const result = (await swagger2openapi.convertObj(data, { + resolve: false, + resolveInternal: false, + laxDefaults: true, + laxurls: true, + lint: false, + prevalidate: false, + })) as ConvertOutputOptions; - data = result.openapi; + data = result.openapi; + } catch (error) { + console.warn('Failed to convert Swagger 2.0 to OpenAPI 3.0', error); + data = null; + } } return { diff --git a/tailwind.config.ts b/tailwind.config.ts index 2b6d23e58..3dce27cde 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -208,7 +208,7 @@ const config: Config = { /** * Variant when the page contains an OpenAPI block. */ - addVariant('page-api-block', 'body:has(.page-api-block) &'); + addVariant('page-api-block', 'body:has(.openapi-block) &'); /** * Variant when the page is displayed in print mode.