@zauni/rollup-plugin-openapi
raw JSON → 3.0.1 verified Mon Apr 27 auth: no javascript
Converts OpenAPI YAML files (OpenAPI 3.0, Swagger 2) into ES6 modules for Rollup and Vite. Version 3.0.1 ships TypeScript definitions, supports `$ref` resolution, and works with Vite's HMR. Different from general YAML loaders: it parses OpenAPI spec, validates, and produces structured code module. Requires Node >=18. Released on JSR as well. Actively maintained with frequent releases based on CI.
Common errors
error Error: Cannot find module 'rollup-plugin-openapi' ↓
cause Missing dev dependency or wrong import path.
fix
Run
npm install --save-dev rollup-plugin-openapi and ensure no typo in import. error TypeError: openapi is not a function ↓
cause Importing as named export instead of default.
fix
Use
import openapi from 'rollup-plugin-openapi' (no braces). error Cannot find module './api.yaml' or its corresponding type declarations. ↓
cause Missing TypeScript declaration for YAML imports.
fix
Create a .d.ts file with
/// <reference types="rollup-plugin-openapi/types/yaml" /> error The requested module 'rollup-plugin-openapi' does not provide an export named 'openapi' ↓
cause Using named import instead of default import.
fix
Remove braces:
import openapi from 'rollup-plugin-openapi' Warnings
breaking Node.js >=18 is required; older versions cause runtime errors. ↓
fix Upgrade Node.js to v18 or later.
gotcha TypeScript users must add a triple-slash reference for .yaml imports; otherwise TS fails with 'Cannot find module'. ↓
fix Create a .d.ts file with `/// <reference types="rollup-plugin-openapi/types/yaml" />`
deprecated The JSR package @zauni/rollup-plugin-openapi is available alongside npm; prefer npm for broader compatibility. ↓
fix Use `npm install rollup-plugin-openapi` instead of jsr install.
gotcha Plugin only works with `$ref` that point to local files; remote $ref (HTTP) are not supported and silently fail. ↓
fix Inline remote references or download them locally before build.
Install
npm install rollup-plugin-openapi yarn add rollup-plugin-openapi pnpm add rollup-plugin-openapi Imports
- openapi (default) wrong
import { openapi } from 'rollup-plugin-openapi'correctimport openapi from 'rollup-plugin-openapi' - openapi (CommonJS) wrong
const { openapi } = require('rollup-plugin-openapi')correctconst openapi = require('rollup-plugin-openapi') - Type declaration for yaml files wrong
import './yaml.d.ts'correct/// <reference types="rollup-plugin-openapi/types/yaml" />
Quickstart
import openapi from 'rollup-plugin-openapi';
export default {
input: 'src/index.js',
output: {
dir: 'output',
format: 'esm',
},
plugins: [
openapi({
include: ['**/*.yaml', '**/*.yml'],
exclude: 'node_modules/**',
}),
],
};