Skip to content

Front-End Frameworks

<rapi-doc> is a standard custom element, so it works in any framework without a wrapper. Two rules apply everywhere:

  • Register it in the browser. import 'rapidoc' defines the element and needs window, so with server-side rendering import it on the client only.
  • Pass attributes as strings, as in HTML: render-style="view", allow-try="false".

Import RapiDoc in an effect, so it runs only in the browser. In the Next.js App Router, mark the file 'use client'.

ApiDocs.tsx
'use client';
import { useEffect } from 'react';
export default function ApiDocs() {
useEffect(() => {
import('rapidoc');
}, []);
return (
<rapi-doc
spec-url="https://petstore.swagger.io/v2/swagger.json"
render-style="view"
show-header="false"
style={{ height: '100vh' }}
/>
);
}

The element renders once it is defined; until then the browser shows it as an empty box.

TypeScript doesn’t know <rapi-doc> and reports Property 'rapi-doc' does not exist on type 'JSX.IntrinsicElements'. rapidoc ships the types; reference them once, for example in src/rapidoc.d.ts:

src/rapidoc.d.ts
/// <reference types="rapidoc/react" />

Every attribute is then checked and completed in JSX: render-style="nope" is an error. For a typed ref, import the element’s type:

import type { RapiDocElement } from 'rapidoc';
const ref = useRef<RapiDocElement>(null);
// ref.current?.loadSpec('/openapi.json');

The types need rapidoc 12.2 or later. <rapi-doc-mini> and <rapi-flow> are typed from 12.2.1.

Tell the Vue compiler that tags starting with rapi- are custom elements, not missing Vue components:

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag) => tag.startsWith('rapi-'),
},
},
}),
],
});

For attribute checking in templates (with Volar), add the types once, for example in src/rapidoc.d.ts:

src/rapidoc.d.ts
/// <reference types="rapidoc/vue" />

Then import RapiDoc when the component mounts:

ApiDocs.vue
<script setup>
import { onMounted } from 'vue';
onMounted(() => import('rapidoc'));
</script>
<template>
<rapi-doc
spec-url="https://petstore.swagger.io/v2/swagger.json"
render-style="focused"
style="height: 100vh"
></rapi-doc>
</template>

Add CUSTOM_ELEMENTS_SCHEMA to the component (or its module) and import RapiDoc:

api-docs.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import 'rapidoc';
@Component({
selector: 'app-api-docs',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<rapi-doc
spec-url="https://petstore.swagger.io/v2/swagger.json"
render-style="view"
style="height: 100vh"
></rapi-doc>
`,
})
export class ApiDocsComponent {}

With Angular SSR, move the import into afterNextRender so it runs in the browser only.

No configuration is needed. Import rapidoc in a client-side script and use the element in your markup. In Astro, a <script>import 'rapidoc';</script> tag in the page is enough.