import { CodeBlock } from '@/components/CodeBlock'; import { Badge } from '@/components/docs/Badge'; import { CodeGroup } from '@/components/docs/CodeGroup'; import { Expandable } from '@/components/docs/Expandable'; import { PropertiesTable } from '@/components/docs/PropertiesTable'; import { operationParameterSections, operationSections, statusColor } from '@/lib/openapi'; import type { NormalizedOperation, SchemaNode } from '@/lib/types'; function FieldChildren({ node }: { node: SchemaNode }) { return ( <> {node.description} {node.enum && node.enum.length > 0 && (
Options:{' '} {node.enum.map((value, index) => ( {index > 0 && ', '} {value} ))}
)} ); } function schemaDetails(node: SchemaNode) { if (!node.children?.length) return undefined; return ( ); } function SchemaTable({ nodes }: { nodes: SchemaNode[] }) { return ( {nodes.map(node => ( ))} ); } /** Renders a schema tree: a root object's properties, or the node itself. */ function SchemaFields({ node }: { node: SchemaNode }) { const isUnion = node.type === 'oneOf' || node.type === 'anyOf'; return ( ); } function HighlightedCode({ language, title, html, source, lineCount, }: { language: string; title?: string; html?: string; source: string; lineCount?: number; }) { return ( {html ? ( // Highlighted at build time by the openapi generator; same markup as // the rehype-shiki pipeline produces for fenced code blocks. ) : ( {source} )} ); } export interface OpenApiOperationProps { operation: NormalizedOperation; } /** The generated reference for one API operation, rendered under the page body. */ export function OpenApiOperation({ operation }: OpenApiOperationProps) { const sections = new Map(operationSections(operation).map(entry => [entry.name, entry.id])); return (
{operationParameterSections(operation).map(({ location, name }) => (

{name}

{location === 'header' && operation.security.length > 0 && ( Authentication credentials, e.g. Bearer <token>. )} {operation.parameters[location].map(parameter => ( ))}
))} {operation.requestBody && (

Request body

{operation.requestBody.example && ( )}
)} {operation.responses.length > 0 && (

Responses

{operation.responses.map(response => (
{response.status} {response.description && ( {response.description} )}
{response.schema && } {response.example && ( )}
))}
)} {operation.samples.length > 0 && (

Code samples

{operation.samples.map(sample => ( ))}
)}
); }