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

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
@@ -31,7 +31,6 @@ let _kubb_adapter_oas = require("@kubb/adapter-oas");
31
31
  let _kubb_core = require("@kubb/core");
32
32
  let node_fs = require("node:fs");
33
33
  node_fs = __toESM(node_fs);
34
- let node_url = require("node:url");
35
34
  let handlebars = require("handlebars");
36
35
  handlebars = __toESM(handlebars);
37
36
  //#region ../../internals/utils/src/string.ts
@@ -52,13 +51,16 @@ function trimExtName(text) {
52
51
  }
53
52
  //#endregion
54
53
  //#region package.json
55
- var version = "5.0.0-beta.4";
54
+ var version = "5.0.0-beta.42";
56
55
  //#endregion
57
56
  //#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);
57
+ /**
58
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
59
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
60
+ * the generated file works without further build steps.
61
+ */
60
62
  async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
61
- const templateFileName = node_path.default.join(__dirname$1, "../static/redoc.hbs");
63
+ const templateFileName = node_path.default.join(__dirname, "../static/redoc.hbs");
62
64
  return handlebars.default.compile(node_fs.default.readFileSync(templateFileName).toString())({
63
65
  title: title || api.info.title || "ReDoc documentation",
64
66
  redocHTML: `
@@ -77,7 +79,30 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
77
79
  }
78
80
  //#endregion
79
81
  //#region src/plugin.ts
82
+ /**
83
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
84
+ * cross-plugin dependency references.
85
+ */
80
86
  const pluginRedocName = "plugin-redoc";
87
+ /**
88
+ * Generates a self-contained static HTML documentation page from your OpenAPI
89
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
90
+ * stay in lockstep with the spec the rest of your code is generated from.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { defineConfig } from 'kubb'
95
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
96
+ *
97
+ * export default defineConfig({
98
+ * input: { path: './petStore.yaml' },
99
+ * output: { path: './src/gen' },
100
+ * plugins: [
101
+ * pluginRedoc({ output: { path: 'docs.html' } }),
102
+ * ],
103
+ * })
104
+ * ```
105
+ */
81
106
  const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
82
107
  const { output = { path: "docs.html" } } = options;
83
108
  return {
@@ -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","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 type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\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, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(import.meta.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\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\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,GAAG;CACrC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,QAAQ,GAC9C,OAAO,KAAK,MAAM,GAAG,QAAQ;CAE/B,OAAO;AACT;;;;;;;;;;;AEnDA,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,CAAC,GAAG;CACnI,MAAM,mBAAmBA,UAAAA,QAAK,KAAA,WAA0B,qBAAqB;CAE7E,OADiBC,WAAAA,QAAI,QAAQC,QAAAA,QAAG,aAAa,gBAAgB,EAAE,SAAS,CAC1D,EAAE;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;;EAM3C;EACA;CACF,CAAC;AACH;;;;;;;ACpBA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,eAAA,GAAA,WAAA,eAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAE3C,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,IAAI;IAC7B,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,OAAOC,YAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,WAAW,MAAM,YAAY,QAAQ;GAE3C,IAAI,WAAW;IACb,UAAU;IACV,MAAMA,YAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACPC,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,9 +1,8 @@
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
5
  import fs from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
6
  import pkg from "handlebars";
8
7
  //#region ../../internals/utils/src/string.ts
9
8
  /**
@@ -23,13 +22,16 @@ function trimExtName(text) {
23
22
  }
24
23
  //#endregion
25
24
  //#region package.json
26
- var version = "5.0.0-beta.4";
25
+ var version = "5.0.0-beta.42";
27
26
  //#endregion
28
27
  //#region src/redoc.tsx
29
- const __filename = fileURLToPath(import.meta.url);
30
- const __dirname = path.dirname(__filename);
28
+ /**
29
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
30
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
31
+ * the generated file works without further build steps.
32
+ */
31
33
  async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
32
- const templateFileName = path.join(__dirname, "../static/redoc.hbs");
34
+ const templateFileName = path.join(import.meta.dirname, "../static/redoc.hbs");
33
35
  return pkg.compile(fs.readFileSync(templateFileName).toString())({
34
36
  title: title || api.info.title || "ReDoc documentation",
35
37
  redocHTML: `
@@ -48,7 +50,30 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
48
50
  }
49
51
  //#endregion
50
52
  //#region src/plugin.ts
53
+ /**
54
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
55
+ * cross-plugin dependency references.
56
+ */
51
57
  const pluginRedocName = "plugin-redoc";
58
+ /**
59
+ * Generates a self-contained static HTML documentation page from your OpenAPI
60
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
61
+ * stay in lockstep with the spec the rest of your code is generated from.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * import { defineConfig } from 'kubb'
66
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
67
+ *
68
+ * export default defineConfig({
69
+ * input: { path: './petStore.yaml' },
70
+ * output: { path: './src/gen' },
71
+ * plugins: [
72
+ * pluginRedoc({ output: { path: 'docs.html' } }),
73
+ * ],
74
+ * })
75
+ * ```
76
+ */
52
77
  const pluginRedoc = definePlugin((options) => {
53
78
  const { output = { path: "docs.html" } } = options;
54
79
  return {
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":["../../../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 type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\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, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(import.meta.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\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\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,GAAG;CACrC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,QAAQ,GAC9C,OAAO,KAAK,MAAM,GAAG,QAAQ;CAE/B,OAAO;AACT;;;;;;;;;;;AEnDA,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,CAAC,GAAG;CACnI,MAAM,mBAAmB,KAAK,KAAK,OAAO,KAAK,SAAS,qBAAqB;CAE7E,OADiB,IAAI,QAAQ,GAAG,aAAa,gBAAgB,EAAE,SAAS,CAC1D,EAAE;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;;EAM3C;EACA;CACF,CAAC;AACH;;;;;;;ACpBA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAE3C,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,IAAI;IAC7B,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/extension.yaml CHANGED
@@ -2,18 +2,18 @@ $schema: https://kubb.dev/schemas/extension.json
2
2
  kind: plugin
3
3
  id: plugin-redoc
4
4
  name: Redoc
5
- description: Generate API documentation with Redoc from OpenAPI specifications.
5
+ description: Render your OpenAPI spec as a single-file HTML page using Redoc, regenerated as part of the Kubb build.
6
6
  category: documentation
7
7
  type: official
8
- npmPackage: "@kubb/plugin-redoc"
8
+ npmPackage: '@kubb/plugin-redoc'
9
9
  docsPath: /plugins/plugin-redoc
10
10
  repo: https://github.com/kubb-labs/plugins
11
11
  maintainers:
12
12
  - name: Stijn Van Hulle
13
13
  github: stijnvanhulle
14
14
  compatibility:
15
- kubb: ">=5.0.0"
16
- node: ">=22"
15
+ kubb: '>=5.0.0'
16
+ node: '>=22'
17
17
  tags:
18
18
  - redoc
19
19
  - api-docs
@@ -32,25 +32,61 @@ featured: false
32
32
  icon:
33
33
  light: https://kubb.dev/feature/openapi.svg
34
34
  intro: |
35
- Generate interactive API documentation from your OpenAPI schema using [Redoc](https://redocly.com/).
35
+ # @kubb/plugin-redoc
36
+
37
+ Generate a static HTML documentation page for your OpenAPI spec using [Redoc](https://redocly.com/). The page is self-contained — drop it on any static host or open it locally.
38
+
39
+ Because the file is regenerated on every Kubb build, your docs stay in lockstep with the spec your code was generated from.
36
40
  options:
37
41
  - name: output
38
- type: "{ path: string }"
42
+ type: '{ path: string }'
39
43
  required: false
40
- description: Specify the output path for the generated documentation HTML file.
44
+ default: "{ path: 'docs.html' }"
45
+ description: Output location of the generated HTML file.
41
46
  properties:
42
47
  - name: path
43
48
  type: string
44
49
  required: true
45
50
  description: |
46
- The output file path for the generated documentation HTML.
51
+ File path of the generated HTML, relative to the global `output.path`.
52
+
53
+ Use a `.html` extension. Unlike most plugins, this option points at a single file rather than a directory.
47
54
  tip: |
48
- if `output.path` is a file, `group` cannot be used.
55
+ When `output.path` points to a single file, the `group` option cannot be used because every operation ends up in the same file.
56
+ examples:
57
+ - name: kubb.config.ts
58
+ files:
59
+ - lang: typescript
60
+ twoslash: false
61
+ code: |
62
+ import { defineConfig } from 'kubb'
63
+ import { pluginTs } from '@kubb/plugin-ts'
64
+
65
+ export default defineConfig({
66
+ input: { path: './petStore.yaml' },
67
+ output: { path: './src/gen' },
68
+ plugins: [
69
+ pluginTs({
70
+ output: { path: './types' },
71
+ }),
72
+ ],
73
+ })
74
+ - name: Resulting tree
75
+ files:
76
+ - lang: text
77
+ twoslash: false
78
+ code: |
79
+ src/
80
+ └── gen/
81
+ └── types/
82
+ ├── Pet.ts
83
+ └── Store.ts
49
84
  default: "'docs.html'"
50
85
  examples:
51
86
  - name: kubb.config.ts
52
87
  files:
53
88
  - lang: typescript
89
+ twoslash: false
54
90
  code: |
55
91
  import { defineConfig } from 'kubb'
56
92
  import { pluginRedoc } from '@kubb/plugin-redoc'
@@ -64,4 +100,3 @@ examples:
64
100
  }),
65
101
  ],
66
102
  })
67
- twoslash: false
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.42",
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"
@@ -51,8 +50,8 @@
51
50
  "registry": "https://registry.npmjs.org/"
52
51
  },
53
52
  "dependencies": {
54
- "@kubb/adapter-oas": "5.0.0-beta.4",
55
- "@kubb/core": "5.0.0-beta.4",
53
+ "@kubb/adapter-oas": "5.0.0-beta.42",
54
+ "@kubb/core": "5.0.0-beta.42",
56
55
  "handlebars": "^4.7.9"
57
56
  },
58
57
  "devDependencies": {
@@ -75,6 +74,7 @@
75
74
  "lint:fix": "oxlint --fix .",
76
75
  "release": "pnpm publish --no-git-check",
77
76
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
77
+ "release:stage": "pnpm stage publish --no-git-check",
78
78
  "start": "tsdown --watch",
79
79
  "test": "vitest --passWithNoTests",
80
80
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
package/src/plugin.ts CHANGED
@@ -8,8 +8,31 @@ import { version } from '../package.json'
8
8
  import { getPageHTML } from './redoc.tsx'
9
9
  import type { PluginRedoc } from './types.ts'
10
10
 
11
+ /**
12
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
13
+ * cross-plugin dependency references.
14
+ */
11
15
  export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
12
16
 
17
+ /**
18
+ * Generates a self-contained static HTML documentation page from your OpenAPI
19
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
20
+ * stay in lockstep with the spec the rest of your code is generated from.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { defineConfig } from 'kubb'
25
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
26
+ *
27
+ * export default defineConfig({
28
+ * input: { path: './petStore.yaml' },
29
+ * output: { path: './src/gen' },
30
+ * plugins: [
31
+ * pluginRedoc({ output: { path: 'docs.html' } }),
32
+ * ],
33
+ * })
34
+ * ```
35
+ */
13
36
  export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
14
37
  const { output = { path: 'docs.html' } } = options
15
38
 
package/src/redoc.tsx CHANGED
@@ -1,20 +1,21 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
3
  import type { AdapterOas } from '@kubb/adapter-oas'
5
4
  import pkg from 'handlebars'
6
5
 
7
- const __filename = fileURLToPath(import.meta.url)
8
- const __dirname = path.dirname(__filename)
9
-
10
6
  type BuildDocsOptions = {
11
7
  title?: string
12
8
  disableGoogleFont?: boolean
13
9
  templateOptions?: any
14
10
  }
15
11
 
12
+ /**
13
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
14
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
15
+ * the generated file works without further build steps.
16
+ */
16
17
  export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
17
- const templateFileName = path.join(__dirname, '../static/redoc.hbs')
18
+ const templateFileName = path.join(import.meta.dirname, '../static/redoc.hbs')
18
19
  const template = pkg.compile(fs.readFileSync(templateFileName).toString())
19
20
  return template({
20
21
  title: title || api.info.title || 'ReDoc documentation',
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
  */
File without changes