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 needswindow, so with server-side rendering import it on the client only. - Pass attributes as strings, as in HTML:
render-style="view",allow-try="false".
React and Next.js
Section titled “React and Next.js”Import RapiDoc in an effect, so it runs only in the browser. In the Next.js App Router, mark the file 'use client'.
'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
Section titled “TypeScript”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:
/// <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.
Vue and Nuxt
Section titled “Vue and Nuxt”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-'), }, }, }), ],});export default defineNuxtConfig({ vue: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('rapi-'), }, },});For attribute checking in templates (with Volar), add the types once, for example in src/rapidoc.d.ts:
/// <reference types="rapidoc/vue" />Then import RapiDoc when the component mounts:
<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>Angular
Section titled “Angular”Add CUSTOM_ELEMENTS_SCHEMA to the component (or its module) and import RapiDoc:
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.
Svelte, Astro and plain bundlers
Section titled “Svelte, Astro and plain bundlers”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.