@kubb/plugin-redoc 5.0.0-beta.4 → 5.0.0-beta.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,19 +1,16 @@
1
1
  <div align="center">
2
- <h1>Plugin Redoc</h1>
3
2
  <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
4
- <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
5
4
  </a>
6
5
 
7
6
  [![npm version][npm-version-src]][npm-version-href]
8
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
9
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
10
9
  [![License][license-src]][license-href]
11
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Node][node-src]][node-href]
12
11
 
13
12
  <h4>
14
- <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
15
- <span> · </span>
16
- <a href="https://kubb.dev/" target="_blank">Documentation</a>
13
+ <a href="https://kubb.dev/plugins/redoc" target="_blank">Documentation</a>
17
14
  <span> · </span>
18
15
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
19
16
  <span> · </span>
@@ -21,11 +18,31 @@
21
18
  </h4>
22
19
  </div>
23
20
 
24
- Create beautiful docs with Redoc.
21
+ <br />
22
+
23
+ # @kubb/plugin-redoc
24
+
25
+ ### Generate a ReDoc API reference from OpenAPI
26
+
27
+ `@kubb/plugin-redoc` generates a ReDoc API reference page from your OpenAPI specification. The output is a standalone HTML file you can host without a build step or server.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ bun add @kubb/plugin-redoc
33
+ # or
34
+ pnpm add @kubb/plugin-redoc
35
+ # or
36
+ npm install @kubb/plugin-redoc
37
+ ```
38
+
39
+ ## Documentation
40
+
41
+ See the [full documentation](https://kubb.dev/plugins/redoc) for configuration options and examples.
25
42
 
26
43
  ## Supporting Kubb
27
44
 
28
- Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
45
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
29
46
 
30
47
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
31
48
 
@@ -35,19 +52,19 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
35
52
  </a>
36
53
  </p>
37
54
 
55
+ ## License
56
+
57
+ [MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
58
+
38
59
  <!-- Badges -->
39
60
 
40
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
41
- [npm-version-href]: https://npmjs.com/package/@kubb/plugin-redoc
42
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
43
- [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-redoc
44
- [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
61
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
62
+ [npm-version-href]: https://npmx.dev/package/@kubb/plugin-redoc
63
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
64
+ [npm-downloads-href]: https://npmx.dev/package/@kubb/plugin-redoc
65
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
66
+ [stars-href]: https://github.com/kubb-labs/kubb
67
+ [license-src]: https://shieldcn.dev/npm/license/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc
45
68
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
46
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
47
- [build-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
48
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
49
- [minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
50
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
51
- [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
52
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
53
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
69
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
70
+ [node-href]: https://npmx.dev/package/@kubb/plugin-redoc
package/dist/index.cjs CHANGED
@@ -25,43 +25,49 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
  //#endregion
27
27
  let node_path = require("node:path");
28
- let node_path$1 = __toESM(node_path, 1);
29
- node_path = __toESM(node_path);
28
+ node_path = __toESM(node_path, 1);
30
29
  let _kubb_adapter_oas = require("@kubb/adapter-oas");
31
30
  let _kubb_core = require("@kubb/core");
32
- let node_fs = require("node:fs");
33
- node_fs = __toESM(node_fs);
34
- let node_url = require("node:url");
35
- let handlebars = require("handlebars");
36
- handlebars = __toESM(handlebars);
37
- //#region ../../internals/utils/src/string.ts
38
- /**
39
- * Strips the file extension from a path or file name.
40
- * Only removes the last `.ext` segment when the dot is not part of a directory name.
41
- *
42
- * @example
43
- * trimExtName('petStore.ts') // 'petStore'
44
- * trimExtName('/src/models/pet.ts') // '/src/models/pet'
45
- * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
46
- * trimExtName('noExtension') // 'noExtension'
47
- */
48
- function trimExtName(text) {
49
- const dotIndex = text.lastIndexOf(".");
50
- if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
51
- return text;
52
- }
53
- //#endregion
54
31
  //#region package.json
55
- var version = "5.0.0-beta.4";
32
+ var version = "5.0.0-beta.56";
56
33
  //#endregion
57
34
  //#region src/redoc.tsx
58
- const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
59
- const __dirname$1 = node_path.default.dirname(__filename$1);
60
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
61
- const templateFileName = node_path.default.join(__dirname$1, "../static/redoc.hbs");
62
- return handlebars.default.compile(node_fs.default.readFileSync(templateFileName).toString())({
63
- title: title || api.info.title || "ReDoc documentation",
64
- redocHTML: `
35
+ const htmlEscapes = {
36
+ "&": "&amp;",
37
+ "<": "&lt;",
38
+ ">": "&gt;",
39
+ "\"": "&quot;",
40
+ "'": "&#x27;",
41
+ "`": "&#x60;",
42
+ "=": "&#x3D;"
43
+ };
44
+ function escapeHtml(value) {
45
+ return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
46
+ }
47
+ /**
48
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
49
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
50
+ * the generated file works without further build steps.
51
+ */
52
+ async function getPageHTML(api, { title, disableGoogleFont } = {}) {
53
+ return `<html>
54
+
55
+ <head>
56
+ <meta charset='utf8' />
57
+ <title>${escapeHtml(title || api.info.title || "ReDoc documentation")}</title>
58
+ <!-- needed for adaptive design -->
59
+ <meta name='viewport' content='width=device-width, initial-scale=1' />
60
+ <style>
61
+ body {
62
+ padding: 0;
63
+ margin: 0;
64
+ }
65
+ </style>
66
+ ${disableGoogleFont ? "" : `<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />`}
67
+ </head>
68
+
69
+ <body>
70
+ ${`
65
71
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
66
72
  <div id="redoc-container"></div>
67
73
  <script>
@@ -70,16 +76,41 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
70
76
  "expandResponses": "200,400"
71
77
  }, document.getElementById('redoc-container'))
72
78
  <\/script>
73
- `,
74
- disableGoogleFont,
75
- templateOptions
76
- });
79
+ `}
80
+ </body>
81
+
82
+ </html>`;
77
83
  }
78
84
  //#endregion
79
85
  //#region src/plugin.ts
86
+ /**
87
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
88
+ * cross-plugin dependency references.
89
+ */
80
90
  const pluginRedocName = "plugin-redoc";
91
+ /**
92
+ * Generates a self-contained static HTML documentation page from your OpenAPI
93
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
94
+ * stay in lockstep with the spec the rest of your code is generated from.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import { defineConfig } from 'kubb'
99
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
100
+ *
101
+ * export default defineConfig({
102
+ * input: { path: './petStore.yaml' },
103
+ * output: { path: './src/gen' },
104
+ * plugins: [
105
+ * pluginRedoc({ output: { path: 'docs.html' } }),
106
+ * ],
107
+ * })
108
+ * ```
109
+ */
81
110
  const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
82
111
  const { output = { path: "docs.html" } } = options;
112
+ const extname = node_path.default.extname(output.path);
113
+ const name = extname ? output.path.slice(0, -extname.length) : output.path;
83
114
  return {
84
115
  name: pluginRedocName,
85
116
  version,
@@ -87,7 +118,7 @@ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
87
118
  hooks: { async "kubb:plugin:setup"(ctx) {
88
119
  ctx.setOptions({
89
120
  output,
90
- name: trimExtName(output.path),
121
+ name,
91
122
  exclude: [],
92
123
  override: []
93
124
  });
@@ -95,11 +126,11 @@ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
95
126
  if (adapter?.name !== _kubb_adapter_oas.adapterOasName) throw new Error(`[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \`adapter: adapterOas()\`) in your Kubb config.`);
96
127
  const document = adapter.document;
97
128
  if (!document) throw new Error(`[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`);
98
- const root = node_path$1.default.resolve(ctx.config.root, ctx.config.output.path);
129
+ const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
99
130
  const pageHTML = await getPageHTML(document);
100
131
  ctx.injectFile({
101
132
  baseName: "docs.html",
102
- path: node_path$1.default.resolve(root, output.path || "./docs.html"),
133
+ path: node_path.default.resolve(root, output.path || "./docs.html"),
103
134
  sources: [_kubb_core.ast.createSource({
104
135
  name: "docs.html",
105
136
  nodes: [_kubb_core.ast.createText(pageHTML)]
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__filename","__dirname","path","pkg","fs","adapterOasName","path","ast"],"sources":["../../../internals/utils/src/string.ts","../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,IAAI;AACtC,KAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,CAC/C,QAAO,KAAK,MAAM,GAAG,SAAS;AAEhC,QAAO;;;;;;;AE5DT,MAAMA,gBAAAA,GAAAA,SAAAA,eAAAA,QAAAA,MAAAA,CAAAA,cAAAA,WAAAA,CAAAA,KAA2C;AACjD,MAAMC,cAAYC,UAAAA,QAAK,QAAQF,aAAW;AAQ1C,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACnI,MAAM,mBAAmBE,UAAAA,QAAK,KAAKD,aAAW,sBAAsB;AAEpE,QADiBE,WAAAA,QAAI,QAAQC,QAAAA,QAAG,aAAa,iBAAiB,CAAC,UAAU,CAC1D,CAAC;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;;;;;;EAM3C;EACA;EACD,CAAC;;;;ACtBJ,MAAa,kBAAkB;AAE/B,MAAa,eAAA,GAAA,WAAA,eAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;AAC7B,OAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,KAAK;IAC9B,SAAS,EAAE;IACX,UAAU,EAAE;IACb,CAAC;GAEF,MAAM,UAAU,IAAI,OAAO;AAE3B,OAAI,SAAS,SAASC,kBAAAA,eACpB,OAAM,IAAI,MACR,IAAI,gBAAgB,uIACrB;GAGH,MAAM,WAAY,QAAgC;AAElD,OAAI,CAAC,SACH,OAAM,IAAI,MACR,IAAI,gBAAgB,yHACrB;GAGH,MAAM,OAAOC,YAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,WAAW,MAAM,YAAY,SAAS;AAE5C,OAAI,WAAW;IACb,UAAU;IACV,MAAMA,YAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACPC,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAW,SAAS,CAAC;KAClC,CAAC,CACH;IACF,CAAC;KAEL;EACF;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["path","adapterOasName","ast"],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nconst htmlEscapes: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#x27;',\n '`': '&#x60;',\n '=': '&#x3D;',\n}\n\nfunction escapeHtml(value: string) {\n return value.replace(/[&<>\"'`=]/g, (char) => htmlEscapes[char] ?? char)\n}\n\n/**\n * Renders a self-contained Redoc HTML page for an OpenAPI document. The page\n * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so\n * the generated file works without further build steps.\n */\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont }: BuildDocsOptions = {}) {\n const pageTitle = escapeHtml(title || api.info.title || 'ReDoc documentation')\n const googleFont = disableGoogleFont\n ? ''\n : `<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />`\n const redocHTML = `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `\n\n return `<html>\n\n <head>\n <meta charset='utf8' />\n <title>${pageTitle}</title>\n <!-- needed for adaptive design -->\n <meta name='viewport' content='width=device-width, initial-scale=1' />\n <style>\n body {\n padding: 0;\n margin: 0;\n }\n </style>\n ${googleFont}\n </head>\n\n <body>\n ${redocHTML}\n </body>\n\n</html>`\n}\n","import path from 'node:path'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\n/**\n * Generates a self-contained static HTML documentation page from your OpenAPI\n * spec using Redoc. The file is regenerated on every Kubb build, so the docs\n * stay in lockstep with the spec the rest of your code is generated from.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginRedoc({ output: { path: 'docs.html' } }),\n * ],\n * })\n * ```\n */\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n const extname = path.extname(output.path)\n const name = extname ? output.path.slice(0, -extname.length) : output.path\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name,\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACQA,MAAM,cAAsC;CAC1C,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACP;AAEA,SAAS,WAAW,OAAe;CACjC,OAAO,MAAM,QAAQ,eAAe,SAAS,YAAY,SAAS,IAAI;AACxE;;;;;;AAOA,eAAsB,YAAY,KAA6B,EAAE,OAAO,sBAAwC,CAAC,GAAG;CAgBlH,OAAO;;;;aAfW,WAAW,SAAS,IAAI,KAAK,SAAS,qBAmBrC,EAAE;;;;;;;;;MAlBF,oBACf,KACA,qHAyBW;;;;MAIX;;;;kBAxBY,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;MAwB/B;;;;AAIhB;;;;;;;ACnDA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,eAAA,GAAA,WAAA,aAAA,EAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAC3C,MAAM,UAAUA,UAAAA,QAAK,QAAQ,OAAO,IAAI;CACxC,MAAM,OAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAI,OAAO;CAEtE,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA;IACA,SAAS,CAAC;IACV,UAAU,CAAC;GACb,CAAC;GAED,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAASC,kBAAAA,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;GAGF,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;GAGF,MAAM,OAAOD,UAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,WAAW,MAAM,YAAY,QAAQ;GAE3C,IAAI,WAAW;IACb,UAAU;IACV,MAAMA,UAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACPE,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAW,QAAQ,CAAC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,16 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _$_kubb_core0 from "@kubb/core";
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
3
2
  import { Exclude, Include, Output, Override, PluginFactoryOptions } from "@kubb/core";
4
3
 
5
4
  //#region src/types.d.ts
6
5
  type Options = {
6
+ /**
7
+ * Output location of the generated Redoc HTML file. The path is resolved
8
+ * against the global `output.path` set on `defineConfig`.
9
+ */
7
10
  output?: {
8
11
  /**
9
- * Output path for the generated HTML documentation.
12
+ * File path of the generated HTML, relative to the global `output.path`.
13
+ * Unlike most plugins, this points at a single file rather than a directory.
10
14
  *
11
15
  * @default 'docs.html'
12
16
  */
@@ -30,8 +34,31 @@ declare global {
30
34
  }
31
35
  //#endregion
32
36
  //#region src/plugin.d.ts
37
+ /**
38
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
39
+ * cross-plugin dependency references.
40
+ */
33
41
  declare const pluginRedocName = "plugin-redoc";
34
- declare const pluginRedoc: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginRedoc>;
42
+ /**
43
+ * Generates a self-contained static HTML documentation page from your OpenAPI
44
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
45
+ * stay in lockstep with the spec the rest of your code is generated from.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { defineConfig } from 'kubb'
50
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
51
+ *
52
+ * export default defineConfig({
53
+ * input: { path: './petStore.yaml' },
54
+ * output: { path: './src/gen' },
55
+ * plugins: [
56
+ * pluginRedoc({ output: { path: 'docs.html' } }),
57
+ * ],
58
+ * })
59
+ * ```
60
+ */
61
+ declare const pluginRedoc: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginRedoc>;
35
62
  //#endregion
36
63
  export { type PluginRedoc, pluginRedoc as default, pluginRedoc, pluginRedocName };
37
64
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,38 +1,47 @@
1
- import "./chunk--u3MIqq1.js";
1
+ import "./chunk-C0LytTxp.js";
2
2
  import path from "node:path";
3
3
  import { adapterOasName } from "@kubb/adapter-oas";
4
4
  import { ast, definePlugin } from "@kubb/core";
5
- import fs from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
- import pkg from "handlebars";
8
- //#region ../../internals/utils/src/string.ts
9
- /**
10
- * Strips the file extension from a path or file name.
11
- * Only removes the last `.ext` segment when the dot is not part of a directory name.
12
- *
13
- * @example
14
- * trimExtName('petStore.ts') // 'petStore'
15
- * trimExtName('/src/models/pet.ts') // '/src/models/pet'
16
- * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
17
- * trimExtName('noExtension') // 'noExtension'
18
- */
19
- function trimExtName(text) {
20
- const dotIndex = text.lastIndexOf(".");
21
- if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
22
- return text;
23
- }
24
- //#endregion
25
5
  //#region package.json
26
- var version = "5.0.0-beta.4";
6
+ var version = "5.0.0-beta.56";
27
7
  //#endregion
28
8
  //#region src/redoc.tsx
29
- const __filename = fileURLToPath(import.meta.url);
30
- const __dirname = path.dirname(__filename);
31
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
32
- const templateFileName = path.join(__dirname, "../static/redoc.hbs");
33
- return pkg.compile(fs.readFileSync(templateFileName).toString())({
34
- title: title || api.info.title || "ReDoc documentation",
35
- redocHTML: `
9
+ const htmlEscapes = {
10
+ "&": "&amp;",
11
+ "<": "&lt;",
12
+ ">": "&gt;",
13
+ "\"": "&quot;",
14
+ "'": "&#x27;",
15
+ "`": "&#x60;",
16
+ "=": "&#x3D;"
17
+ };
18
+ function escapeHtml(value) {
19
+ return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
20
+ }
21
+ /**
22
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
23
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
24
+ * the generated file works without further build steps.
25
+ */
26
+ async function getPageHTML(api, { title, disableGoogleFont } = {}) {
27
+ return `<html>
28
+
29
+ <head>
30
+ <meta charset='utf8' />
31
+ <title>${escapeHtml(title || api.info.title || "ReDoc documentation")}</title>
32
+ <!-- needed for adaptive design -->
33
+ <meta name='viewport' content='width=device-width, initial-scale=1' />
34
+ <style>
35
+ body {
36
+ padding: 0;
37
+ margin: 0;
38
+ }
39
+ </style>
40
+ ${disableGoogleFont ? "" : `<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />`}
41
+ </head>
42
+
43
+ <body>
44
+ ${`
36
45
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
37
46
  <div id="redoc-container"></div>
38
47
  <script>
@@ -41,16 +50,41 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
41
50
  "expandResponses": "200,400"
42
51
  }, document.getElementById('redoc-container'))
43
52
  <\/script>
44
- `,
45
- disableGoogleFont,
46
- templateOptions
47
- });
53
+ `}
54
+ </body>
55
+
56
+ </html>`;
48
57
  }
49
58
  //#endregion
50
59
  //#region src/plugin.ts
60
+ /**
61
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
62
+ * cross-plugin dependency references.
63
+ */
51
64
  const pluginRedocName = "plugin-redoc";
65
+ /**
66
+ * Generates a self-contained static HTML documentation page from your OpenAPI
67
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
68
+ * stay in lockstep with the spec the rest of your code is generated from.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { defineConfig } from 'kubb'
73
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
74
+ *
75
+ * export default defineConfig({
76
+ * input: { path: './petStore.yaml' },
77
+ * output: { path: './src/gen' },
78
+ * plugins: [
79
+ * pluginRedoc({ output: { path: 'docs.html' } }),
80
+ * ],
81
+ * })
82
+ * ```
83
+ */
52
84
  const pluginRedoc = definePlugin((options) => {
53
85
  const { output = { path: "docs.html" } } = options;
86
+ const extname = path.extname(output.path);
87
+ const name = extname ? output.path.slice(0, -extname.length) : output.path;
54
88
  return {
55
89
  name: pluginRedocName,
56
90
  version,
@@ -58,7 +92,7 @@ const pluginRedoc = definePlugin((options) => {
58
92
  hooks: { async "kubb:plugin:setup"(ctx) {
59
93
  ctx.setOptions({
60
94
  output,
61
- name: trimExtName(output.path),
95
+ name,
62
96
  exclude: [],
63
97
  override: []
64
98
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/string.ts","../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","","import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\nconst __filename = fileURLToPath(import.meta.url)\nconst __dirname = path.dirname(__filename)\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6DA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,IAAI;AACtC,KAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,CAC/C,QAAO,KAAK,MAAM,GAAG,SAAS;AAEhC,QAAO;;;;;;;AE5DT,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AACjD,MAAM,YAAY,KAAK,QAAQ,WAAW;AAQ1C,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACnI,MAAM,mBAAmB,KAAK,KAAK,WAAW,sBAAsB;AAEpE,QADiB,IAAI,QAAQ,GAAG,aAAa,iBAAiB,CAAC,UAAU,CAC1D,CAAC;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;;;;;;EAM3C;EACA;EACD,CAAC;;;;ACtBJ,MAAa,kBAAkB;AAE/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;AAC7B,OAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,KAAK;IAC9B,SAAS,EAAE;IACX,UAAU,EAAE;IACb,CAAC;GAEF,MAAM,UAAU,IAAI,OAAO;AAE3B,OAAI,SAAS,SAAS,eACpB,OAAM,IAAI,MACR,IAAI,gBAAgB,uIACrB;GAGH,MAAM,WAAY,QAAgC;AAElD,OAAI,CAAC,SACH,OAAM,IAAI,MACR,IAAI,gBAAgB,yHACrB;GAGH,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,WAAW,MAAM,YAAY,SAAS;AAE5C,OAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAW,SAAS,CAAC;KAClC,CAAC,CACH;IACF,CAAC;KAEL;EACF;EACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nconst htmlEscapes: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#x27;',\n '`': '&#x60;',\n '=': '&#x3D;',\n}\n\nfunction escapeHtml(value: string) {\n return value.replace(/[&<>\"'`=]/g, (char) => htmlEscapes[char] ?? char)\n}\n\n/**\n * Renders a self-contained Redoc HTML page for an OpenAPI document. The page\n * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so\n * the generated file works without further build steps.\n */\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont }: BuildDocsOptions = {}) {\n const pageTitle = escapeHtml(title || api.info.title || 'ReDoc documentation')\n const googleFont = disableGoogleFont\n ? ''\n : `<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />`\n const redocHTML = `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `\n\n return `<html>\n\n <head>\n <meta charset='utf8' />\n <title>${pageTitle}</title>\n <!-- needed for adaptive design -->\n <meta name='viewport' content='width=device-width, initial-scale=1' />\n <style>\n body {\n padding: 0;\n margin: 0;\n }\n </style>\n ${googleFont}\n </head>\n\n <body>\n ${redocHTML}\n </body>\n\n</html>`\n}\n","import path from 'node:path'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\n/**\n * Generates a self-contained static HTML documentation page from your OpenAPI\n * spec using Redoc. The file is regenerated on every Kubb build, so the docs\n * stay in lockstep with the spec the rest of your code is generated from.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginRedoc({ output: { path: 'docs.html' } }),\n * ],\n * })\n * ```\n */\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n const extname = path.extname(output.path)\n const name = extname ? output.path.slice(0, -extname.length) : output.path\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name,\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;ACQA,MAAM,cAAsC;CAC1C,KAAK;CACL,KAAK;CACL,KAAK;CACL,MAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACP;AAEA,SAAS,WAAW,OAAe;CACjC,OAAO,MAAM,QAAQ,eAAe,SAAS,YAAY,SAAS,IAAI;AACxE;;;;;;AAOA,eAAsB,YAAY,KAA6B,EAAE,OAAO,sBAAwC,CAAC,GAAG;CAgBlH,OAAO;;;;aAfW,WAAW,SAAS,IAAI,KAAK,SAAS,qBAmBrC,EAAE;;;;;;;;;MAlBF,oBACf,KACA,qHAyBW;;;;MAIX;;;;kBAxBY,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;MAwB/B;;;;AAIhB;;;;;;;ACnDA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAC3C,MAAM,UAAU,KAAK,QAAQ,OAAO,IAAI;CACxC,MAAM,OAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAI,OAAO;CAEtE,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA;IACA,SAAS,CAAC;IACV,UAAU,CAAC;GACb,CAAC;GAED,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAAS,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;GAGF,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;GAGF,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,WAAW,MAAM,YAAY,QAAQ;GAE3C,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAW,QAAQ,CAAC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@kubb/plugin-redoc",
3
- "version": "5.0.0-beta.4",
4
- "description": "Redoc documentation generator plugin for Kubb, creating beautiful, interactive API documentation from OpenAPI specifications.",
3
+ "version": "5.0.0-beta.56",
4
+ "description": "Generate a beautiful, interactive ReDoc API reference page from your OpenAPI specification. Produces a standalone HTML file with a responsive, developer-friendly UI.",
5
5
  "keywords": [
6
6
  "api-docs",
7
- "code-generator",
7
+ "api-reference",
8
+ "code-generation",
8
9
  "codegen",
9
10
  "documentation",
10
- "interactive-docs",
11
11
  "kubb",
12
12
  "openapi",
13
- "plugins",
14
13
  "redoc",
15
14
  "swagger",
16
15
  "typescript"
@@ -25,8 +24,6 @@
25
24
  "files": [
26
25
  "src",
27
26
  "dist",
28
- "static",
29
- "extension.yaml",
30
27
  "!/**/**.test.**",
31
28
  "!/**/__tests__/**",
32
29
  "!/**/__snapshots__/**"
@@ -51,30 +48,23 @@
51
48
  "registry": "https://registry.npmjs.org/"
52
49
  },
53
50
  "dependencies": {
54
- "@kubb/adapter-oas": "5.0.0-beta.4",
55
- "@kubb/core": "5.0.0-beta.4",
56
- "handlebars": "^4.7.9"
51
+ "@kubb/adapter-oas": "5.0.0-beta.55",
52
+ "@kubb/core": "5.0.0-beta.55"
57
53
  },
58
54
  "devDependencies": {
59
55
  "@internals/utils": "0.0.0"
60
56
  },
61
- "size-limit": [
62
- {
63
- "path": "./dist/*.js",
64
- "limit": "510 KiB",
65
- "gzip": true
66
- }
67
- ],
68
57
  "engines": {
69
58
  "node": ">=22"
70
59
  },
71
60
  "scripts": {
72
- "build": "tsdown && size-limit",
73
- "clean": "npx rimraf ./dist",
61
+ "build": "tsdown",
62
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
74
63
  "lint": "oxlint .",
75
64
  "lint:fix": "oxlint --fix .",
76
65
  "release": "pnpm publish --no-git-check",
77
66
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
67
+ "release:stage": "pnpm stage publish --no-git-check",
78
68
  "start": "tsdown --watch",
79
69
  "test": "vitest --passWithNoTests",
80
70
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
package/src/plugin.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import path from 'node:path'
2
- import { trimExtName } from '@internals/utils'
3
2
  import type { AdapterOas } from '@kubb/adapter-oas'
4
3
  import { adapterOasName } from '@kubb/adapter-oas'
5
4
 
@@ -8,10 +7,35 @@ import { version } from '../package.json'
8
7
  import { getPageHTML } from './redoc.tsx'
9
8
  import type { PluginRedoc } from './types.ts'
10
9
 
10
+ /**
11
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
12
+ * cross-plugin dependency references.
13
+ */
11
14
  export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
12
15
 
16
+ /**
17
+ * Generates a self-contained static HTML documentation page from your OpenAPI
18
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
19
+ * stay in lockstep with the spec the rest of your code is generated from.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { defineConfig } from 'kubb'
24
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
25
+ *
26
+ * export default defineConfig({
27
+ * input: { path: './petStore.yaml' },
28
+ * output: { path: './src/gen' },
29
+ * plugins: [
30
+ * pluginRedoc({ output: { path: 'docs.html' } }),
31
+ * ],
32
+ * })
33
+ * ```
34
+ */
13
35
  export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
14
36
  const { output = { path: 'docs.html' } } = options
37
+ const extname = path.extname(output.path)
38
+ const name = extname ? output.path.slice(0, -extname.length) : output.path
15
39
 
16
40
  return {
17
41
  name: pluginRedocName,
@@ -21,7 +45,7 @@ export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
21
45
  async 'kubb:plugin:setup'(ctx) {
22
46
  ctx.setOptions({
23
47
  output,
24
- name: trimExtName(output.path),
48
+ name,
25
49
  exclude: [],
26
50
  override: [],
27
51
  })
package/src/redoc.tsx CHANGED
@@ -1,11 +1,4 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
1
  import type { AdapterOas } from '@kubb/adapter-oas'
5
- import pkg from 'handlebars'
6
-
7
- const __filename = fileURLToPath(import.meta.url)
8
- const __dirname = path.dirname(__filename)
9
2
 
10
3
  type BuildDocsOptions = {
11
4
  title?: string
@@ -13,12 +6,31 @@ type BuildDocsOptions = {
13
6
  templateOptions?: any
14
7
  }
15
8
 
16
- export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
17
- const templateFileName = path.join(__dirname, '../static/redoc.hbs')
18
- const template = pkg.compile(fs.readFileSync(templateFileName).toString())
19
- return template({
20
- title: title || api.info.title || 'ReDoc documentation',
21
- redocHTML: `
9
+ const htmlEscapes: Record<string, string> = {
10
+ '&': '&amp;',
11
+ '<': '&lt;',
12
+ '>': '&gt;',
13
+ '"': '&quot;',
14
+ "'": '&#x27;',
15
+ '`': '&#x60;',
16
+ '=': '&#x3D;',
17
+ }
18
+
19
+ function escapeHtml(value: string) {
20
+ return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char)
21
+ }
22
+
23
+ /**
24
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
25
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
26
+ * the generated file works without further build steps.
27
+ */
28
+ export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont }: BuildDocsOptions = {}) {
29
+ const pageTitle = escapeHtml(title || api.info.title || 'ReDoc documentation')
30
+ const googleFont = disableGoogleFont
31
+ ? ''
32
+ : `<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />`
33
+ const redocHTML = `
22
34
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
23
35
  <div id="redoc-container"></div>
24
36
  <script>
@@ -27,8 +39,27 @@ export async function getPageHTML(api: AdapterOas['document'], { title, disableG
27
39
  "expandResponses": "200,400"
28
40
  }, document.getElementById('redoc-container'))
29
41
  </script>
30
- `,
31
- disableGoogleFont,
32
- templateOptions,
33
- })
42
+ `
43
+
44
+ return `<html>
45
+
46
+ <head>
47
+ <meta charset='utf8' />
48
+ <title>${pageTitle}</title>
49
+ <!-- needed for adaptive design -->
50
+ <meta name='viewport' content='width=device-width, initial-scale=1' />
51
+ <style>
52
+ body {
53
+ padding: 0;
54
+ margin: 0;
55
+ }
56
+ </style>
57
+ ${googleFont}
58
+ </head>
59
+
60
+ <body>
61
+ ${redocHTML}
62
+ </body>
63
+
64
+ </html>`
34
65
  }
package/src/types.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  import type { Exclude, Include, Output, Override, PluginFactoryOptions } from '@kubb/core'
2
2
 
3
3
  export type Options = {
4
+ /**
5
+ * Output location of the generated Redoc HTML file. The path is resolved
6
+ * against the global `output.path` set on `defineConfig`.
7
+ */
4
8
  output?: {
5
9
  /**
6
- * Output path for the generated HTML documentation.
10
+ * File path of the generated HTML, relative to the global `output.path`.
11
+ * Unlike most plugins, this points at a single file rather than a directory.
7
12
  *
8
13
  * @default 'docs.html'
9
14
  */
package/extension.yaml DELETED
@@ -1,67 +0,0 @@
1
- $schema: https://kubb.dev/schemas/extension.json
2
- kind: plugin
3
- id: plugin-redoc
4
- name: Redoc
5
- description: Generate API documentation with Redoc from OpenAPI specifications.
6
- category: documentation
7
- type: official
8
- npmPackage: "@kubb/plugin-redoc"
9
- docsPath: /plugins/plugin-redoc
10
- repo: https://github.com/kubb-labs/plugins
11
- maintainers:
12
- - name: Stijn Van Hulle
13
- github: stijnvanhulle
14
- compatibility:
15
- kubb: ">=5.0.0"
16
- node: ">=22"
17
- tags:
18
- - redoc
19
- - api-docs
20
- - documentation
21
- - interactive-docs
22
- - codegen
23
- - openapi
24
- dependencies: []
25
- resources:
26
- documentation: https://kubb.dev/plugins/plugin-redoc
27
- repository: https://github.com/kubb-labs/plugins
28
- issues: https://github.com/kubb-labs/plugins/issues
29
- changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-redoc/CHANGELOG.md
30
- codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/simple-single
31
- featured: false
32
- icon:
33
- light: https://kubb.dev/feature/openapi.svg
34
- intro: |
35
- Generate interactive API documentation from your OpenAPI schema using [Redoc](https://redocly.com/).
36
- options:
37
- - name: output
38
- type: "{ path: string }"
39
- required: false
40
- description: Specify the output path for the generated documentation HTML file.
41
- properties:
42
- - name: path
43
- type: string
44
- required: true
45
- description: |
46
- The output file path for the generated documentation HTML.
47
- tip: |
48
- if `output.path` is a file, `group` cannot be used.
49
- default: "'docs.html'"
50
- examples:
51
- - name: kubb.config.ts
52
- files:
53
- - lang: typescript
54
- code: |
55
- import { defineConfig } from 'kubb'
56
- import { pluginRedoc } from '@kubb/plugin-redoc'
57
-
58
- export default defineConfig({
59
- input: { path: './petStore.yaml' },
60
- output: { path: './src/gen' },
61
- plugins: [
62
- pluginRedoc({
63
- output: { path: 'docs.html' },
64
- }),
65
- ],
66
- })
67
- twoslash: false
package/static/redoc.hbs DELETED
@@ -1,21 +0,0 @@
1
- <html>
2
-
3
- <head>
4
- <meta charset='utf8' />
5
- <title>{{title}}</title>
6
- <!-- needed for adaptive design -->
7
- <meta name='viewport' content='width=device-width, initial-scale=1' />
8
- <style>
9
- body {
10
- padding: 0;
11
- margin: 0;
12
- }
13
- </style>
14
- {{#unless disableGoogleFont}}<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />{{/unless}}
15
- </head>
16
-
17
- <body>
18
- {{{redocHTML}}}
19
- </body>
20
-
21
- </html>
File without changes