
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
rollup-plugin-openapi
Advanced tools
A Rollup and Vite plugin which converts OpenAPI YAML files to ES6 modules.
A Rollup and Vite plugin which converts OpenAPI YAML files to ES6 modules.
💡 The plugin works with $ref references in your YAML files!
Using npm:
npm install rollup-plugin-openapi --save-dev
Create a rollup.config.js
configuration file and
import the plugin:
import openapi from "rollup-plugin-openapi";
export default {
input: "src/index.js",
output: {
dir: "output",
format: "cjs",
},
plugins: [openapi()],
};
Then call rollup either via the
CLI or the
API.
Create a vite.config.js
configuration file and import the
plugin:
import openapi from "rollup-plugin-openapi";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [openapi()],
});
Then call vite either via the
CLI or the
API.
With an accompanying file src/index.js, the local src/api.yaml file would
now be importable as seen below:
src/api.yaml
openapi: '3.0.0'
info:
title: My great API
description: Great description
version: '1.0.0'
paths:
/my/path:
get:
summary: Some GET request
responses:
'200':
description: Some response
content:
application/json:
schema:
type: object
properties:
someKey:
type: string
example:
someKey: some value
src/index.js
import api from "./api.yaml";
console.log(api);
If you have SwaggerUI in the React flavor installed you can now render it. With Vite you get Hot Module Reload for free.
src/index.jsx
import React from "react";
import ReactDOM from "react-dom";
import SwaggerUI from "swagger-ui-react";
import "swagger-ui-react/swagger-ui.css";
import api from "./api.yaml";
ReactDOM.render(<SwaggerUI spec={api} />, document.getElementById("root"));
If you use TypeScript you need to create a file like yaml.d.ts with the
following contents:
src/yaml.d.ts
/// <reference types="rollup-plugin-openapi/types/yaml" />
src/index.ts
import api from "./api.yaml";
console.log(api);
Otherwise TypeScript will fail with the error
Cannot find module './api.yaml' or its corresponding type declarations.
excludeType: String | Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
includeType: String | Array[...String]
Default: null
A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.
FAQs
A Rollup and Vite plugin which converts OpenAPI YAML files to ES6 modules.
We found that rollup-plugin-openapi demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.