Skip to content

unjs/openapi-renderer

Repository files navigation

openapi-renderer

npm version npm downloads bundle size install size

Simple OpenAPI spec to HTML renderer.

Note

This is a new project, so feel free to share your ideas and contribute. Contributions are more than welcome!

Supported Renderers

Usage

renderResponse

Using renderResponse(req, options), you can render UI into a standard Response object from an incoming Request.

Example: Using srvx (same code works with Node.js, Deno, and Bun)

import { serve } from "srvx";
import { renderResponse } from "openapi-renderer";

serve({
  fetch(req) {
    return renderResponse(req, {
      spec: "https://petstore.swagger.io/v2/swagger.json",
      allowCustomQuery: { spec: false, renderer: true },
    });
  },
});

renderHTML

Using renderHTML(options), you can render UI into an HTML string.

import { renderHTML } from "openapi-renderer";

const html = renderHTML({
  spec: "https://petstore.swagger.io/v2/swagger.json",
});

Options

  • renderer: Renderer UI. Possible values: "swagger" | "scalar" | "kong"
  • spec: URL to OpenAPI spec JSON to render
  • meta: Metadata for the OpenAPI documentation.
  • styles: Additional HTML styles.
  • scalar: Scalar UI configuration.
  • swagger: Swagger UI configuration.
  • kong: Kong Spec Renderer UI configuration.

Development

  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

💛 Published under the MIT license.

About

Simple OpenAPI spec to HTML renderer.

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •