@kubb/plugin-redoc 5.0.0-alpha.8 → 5.0.0-beta.10

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/LICENSE CHANGED
@@ -1,14 +1,21 @@
1
- Copyright (c) 2026 Stijn Van Hulle
1
+ MIT License
2
2
 
3
- This repository contains software under two licenses:
3
+ Copyright (c) 2026 Kubb Labs
4
4
 
5
- 1. Most of the code in this repository is licensed under the
6
- MIT License see licenses/LICENSE-MIT for the full license text.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
7
11
 
8
- 2. The following components are licensed under the
9
- GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)
10
- — see licenses/LICENSE-AGPL-3.0 for the full license text:
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
11
14
 
12
- - packages/agent (published as @kubb/agent)
13
-
14
- Each package's own LICENSE file or package.json specifies its applicable license.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,19 +1,19 @@
1
1
  <div align="center">
2
- <h1>Plugin Redoc</h1>
2
+ <h1>@kubb/plugin-redoc</h1>
3
3
  <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
4
4
  <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
5
5
  </a>
6
6
 
7
-
8
7
  [![npm version][npm-version-src]][npm-version-href]
9
8
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
10
9
  [![Coverage][coverage-src]][coverage-href]
11
10
  [![License][license-src]][license-href]
12
11
  [![Sponsors][sponsors-src]][sponsors-href]
12
+
13
13
  <h4>
14
- <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
14
+ <a href="https://codesandbox.io/s/github/kubb-labs/plugins/tree/main/examples/typescript" target="_blank">View Demo</a>
15
15
  <span> · </span>
16
- <a href="https://kubb.dev/" target="_blank">Documentation</a>
16
+ <a href="https://kubb.dev/plugins/redoc" target="_blank">Documentation</a>
17
17
  <span> · </span>
18
18
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
19
19
  <span> · </span>
@@ -21,12 +21,31 @@
21
21
  </h4>
22
22
  </div>
23
23
 
24
- Create beautiful docs with Redoc.
24
+ `@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.
25
+
26
+ ## Features
27
+
28
+ - Produces a self-contained HTML file with the ReDoc three-panel layout
29
+ - Supports theming and branding via ReDoc configuration options
30
+ - Works with any valid OpenAPI 3.0 or 3.1 specification
25
31
 
32
+ ## Installation
33
+
34
+ ```bash
35
+ bun add @kubb/plugin-redoc
36
+ # or
37
+ pnpm add @kubb/plugin-redoc
38
+ # or
39
+ npm install @kubb/plugin-redoc
40
+ ```
41
+
42
+ ## Documentation
43
+
44
+ See the [full documentation](https://kubb.dev/plugins/redoc) for configuration options and examples.
26
45
 
27
46
  ## Supporting Kubb
28
47
 
29
- 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:
48
+ Kubb is 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:
30
49
 
31
50
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
51
 
@@ -36,7 +55,6 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
36
55
  </a>
37
56
  </p>
38
57
 
39
-
40
58
  <!-- Badges -->
41
59
 
42
60
  [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
package/dist/index.cjs CHANGED
@@ -1,4 +1,7 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
2
5
  //#region \0rolldown/runtime.js
3
6
  var __create = Object.create;
4
7
  var __defProp = Object.defineProperty;
@@ -22,14 +25,35 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
25
  }) : target, mod));
23
26
  //#endregion
24
27
  let node_path = require("node:path");
28
+ let node_path$1 = __toESM(node_path, 1);
25
29
  node_path = __toESM(node_path);
30
+ let _kubb_adapter_oas = require("@kubb/adapter-oas");
26
31
  let _kubb_core = require("@kubb/core");
27
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
28
32
  let node_fs = require("node:fs");
29
33
  node_fs = __toESM(node_fs);
30
34
  let node_url = require("node:url");
31
35
  let handlebars = require("handlebars");
32
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
+ //#region package.json
55
+ var version = "5.0.0-beta.10";
56
+ //#endregion
33
57
  //#region src/redoc.tsx
34
58
  const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
35
59
  const __dirname$1 = node_path.default.dirname(__filename$1);
@@ -53,38 +77,39 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
53
77
  }
54
78
  //#endregion
55
79
  //#region src/plugin.ts
56
- function trimExtName(text) {
57
- return text.replace(/\.[^/.]+$/, "");
58
- }
59
80
  const pluginRedocName = "plugin-redoc";
60
- const pluginRedoc = (0, _kubb_core.createPlugin)((options) => {
81
+ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
61
82
  const { output = { path: "docs.html" } } = options;
62
83
  return {
63
84
  name: pluginRedocName,
64
- options: {
65
- output,
66
- name: trimExtName(output.path)
67
- },
68
- pre: [_kubb_plugin_oas.pluginOasName],
69
- async install() {
70
- const oas = await this.getOas();
71
- await oas.dereference();
72
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
73
- const pageHTML = await getPageHTML(oas.api);
74
- await this.addFile({
85
+ version,
86
+ options,
87
+ hooks: { async "kubb:plugin:setup"(ctx) {
88
+ ctx.setOptions({
89
+ output,
90
+ name: trimExtName(output.path),
91
+ exclude: [],
92
+ override: []
93
+ });
94
+ const adapter = ctx.config.adapter;
95
+ 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
+ const document = adapter.document;
97
+ 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);
99
+ const pageHTML = await getPageHTML(document);
100
+ ctx.injectFile({
75
101
  baseName: "docs.html",
76
- path: node_path.default.resolve(root, output.path || "./docs.html"),
77
- sources: [{
102
+ path: node_path$1.default.resolve(root, output.path || "./docs.html"),
103
+ sources: [_kubb_core.ast.createSource({
78
104
  name: "docs.html",
79
- value: pageHTML
80
- }],
81
- imports: [],
82
- exports: []
105
+ nodes: [_kubb_core.ast.createText(pageHTML)]
106
+ })]
83
107
  });
84
- }
108
+ } }
85
109
  };
86
110
  });
87
111
  //#endregion
112
+ exports.default = pluginRedoc;
88
113
  exports.pluginRedoc = pluginRedoc;
89
114
  exports.pluginRedocName = pluginRedocName;
90
115
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["__filename","__dirname","path","pkg","fs","pluginOasName","path"],"sources":["../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { OasTypes } from '@kubb/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: OasTypes.OASDocument, { 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 { createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nfunction trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async install() {\n const oas = await this.getOas()\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.addFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n {\n name: 'docs.html',\n value: pageHTML,\n },\n ],\n imports: [],\n exports: [],\n })\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAMA,gBAAAA,GAAAA,SAAAA,eAAAA,QAAAA,MAAAA,CAAAA,cAAAA,WAAAA,CAAAA,KAA2C;AACjD,MAAMC,cAAYC,UAAAA,QAAK,QAAQF,aAAW;AAQ1C,eAAsB,YAAY,KAA2B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACjI,MAAM,mBAAmBE,UAAAA,QAAK,KAAKD,aAAW,sBAAsB;AAEpE,QADiBE,WAAAA,QAAI,QAAQC,QAAAA,QAAG,aAAa,iBAAiB,CAAC,UAAU,CAAC,CAC1D;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;;;;;;EAM3C;EACA;EACD,CAAC;;;;AC1BJ,SAAS,YAAY,MAAsB;AACzC,QAAO,KAAK,QAAQ,aAAa,GAAG;;AAGtC,MAAa,kBAAkB;AAE/B,MAAa,eAAA,GAAA,WAAA,eAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,MAAM,YAAY,OAAO,KAAK;GAC/B;EACD,KAAK,CAACC,iBAAAA,cAAc;EACpB,MAAM,UAAU;GACd,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAEvB,MAAM,OAAOC,UAAAA,QAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,WAAW,MAAM,YAAY,IAAI,IAAI;AAE3C,SAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAMA,UAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACP;KACE,MAAM;KACN,OAAO;KACR,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;;EAEL;EACD"}
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;CACtC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,EAC/C,OAAO,KAAK,MAAM,GAAG,SAAS;CAEhC,OAAO;;;;;;;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;CAEpE,OADiBE,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;CAE3C,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,KAAK;IAC9B,SAAS,EAAE;IACX,UAAU,EAAE;IACb,CAAC;GAEF,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAASC,kBAAAA,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,uIACrB;GAGH,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,yHACrB;GAGH,MAAM,OAAOC,YAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,WAAW,MAAM,YAAY,SAAS;GAE5C,IAAI,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"}
package/dist/index.d.ts CHANGED
@@ -1,26 +1,37 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _kubb_core0 from "@kubb/core";
3
- import { Output, PluginFactoryOptions } from "@kubb/core";
4
- import { Oas } from "@kubb/oas";
2
+ import * as _$_kubb_core0 from "@kubb/core";
3
+ import { Exclude, Include, Output, Override, PluginFactoryOptions } from "@kubb/core";
5
4
 
6
5
  //#region src/types.d.ts
7
6
  type Options = {
8
7
  output?: {
9
8
  /**
10
- * Output for the generated doc, [https://redocly.com/](https://redocly.com/) is being used for the generation
9
+ * Output path for the generated HTML documentation.
10
+ *
11
11
  * @default 'docs.html'
12
12
  */
13
13
  path: string;
14
14
  };
15
15
  };
16
16
  type ResolveOptions = {
17
- output: Output<Oas>;
17
+ output: Output<never>;
18
+ name: string;
19
+ exclude: Array<Exclude>;
20
+ include?: Array<Include>;
21
+ override: Array<Override<ResolveOptions>>;
18
22
  };
19
- type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>;
23
+ type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions>;
24
+ declare global {
25
+ namespace Kubb {
26
+ interface PluginRegistry {
27
+ 'plugin-redoc': PluginRedoc;
28
+ }
29
+ }
30
+ }
20
31
  //#endregion
21
32
  //#region src/plugin.d.ts
22
33
  declare const pluginRedocName = "plugin-redoc";
23
- declare const pluginRedoc: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginRedoc>;
34
+ declare const pluginRedoc: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginRedoc>;
24
35
  //#endregion
25
- export { type PluginRedoc, pluginRedoc, pluginRedocName };
36
+ export { type PluginRedoc, pluginRedoc as default, pluginRedoc, pluginRedocName };
26
37
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,10 +1,30 @@
1
1
  import "./chunk--u3MIqq1.js";
2
2
  import path from "node:path";
3
- import { createPlugin } from "@kubb/core";
4
- import { pluginOasName } from "@kubb/plugin-oas";
3
+ import { adapterOasName } from "@kubb/adapter-oas";
4
+ import { ast, definePlugin } from "@kubb/core";
5
5
  import fs from "node:fs";
6
6
  import { fileURLToPath } from "node:url";
7
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
+ //#region package.json
26
+ var version = "5.0.0-beta.10";
27
+ //#endregion
8
28
  //#region src/redoc.tsx
9
29
  const __filename = fileURLToPath(import.meta.url);
10
30
  const __dirname = path.dirname(__filename);
@@ -28,38 +48,38 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
28
48
  }
29
49
  //#endregion
30
50
  //#region src/plugin.ts
31
- function trimExtName(text) {
32
- return text.replace(/\.[^/.]+$/, "");
33
- }
34
51
  const pluginRedocName = "plugin-redoc";
35
- const pluginRedoc = createPlugin((options) => {
52
+ const pluginRedoc = definePlugin((options) => {
36
53
  const { output = { path: "docs.html" } } = options;
37
54
  return {
38
55
  name: pluginRedocName,
39
- options: {
40
- output,
41
- name: trimExtName(output.path)
42
- },
43
- pre: [pluginOasName],
44
- async install() {
45
- const oas = await this.getOas();
46
- await oas.dereference();
47
- const root = path.resolve(this.config.root, this.config.output.path);
48
- const pageHTML = await getPageHTML(oas.api);
49
- await this.addFile({
56
+ version,
57
+ options,
58
+ hooks: { async "kubb:plugin:setup"(ctx) {
59
+ ctx.setOptions({
60
+ output,
61
+ name: trimExtName(output.path),
62
+ exclude: [],
63
+ override: []
64
+ });
65
+ const adapter = ctx.config.adapter;
66
+ if (adapter?.name !== 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.`);
67
+ const document = adapter.document;
68
+ 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.`);
69
+ const root = path.resolve(ctx.config.root, ctx.config.output.path);
70
+ const pageHTML = await getPageHTML(document);
71
+ ctx.injectFile({
50
72
  baseName: "docs.html",
51
73
  path: path.resolve(root, output.path || "./docs.html"),
52
- sources: [{
74
+ sources: [ast.createSource({
53
75
  name: "docs.html",
54
- value: pageHTML
55
- }],
56
- imports: [],
57
- exports: []
76
+ nodes: [ast.createText(pageHTML)]
77
+ })]
58
78
  });
59
- }
79
+ } }
60
80
  };
61
81
  });
62
82
  //#endregion
63
- export { pluginRedoc, pluginRedocName };
83
+ export { pluginRedoc as default, pluginRedoc, pluginRedocName };
64
84
 
65
85
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { OasTypes } from '@kubb/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: OasTypes.OASDocument, { 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 { createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nfunction trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async install() {\n const oas = await this.getOas()\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.addFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n {\n name: 'docs.html',\n value: pageHTML,\n },\n ],\n imports: [],\n exports: [],\n })\n },\n }\n})\n"],"mappings":";;;;;;;;AAMA,MAAM,aAAa,cAAc,OAAO,KAAK,IAAI;AACjD,MAAM,YAAY,KAAK,QAAQ,WAAW;AAQ1C,eAAsB,YAAY,KAA2B,EAAE,OAAO,mBAAmB,oBAAsC,EAAE,EAAE;CACjI,MAAM,mBAAmB,KAAK,KAAK,WAAW,sBAAsB;AAEpE,QADiB,IAAI,QAAQ,GAAG,aAAa,iBAAiB,CAAC,UAAU,CAAC,CAC1D;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,EAAE,CAAC;;;;;;EAM3C;EACA;EACD,CAAC;;;;AC1BJ,SAAS,YAAY,MAAsB;AACzC,QAAO,KAAK,QAAQ,aAAa,GAAG;;AAGtC,MAAa,kBAAkB;AAE/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,KAAK;AAE3C,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA,MAAM,YAAY,OAAO,KAAK;GAC/B;EACD,KAAK,CAAC,cAAc;EACpB,MAAM,UAAU;GACd,MAAM,MAAM,MAAM,KAAK,QAAQ;AAC/B,SAAM,IAAI,aAAa;GAEvB,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,WAAW,MAAM,YAAY,IAAI,IAAI;AAE3C,SAAM,KAAK,QAAQ;IACjB,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,cAAc;IACtD,SAAS,CACP;KACE,MAAM;KACN,OAAO;KACR,CACF;IACD,SAAS,EAAE;IACX,SAAS,EAAE;IACZ,CAAC;;EAEL;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 { 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;CACtC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,EAC/C,OAAO,KAAK,MAAM,GAAG,SAAS;CAEhC,OAAO;;;;;;;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;CAEpE,OADiB,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;CAE3C,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,KAAK;IAC9B,SAAS,EAAE;IACX,UAAU,EAAE;IACb,CAAC;GAEF,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAAS,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,uIACrB;GAGH,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,yHACrB;GAGH,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,KAAK;GAClE,MAAM,WAAW,MAAM,YAAY,SAAS;GAE5C,IAAI,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"}
package/extension.yaml ADDED
@@ -0,0 +1,67 @@
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/package.json CHANGED
@@ -1,29 +1,43 @@
1
1
  {
2
2
  "name": "@kubb/plugin-redoc",
3
- "version": "5.0.0-alpha.8",
4
- "description": "Redoc documentation generator plugin for Kubb, creating beautiful, interactive API documentation from OpenAPI specifications.",
3
+ "version": "5.0.0-beta.10",
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
- "redoc",
7
- "documentation",
8
6
  "api-docs",
7
+ "api-reference",
8
+ "code-generation",
9
+ "codegen",
10
+ "documentation",
11
+ "kubb",
9
12
  "openapi",
13
+ "redoc",
10
14
  "swagger",
11
- "interactive-docs",
12
- "typescript",
13
- "code-generator",
14
- "codegen",
15
- "plugins",
16
- "kubb"
15
+ "typescript"
17
16
  ],
17
+ "license": "MIT",
18
+ "author": "stijnvanhulle",
18
19
  "repository": {
19
20
  "type": "git",
20
- "url": "git+https://github.com/kubb-labs/kubb.git",
21
+ "url": "git+https://github.com/kubb-labs/plugins.git",
21
22
  "directory": "packages/plugin-redoc"
22
23
  },
23
- "license": "MIT",
24
- "author": "stijnvanhulle",
25
- "sideEffects": false,
24
+ "files": [
25
+ "src",
26
+ "dist",
27
+ "static",
28
+ "extension.yaml",
29
+ "!/**/**.test.**",
30
+ "!/**/__tests__/**",
31
+ "!/**/__snapshots__/**"
32
+ ],
26
33
  "type": "module",
34
+ "sideEffects": false,
35
+ "main": "./dist/index.cjs",
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "typesVersions": {
39
+ "*": {}
40
+ },
27
41
  "exports": {
28
42
  ".": {
29
43
  "import": "./dist/index.js",
@@ -31,18 +45,18 @@
31
45
  },
32
46
  "./package.json": "./package.json"
33
47
  },
34
- "types": "./dist/index.d.ts",
35
- "typesVersions": {
36
- "*": {}
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
52
+ "dependencies": {
53
+ "@kubb/adapter-oas": "5.0.0-beta.10",
54
+ "@kubb/core": "5.0.0-beta.10",
55
+ "handlebars": "^4.7.9"
56
+ },
57
+ "devDependencies": {
58
+ "@internals/utils": "0.0.0"
37
59
  },
38
- "files": [
39
- "src",
40
- "dist",
41
- "static",
42
- "!/**/**.test.**",
43
- "!/**/__tests__/**",
44
- "!/**/__snapshots__/**"
45
- ],
46
60
  "size-limit": [
47
61
  {
48
62
  "path": "./dist/*.js",
@@ -50,32 +64,14 @@
50
64
  "gzip": true
51
65
  }
52
66
  ],
53
- "dependencies": {
54
- "@kubb/fabric-core": "0.14.0",
55
- "@kubb/react-fabric": "0.14.0",
56
- "handlebars": "^4.7.8",
57
- "@kubb/core": "5.0.0-alpha.8",
58
- "@kubb/plugin-oas": "5.0.0-alpha.8",
59
- "@kubb/oas": "5.0.0-alpha.8"
60
- },
61
- "peerDependencies": {
62
- "@kubb/fabric-core": "0.14.0",
63
- "@kubb/react-fabric": "0.14.0"
64
- },
65
67
  "engines": {
66
68
  "node": ">=22"
67
69
  },
68
- "publishConfig": {
69
- "access": "public",
70
- "registry": "https://registry.npmjs.org/"
71
- },
72
- "main": "./dist/index.cjs",
73
- "module": "./dist/index.js",
74
70
  "scripts": {
75
71
  "build": "tsdown && size-limit",
76
72
  "clean": "npx rimraf ./dist",
77
- "lint": "bun biome lint .",
78
- "lint:fix": "bun biome lint --fix --unsafe .",
73
+ "lint": "oxlint .",
74
+ "lint:fix": "oxlint --fix .",
79
75
  "release": "pnpm publish --no-git-check",
80
76
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
81
77
  "start": "tsdown --watch",
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { pluginRedoc, pluginRedocName } from './plugin.ts'
1
+ export { default, pluginRedoc, pluginRedocName } from './plugin.ts'
2
2
  export type { PluginRedoc } from './types.ts'
package/src/plugin.ts CHANGED
@@ -1,44 +1,63 @@
1
1
  import path from 'node:path'
2
- import { createPlugin } from '@kubb/core'
3
- import { pluginOasName } from '@kubb/plugin-oas'
2
+ import { trimExtName } from '@internals/utils'
3
+ import type { AdapterOas } from '@kubb/adapter-oas'
4
+ import { adapterOasName } from '@kubb/adapter-oas'
5
+
6
+ import { type Adapter, ast, definePlugin } from '@kubb/core'
7
+ import { version } from '../package.json'
4
8
  import { getPageHTML } from './redoc.tsx'
5
9
  import type { PluginRedoc } from './types.ts'
6
10
 
7
- function trimExtName(text: string): string {
8
- return text.replace(/\.[^/.]+$/, '')
9
- }
10
-
11
11
  export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
12
12
 
13
- export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
13
+ export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
14
14
  const { output = { path: 'docs.html' } } = options
15
15
 
16
16
  return {
17
17
  name: pluginRedocName,
18
- options: {
19
- output,
20
- name: trimExtName(output.path),
21
- },
22
- pre: [pluginOasName],
23
- async install() {
24
- const oas = await this.getOas()
25
- await oas.dereference()
26
-
27
- const root = path.resolve(this.config.root, this.config.output.path)
28
- const pageHTML = await getPageHTML(oas.api)
29
-
30
- await this.addFile({
31
- baseName: 'docs.html',
32
- path: path.resolve(root, output.path || './docs.html'),
33
- sources: [
34
- {
35
- name: 'docs.html',
36
- value: pageHTML,
37
- },
38
- ],
39
- imports: [],
40
- exports: [],
41
- })
18
+ version,
19
+ options,
20
+ hooks: {
21
+ async 'kubb:plugin:setup'(ctx) {
22
+ ctx.setOptions({
23
+ output,
24
+ name: trimExtName(output.path),
25
+ exclude: [],
26
+ override: [],
27
+ })
28
+
29
+ const adapter = ctx.config.adapter
30
+
31
+ if (adapter?.name !== adapterOasName) {
32
+ throw new Error(
33
+ `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \`adapter: adapterOas()\`) in your Kubb config.`,
34
+ )
35
+ }
36
+
37
+ const document = (adapter as Adapter<AdapterOas>).document
38
+
39
+ if (!document) {
40
+ throw new Error(
41
+ `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,
42
+ )
43
+ }
44
+
45
+ const root = path.resolve(ctx.config.root, ctx.config.output.path)
46
+ const pageHTML = await getPageHTML(document)
47
+
48
+ ctx.injectFile({
49
+ baseName: 'docs.html',
50
+ path: path.resolve(root, output.path || './docs.html'),
51
+ sources: [
52
+ ast.createSource({
53
+ name: 'docs.html',
54
+ nodes: [ast.createText(pageHTML)],
55
+ }),
56
+ ],
57
+ })
58
+ },
42
59
  },
43
60
  }
44
61
  })
62
+
63
+ export default pluginRedoc
package/src/redoc.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { fileURLToPath } from 'node:url'
4
- import type { OasTypes } from '@kubb/oas'
4
+ import type { AdapterOas } from '@kubb/adapter-oas'
5
5
  import pkg from 'handlebars'
6
6
 
7
7
  const __filename = fileURLToPath(import.meta.url)
@@ -13,7 +13,7 @@ type BuildDocsOptions = {
13
13
  templateOptions?: any
14
14
  }
15
15
 
16
- export async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
16
+ export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
17
17
  const templateFileName = path.join(__dirname, '../static/redoc.hbs')
18
18
  const template = pkg.compile(fs.readFileSync(templateFileName).toString())
19
19
  return template({
package/src/types.ts CHANGED
@@ -1,10 +1,10 @@
1
- import type { Output, PluginFactoryOptions } from '@kubb/core'
2
- import type { Oas } from '@kubb/oas'
1
+ import type { Exclude, Include, Output, Override, PluginFactoryOptions } from '@kubb/core'
3
2
 
4
3
  export type Options = {
5
4
  output?: {
6
5
  /**
7
- * Output for the generated doc, [https://redocly.com/](https://redocly.com/) is being used for the generation
6
+ * Output path for the generated HTML documentation.
7
+ *
8
8
  * @default 'docs.html'
9
9
  */
10
10
  path: string
@@ -12,7 +12,19 @@ export type Options = {
12
12
  }
13
13
 
14
14
  type ResolveOptions = {
15
- output: Output<Oas>
15
+ output: Output<never>
16
+ name: string
17
+ exclude: Array<Exclude>
18
+ include?: Array<Include>
19
+ override: Array<Override<ResolveOptions>>
16
20
  }
17
21
 
18
- export type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>
22
+ export type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions>
23
+
24
+ declare global {
25
+ namespace Kubb {
26
+ interface PluginRegistry {
27
+ 'plugin-redoc': PluginRedoc
28
+ }
29
+ }
30
+ }
package/static/redoc.hbs CHANGED
@@ -1,22 +1,21 @@
1
- <!DOCTYPE html>
2
1
  <html>
3
2
 
4
- <head>
5
- <meta charset="utf8" />
6
- <title>{{title}}</title>
7
- <!-- needed for adaptive design -->
8
- <meta name="viewport" content="width=device-width, initial-scale=1">
9
- <style>
10
- body {
11
- padding: 0;
12
- margin: 0;
13
- }
14
- </style>
15
- {{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
16
- </head>
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>
17
16
 
18
- <body>
19
- {{{redocHTML}}}
20
- </body>
17
+ <body>
18
+ {{{redocHTML}}}
19
+ </body>
21
20
 
22
- </html>
21
+ </html>