Skip to main content

Usage

After installing @open-resource-discovery/metadata-renderer, import the React component and the bundled stylesheet.

Importing styles​

The stylesheet import is side-effecting and must appear once in your application — typically in your entry file alongside other global stylesheets:

import '@open-resource-discovery/metadata-renderer/styles';

Without this import the renderers will have no styling.

Basic usage​

MetadataRenderer auto-detects the format and dispatches to the right renderer. One import is all you need:

import { MetadataRenderer } from '@open-resource-discovery/metadata-renderer';
import '@open-resource-discovery/metadata-renderer/styles';

export function MyView({ file }: { file: string }) {
return <MetadataRenderer content={file} />;
}

All five formats (OpenAPI, CSN, AsyncAPI, A2A, MCP) are supported out of the box.

Props​

PropTypeRequiredDescription
contentstring✓Metadata document as a string (YAML or JSON).
renderersRendererMap—Map of format keys to renderer components. Defaults to all renderers. Pass an explicit subset to enable tree-shaking.
optionsMetadataRendererOptions—Behavioral options. See Options.
typeMetaType—Override auto-detection. One of 'openapi', 'csn', 'asyncapi', 'a2a', 'mcp'.
classNamestring—Extra CSS class on the renderer root. Pass 'dark' to activate dark mode.
themeRendererTheme—Custom CSS token overrides. See Theming.

Tree-shaking with individual renderers​

Because renderers is an explicit map you control, bundlers can statically see which renderer modules are imported and drop the rest. To render only A2A and OpenAPI documents:

import { MetadataRenderer } from '@open-resource-discovery/metadata-renderer';
import { OpenApiRenderer } from '@open-resource-discovery/metadata-renderer/openapi';
import { A2ARenderer } from '@open-resource-discovery/metadata-renderer/a2a';

<MetadataRenderer content={file} renderers={{ openapi: OpenApiRenderer, a2a: A2ARenderer }} />;

CSN, AsyncAPI, and MCP code is not included in the bundle at all.

Options​

Pass an options object to fine-tune behavior:

<MetadataRenderer
content={file}
renderers={renderers}
options={{
autoDetect: true,
fallback: 'error',
a2a: { showValidation: true, showConnection: false },
mcp: { showValidation: true },
csn: {/* CsnRendererConfig */},
asyncapi: {/* Partial<ConfigInterface> */},
}}
/>

MetadataRendererOptions​

OptionTypeDefaultDescription
autoDetectbooleantrueAuto-detect format from content when type is not set. When false, an explicit type prop is required; otherwise the fallback is shown.
fallback'error' | 'raw''error'What to render when the format cannot be handled (unknown, or no renderer registered). 'error' shows a styled message; 'raw' shows the content in a <pre> block.
customAttributesCustomAttributesOptions | falsedisabledCustom extension attribute renderers per protocol. Pass false to disable all custom attribute rendering. See Custom Attributes.
csnCsnRendererConfig—Passed through to CsnRenderer.
asyncapiPartial<ConfigInterface>—Passed through to AsyncApiRenderer.
a2a{ showValidation?: boolean; showConnection?: boolean }—Passed through to A2ARenderer.
mcp{ showValidation?: boolean }—Passed through to McpRenderer.

Individual renderer props​

Each renderer accepts content, className, and theme. Additional props:

RendererExtra props
OpenApiRenderercustomAttributes?: OpenApiCustomAttributesConfig[]
CsnRendererconfig?: CsnRendererConfig
AsyncApiRendererconfig?: Partial<ConfigInterface>
A2ARenderershowValidation?: boolean, showConnection?: boolean
McpRenderershowValidation?: boolean

Theming​

Pass a theme prop to override the default color tokens. Use the createTheme helper for a type-safe camelCase API:

import { MetadataRenderer, createTheme } from '@open-resource-discovery/metadata-renderer';
import { OpenApiRenderer } from '@open-resource-discovery/metadata-renderer/openapi';

const theme = createTheme({
primary: '#0098ff',
background: '#1e1e1e',
foreground: '#d4d4d4',
muted: '#2d2d30',
mutedForeground: '#969696',
border: '#3e3e42',
});

export function MyView({ file }: { file: string }) {
return <MetadataRenderer content={file} renderers={{ openapi: OpenApiRenderer }} theme={theme} />;
}

For dark mode, combine theme with className="dark":

<MetadataRenderer content={file} renderers={renderers} className="dark" theme={theme} />

createTheme accepts the following tokens (all optional):

TokenDescription
backgroundPage / panel background
foregroundDefault text color
primary / primaryForegroundBrand accent and its text
secondary / secondaryForegroundSecondary surfaces
muted / mutedForegroundSubdued surfaces and text
accent / accentForegroundHover / highlight surfaces
card / cardForegroundCard background and text
popover / popoverForegroundDropdown / popover background and text
destructive / destructiveForegroundDanger color
success / successForegroundSuccess color
warning / warningForegroundWarning color
borderBorder color
inputInput border color
ringFocus ring color
radiusBorder radius (px value as string, e.g. '8')

You can also provide raw --ord-* CSS custom properties directly as the RendererTheme type:

import type { RendererTheme } from '@open-resource-discovery/metadata-renderer';

const theme: RendererTheme = {
'--ord-primary': '#0098ff',
'--ord-background': '#1e1e1e',
};