@kubb/plugin-redoc 5.0.0-alpha.9 → 5.0.0-beta.103

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,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
-
8
6
  [![npm version][npm-version-src]][npm-version-href]
9
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
10
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
11
9
  [![License][license-src]][license-href]
12
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Node][node-src]][node-href]
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,12 +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 with Kubb
25
26
 
27
+ `@kubb/plugin-redoc` generates a ReDoc API reference page with Kubb. 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.
26
42
 
27
43
  ## Supporting Kubb
28
44
 
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:
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:
30
46
 
31
47
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
48
 
@@ -36,20 +52,19 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
36
52
  </a>
37
53
  </p>
38
54
 
55
+ ## License
56
+
57
+ [MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
39
58
 
40
59
  <!-- Badges -->
41
60
 
42
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
43
- [npm-version-href]: https://npmjs.com/package/@kubb/plugin-redoc
44
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
45
- [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-redoc
46
- [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
47
68
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
48
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
49
- [build-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
50
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
51
- [minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
52
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
53
- [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
54
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
55
- [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
@@ -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,22 +25,49 @@ 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");
25
- node_path = __toESM(node_path);
26
- let _kubb_core = require("@kubb/core");
27
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
28
- let node_fs = require("node:fs");
29
- node_fs = __toESM(node_fs);
30
- let node_url = require("node:url");
31
- let handlebars = require("handlebars");
32
- handlebars = __toESM(handlebars);
28
+ node_path = __toESM(node_path, 1);
29
+ let _kubb_adapter_oas = require("@kubb/adapter-oas");
30
+ let kubb_kit = require("kubb/kit");
31
+ //#region package.json
32
+ var version = "5.0.0-beta.103";
33
+ //#endregion
33
34
  //#region src/redoc.tsx
34
- const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
35
- const __dirname$1 = node_path.default.dirname(__filename$1);
36
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
37
- const templateFileName = node_path.default.join(__dirname$1, "../static/redoc.hbs");
38
- return handlebars.default.compile(node_fs.default.readFileSync(templateFileName).toString())({
39
- title: title || api.info.title || "ReDoc documentation",
40
- 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) {
53
+ return `<html>
54
+
55
+ <head>
56
+ <meta charset='utf8' />
57
+ <title>${escapeHtml(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
+ <link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />
67
+ </head>
68
+
69
+ <body>
70
+ ${`
41
71
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
42
72
  <div id="redoc-container"></div>
43
73
  <script>
@@ -46,45 +76,71 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
46
76
  "expandResponses": "200,400"
47
77
  }, document.getElementById('redoc-container'))
48
78
  <\/script>
49
- `,
50
- disableGoogleFont,
51
- templateOptions
52
- });
79
+ `}
80
+ </body>
81
+
82
+ </html>`;
53
83
  }
54
84
  //#endregion
55
85
  //#region src/plugin.ts
56
- function trimExtName(text) {
57
- return text.replace(/\.[^/.]+$/, "");
58
- }
86
+ /**
87
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
88
+ * cross-plugin dependency references.
89
+ */
59
90
  const pluginRedocName = "plugin-redoc";
60
- const pluginRedoc = (0, _kubb_core.createPlugin)((options) => {
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/config'
99
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
100
+ *
101
+ * export default defineConfig({
102
+ * input: './petStore.yaml',
103
+ * output: { path: './src/gen' },
104
+ * plugins: [
105
+ * pluginRedoc({ output: { path: 'docs.html' } }),
106
+ * ],
107
+ * })
108
+ * ```
109
+ */
110
+ const pluginRedoc = (0, kubb_kit.definePlugin)((options) => {
61
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;
62
114
  return {
63
115
  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({
116
+ version,
117
+ options,
118
+ hooks: { async "kubb:plugin:setup"(ctx) {
119
+ ctx.setOptions({
120
+ output,
121
+ name,
122
+ exclude: [],
123
+ override: []
124
+ });
125
+ const adapter = ctx.config.adapter;
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.`);
127
+ const document = adapter.document;
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.`);
129
+ const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
130
+ const pageHTML = await getPageHTML(document);
131
+ ctx.injectFile({
75
132
  baseName: "docs.html",
76
133
  path: node_path.default.resolve(root, output.path || "./docs.html"),
77
- sources: [{
134
+ sources: [kubb_kit.ast.factory.createSource({
78
135
  name: "docs.html",
79
- value: pageHTML
80
- }],
81
- imports: [],
82
- exports: []
136
+ nodes: [kubb_kit.ast.factory.createText(pageHTML)]
137
+ })]
83
138
  });
84
- }
139
+ } }
85
140
  };
86
141
  });
87
142
  //#endregion
143
+ exports.default = pluginRedoc;
88
144
  exports.pluginRedoc = pluginRedoc;
89
145
  exports.pluginRedocName = pluginRedocName;
90
146
 
@@ -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":["path","adapterOasName","ast"],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\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']) {\n const pageTitle = escapeHtml(api.info.title || 'ReDoc documentation')\n const googleFont = `<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/kit'\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/config'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: './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.factory.createSource({\n name: 'docs.html',\n nodes: [ast.factory.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACEA,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;CAc7D,OAAO;;;;aAbW,WAAW,IAAI,KAAK,SAAS,qBAiB5B,EAAE;;;;;;;;;;;;;MAajB;;;;kBAxBY,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;MAwB/B;;;;AAIhB;;;;;;;AC3CA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,eAAA,GAAA,SAAA,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,SAAAA,IAAI,QAAQ,aAAa;KACvB,MAAM;KACN,OAAO,CAACA,SAAAA,IAAI,QAAQ,WAAW,QAAQ,CAAC;IAC1C,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,26 +1,63 @@
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";
5
-
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { Exclude, Include, Output, Override, PluginFactoryOptions } from "kubb/kit";
6
3
  //#region src/types.d.ts
7
4
  type Options = {
5
+ /**
6
+ * Output location of the generated Redoc HTML file. The path is resolved
7
+ * against the global `output.path` set on `defineConfig`.
8
+ */
8
9
  output?: {
9
10
  /**
10
- * Output for the generated doc, [https://redocly.com/](https://redocly.com/) is being used for the generation
11
+ * File path of the generated HTML, relative to the global `output.path`.
12
+ * Unlike most plugins, this points at a single file rather than a directory.
13
+ *
11
14
  * @default 'docs.html'
12
15
  */
13
16
  path: string;
14
17
  };
15
18
  };
16
19
  type ResolveOptions = {
17
- output: Output<Oas>;
20
+ output: Output;
21
+ name: string;
22
+ exclude: Array<Exclude>;
23
+ include?: Array<Include>;
24
+ override: Array<Override<ResolveOptions>>;
18
25
  };
19
- type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>;
26
+ type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions>;
27
+ declare global {
28
+ namespace Kubb {
29
+ interface PluginRegistry {
30
+ 'plugin-redoc': PluginRedoc;
31
+ }
32
+ }
33
+ }
20
34
  //#endregion
21
35
  //#region src/plugin.d.ts
36
+ /**
37
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
38
+ * cross-plugin dependency references.
39
+ */
22
40
  declare const pluginRedocName = "plugin-redoc";
23
- declare const pluginRedoc: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginRedoc>;
41
+ /**
42
+ * Generates a self-contained static HTML documentation page from your OpenAPI
43
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
44
+ * stay in lockstep with the spec the rest of your code is generated from.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { defineConfig } from 'kubb/config'
49
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
50
+ *
51
+ * export default defineConfig({
52
+ * input: './petStore.yaml',
53
+ * output: { path: './src/gen' },
54
+ * plugins: [
55
+ * pluginRedoc({ output: { path: 'docs.html' } }),
56
+ * ],
57
+ * })
58
+ * ```
59
+ */
60
+ declare const pluginRedoc: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginRedoc>;
24
61
  //#endregion
25
- export { type PluginRedoc, pluginRedoc, pluginRedocName };
62
+ export { type PluginRedoc, pluginRedoc as default, pluginRedoc, pluginRedocName };
26
63
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,18 +1,47 @@
1
- import "./chunk--u3MIqq1.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
2
  import path from "node:path";
3
- import { createPlugin } from "@kubb/core";
4
- import { pluginOasName } from "@kubb/plugin-oas";
5
- import fs from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
- import pkg from "handlebars";
3
+ import { adapterOasName } from "@kubb/adapter-oas";
4
+ import { ast, definePlugin } from "kubb/kit";
5
+ //#region package.json
6
+ var version = "5.0.0-beta.103";
7
+ //#endregion
8
8
  //#region src/redoc.tsx
9
- const __filename = fileURLToPath(import.meta.url);
10
- const __dirname = path.dirname(__filename);
11
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
12
- const templateFileName = path.join(__dirname, "../static/redoc.hbs");
13
- return pkg.compile(fs.readFileSync(templateFileName).toString())({
14
- title: title || api.info.title || "ReDoc documentation",
15
- 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) {
27
+ return `<html>
28
+
29
+ <head>
30
+ <meta charset='utf8' />
31
+ <title>${escapeHtml(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
+ <link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />
41
+ </head>
42
+
43
+ <body>
44
+ ${`
16
45
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
17
46
  <div id="redoc-container"></div>
18
47
  <script>
@@ -21,45 +50,70 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
21
50
  "expandResponses": "200,400"
22
51
  }, document.getElementById('redoc-container'))
23
52
  <\/script>
24
- `,
25
- disableGoogleFont,
26
- templateOptions
27
- });
53
+ `}
54
+ </body>
55
+
56
+ </html>`;
28
57
  }
29
58
  //#endregion
30
59
  //#region src/plugin.ts
31
- function trimExtName(text) {
32
- return text.replace(/\.[^/.]+$/, "");
33
- }
60
+ /**
61
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
62
+ * cross-plugin dependency references.
63
+ */
34
64
  const pluginRedocName = "plugin-redoc";
35
- const pluginRedoc = createPlugin((options) => {
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/config'
73
+ * import { pluginRedoc } from '@kubb/plugin-redoc'
74
+ *
75
+ * export default defineConfig({
76
+ * input: './petStore.yaml',
77
+ * output: { path: './src/gen' },
78
+ * plugins: [
79
+ * pluginRedoc({ output: { path: 'docs.html' } }),
80
+ * ],
81
+ * })
82
+ * ```
83
+ */
84
+ const pluginRedoc = definePlugin((options) => {
36
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;
37
88
  return {
38
89
  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({
90
+ version,
91
+ options,
92
+ hooks: { async "kubb:plugin:setup"(ctx) {
93
+ ctx.setOptions({
94
+ output,
95
+ name,
96
+ exclude: [],
97
+ override: []
98
+ });
99
+ const adapter = ctx.config.adapter;
100
+ 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.`);
101
+ const document = adapter.document;
102
+ 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.`);
103
+ const root = path.resolve(ctx.config.root, ctx.config.output.path);
104
+ const pageHTML = await getPageHTML(document);
105
+ ctx.injectFile({
50
106
  baseName: "docs.html",
51
107
  path: path.resolve(root, output.path || "./docs.html"),
52
- sources: [{
108
+ sources: [ast.factory.createSource({
53
109
  name: "docs.html",
54
- value: pageHTML
55
- }],
56
- imports: [],
57
- exports: []
110
+ nodes: [ast.factory.createText(pageHTML)]
111
+ })]
58
112
  });
59
- }
113
+ } }
60
114
  };
61
115
  });
62
116
  //#endregion
63
- export { pluginRedoc, pluginRedocName };
117
+ export { pluginRedoc as default, pluginRedoc, pluginRedocName };
64
118
 
65
119
  //# 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":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\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']) {\n const pageTitle = escapeHtml(api.info.title || 'ReDoc documentation')\n const googleFont = `<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/kit'\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/config'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: './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.factory.createSource({\n name: 'docs.html',\n nodes: [ast.factory.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;ACEA,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;CAc7D,OAAO;;;;aAbW,WAAW,IAAI,KAAK,SAAS,qBAiB5B,EAAE;;;;;;;;;;;;;MAajB;;;;kBAxBY,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;MAwB/B;;;;AAIhB;;;;;;;AC3CA,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,QAAQ,aAAa;KACvB,MAAM;KACN,OAAO,CAAC,IAAI,QAAQ,WAAW,QAAQ,CAAC;IAC1C,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
package/package.json CHANGED
@@ -1,29 +1,39 @@
1
1
  {
2
2
  "name": "@kubb/plugin-redoc",
3
- "version": "5.0.0-alpha.9",
4
- "description": "Redoc documentation generator plugin for Kubb, creating beautiful, interactive API documentation from OpenAPI specifications.",
3
+ "version": "5.0.0-beta.103",
4
+ "description": "Generate a ReDoc API reference page with Kubb. Produces a standalone HTML file you can host without a build step.",
5
5
  "keywords": [
6
- "redoc",
7
- "documentation",
8
6
  "api-docs",
9
- "openapi",
10
- "swagger",
11
- "interactive-docs",
12
- "typescript",
13
- "code-generator",
7
+ "api-reference",
8
+ "code-generation",
14
9
  "codegen",
15
- "plugins",
16
- "kubb"
10
+ "documentation",
11
+ "kubb",
12
+ "meta-framework",
13
+ "redoc",
14
+ "typescript"
17
15
  ],
16
+ "license": "MIT",
17
+ "author": "stijnvanhulle",
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "git+https://github.com/kubb-labs/kubb.git",
20
+ "url": "git+https://github.com/kubb-labs/plugins.git",
21
21
  "directory": "packages/plugin-redoc"
22
22
  },
23
- "license": "MIT",
24
- "author": "stijnvanhulle",
25
- "sideEffects": false,
23
+ "files": [
24
+ "dist",
25
+ "!/**/**.test.**",
26
+ "!/**/__tests__/**",
27
+ "!/**/__snapshots__/**"
28
+ ],
26
29
  "type": "module",
30
+ "sideEffects": false,
31
+ "main": "./dist/index.cjs",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "typesVersions": {
35
+ "*": {}
36
+ },
27
37
  "exports": {
28
38
  ".": {
29
39
  "import": "./dist/index.js",
@@ -31,53 +41,27 @@
31
41
  },
32
42
  "./package.json": "./package.json"
33
43
  },
34
- "types": "./dist/index.d.ts",
35
- "typesVersions": {
36
- "*": {}
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "registry": "https://registry.npmjs.org/"
37
47
  },
38
- "files": [
39
- "src",
40
- "dist",
41
- "static",
42
- "!/**/**.test.**",
43
- "!/**/__tests__/**",
44
- "!/**/__snapshots__/**"
45
- ],
46
- "size-limit": [
47
- {
48
- "path": "./dist/*.js",
49
- "limit": "510 KiB",
50
- "gzip": true
51
- }
52
- ],
53
48
  "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.9",
58
- "@kubb/oas": "5.0.0-alpha.9",
59
- "@kubb/plugin-oas": "5.0.0-alpha.9"
49
+ "@kubb/adapter-oas": "5.0.0-beta.103"
50
+ },
51
+ "devDependencies": {
52
+ "kubb": "5.0.0-beta.103"
60
53
  },
61
54
  "peerDependencies": {
62
- "@kubb/fabric-core": "0.14.0",
63
- "@kubb/react-fabric": "0.14.0"
55
+ "kubb": "5.0.0-beta.103"
64
56
  },
65
57
  "engines": {
66
58
  "node": ">=22"
67
59
  },
68
- "publishConfig": {
69
- "access": "public",
70
- "registry": "https://registry.npmjs.org/"
71
- },
72
- "main": "./dist/index.cjs",
73
- "module": "./dist/index.js",
74
60
  "scripts": {
75
- "build": "tsdown && size-limit",
76
- "clean": "npx rimraf ./dist",
77
- "lint": "bun biome lint .",
78
- "lint:fix": "bun biome lint --fix --unsafe .",
79
- "release": "pnpm publish --no-git-check",
80
- "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
61
+ "build": "tsdown",
62
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
63
+ "lint": "oxlint .",
64
+ "lint:fix": "oxlint --fix .",
81
65
  "start": "tsdown --watch",
82
66
  "test": "vitest --passWithNoTests",
83
67
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { pluginRedoc, pluginRedocName } from './plugin.ts'
2
- export type { PluginRedoc } from './types.ts'
package/src/plugin.ts DELETED
@@ -1,44 +0,0 @@
1
- import path from 'node:path'
2
- import { createPlugin } from '@kubb/core'
3
- import { pluginOasName } from '@kubb/plugin-oas'
4
- import { getPageHTML } from './redoc.tsx'
5
- import type { PluginRedoc } from './types.ts'
6
-
7
- function trimExtName(text: string): string {
8
- return text.replace(/\.[^/.]+$/, '')
9
- }
10
-
11
- export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
12
-
13
- export const pluginRedoc = createPlugin<PluginRedoc>((options) => {
14
- const { output = { path: 'docs.html' } } = options
15
-
16
- return {
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
- })
42
- },
43
- }
44
- })
package/src/redoc.tsx DELETED
@@ -1,34 +0,0 @@
1
- import fs from 'node:fs'
2
- import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
- import type { OasTypes } from '@kubb/oas'
5
- import pkg from 'handlebars'
6
-
7
- const __filename = fileURLToPath(import.meta.url)
8
- const __dirname = path.dirname(__filename)
9
-
10
- type BuildDocsOptions = {
11
- title?: string
12
- disableGoogleFont?: boolean
13
- templateOptions?: any
14
- }
15
-
16
- export async function getPageHTML(api: OasTypes.OASDocument, { 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: `
22
- <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
23
- <div id="redoc-container"></div>
24
- <script>
25
- const data = ${JSON.stringify(api, null, 2)};
26
- Redoc.init(data, {
27
- "expandResponses": "200,400"
28
- }, document.getElementById('redoc-container'))
29
- </script>
30
- `,
31
- disableGoogleFont,
32
- templateOptions,
33
- })
34
- }
package/src/types.ts DELETED
@@ -1,18 +0,0 @@
1
- import type { Output, PluginFactoryOptions } from '@kubb/core'
2
- import type { Oas } from '@kubb/oas'
3
-
4
- export type Options = {
5
- output?: {
6
- /**
7
- * Output for the generated doc, [https://redocly.com/](https://redocly.com/) is being used for the generation
8
- * @default 'docs.html'
9
- */
10
- path: string
11
- }
12
- }
13
-
14
- type ResolveOptions = {
15
- output: Output<Oas>
16
- }
17
-
18
- export type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions, never>
package/static/redoc.hbs DELETED
@@ -1,22 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
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>
17
-
18
- <body>
19
- {{{redocHTML}}}
20
- </body>
21
-
22
- </html>