@kubb/plugin-redoc 5.0.0-beta.10 → 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/README.md CHANGED
@@ -1,18 +1,15 @@
1
1
  <div align="center">
2
- <h1>@kubb/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/plugins/tree/main/examples/typescript" target="_blank">View Demo</a>
15
- <span> · </span>
16
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>
@@ -21,13 +18,13 @@
21
18
  </h4>
22
19
  </div>
23
20
 
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.
21
+ <br />
22
+
23
+ # @kubb/plugin-redoc
25
24
 
26
- ## Features
25
+ ### Generate a ReDoc API reference with Kubb
27
26
 
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
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.
31
28
 
32
29
  ## Installation
33
30
 
@@ -45,7 +42,7 @@ See the [full documentation](https://kubb.dev/plugins/redoc) for configuration o
45
42
 
46
43
  ## Supporting Kubb
47
44
 
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:
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:
49
46
 
50
47
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
51
48
 
@@ -55,19 +52,19 @@ Kubb is an MIT-licensed open source project with its ongoing development made po
55
52
  </a>
56
53
  </p>
57
54
 
55
+ ## License
56
+
57
+ [MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
58
+
58
59
  <!-- Badges -->
59
60
 
60
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
61
- [npm-version-href]: https://npmjs.com/package/@kubb/plugin-redoc
62
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
63
- [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-redoc
64
- [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
65
68
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
66
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
67
- [build-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
68
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
69
- [minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
70
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
71
- [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
72
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
73
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
69
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
70
+ [node-href]: https://npmx.dev/package/@kubb/plugin-redoc
package/dist/index.cjs CHANGED
@@ -25,43 +25,49 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
  //#endregion
27
27
  let node_path = require("node:path");
28
- let node_path$1 = __toESM(node_path, 1);
29
- node_path = __toESM(node_path);
28
+ node_path = __toESM(node_path, 1);
30
29
  let _kubb_adapter_oas = require("@kubb/adapter-oas");
31
- let _kubb_core = require("@kubb/core");
32
- let node_fs = require("node:fs");
33
- node_fs = __toESM(node_fs);
34
- let node_url = require("node:url");
35
- let handlebars = require("handlebars");
36
- handlebars = __toESM(handlebars);
37
- //#region ../../internals/utils/src/string.ts
38
- /**
39
- * Strips the file extension from a path or file name.
40
- * Only removes the last `.ext` segment when the dot is not part of a directory name.
41
- *
42
- * @example
43
- * trimExtName('petStore.ts') // 'petStore'
44
- * trimExtName('/src/models/pet.ts') // '/src/models/pet'
45
- * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
46
- * trimExtName('noExtension') // 'noExtension'
47
- */
48
- function trimExtName(text) {
49
- const dotIndex = text.lastIndexOf(".");
50
- if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
51
- return text;
52
- }
53
- //#endregion
30
+ let kubb_kit = require("kubb/kit");
54
31
  //#region package.json
55
- var version = "5.0.0-beta.10";
32
+ var version = "5.0.0-beta.103";
56
33
  //#endregion
57
34
  //#region src/redoc.tsx
58
- const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
59
- const __dirname$1 = node_path.default.dirname(__filename$1);
60
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
61
- const templateFileName = node_path.default.join(__dirname$1, "../static/redoc.hbs");
62
- return handlebars.default.compile(node_fs.default.readFileSync(templateFileName).toString())({
63
- title: title || api.info.title || "ReDoc documentation",
64
- redocHTML: `
35
+ const htmlEscapes = {
36
+ "&": "&amp;",
37
+ "<": "&lt;",
38
+ ">": "&gt;",
39
+ "\"": "&quot;",
40
+ "'": "&#x27;",
41
+ "`": "&#x60;",
42
+ "=": "&#x3D;"
43
+ };
44
+ function escapeHtml(value) {
45
+ return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
46
+ }
47
+ /**
48
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
49
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
50
+ * the generated file works without further build steps.
51
+ */
52
+ async function getPageHTML(api) {
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
+ ${`
65
71
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
66
72
  <div id="redoc-container"></div>
67
73
  <script>
@@ -70,16 +76,41 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
70
76
  "expandResponses": "200,400"
71
77
  }, document.getElementById('redoc-container'))
72
78
  <\/script>
73
- `,
74
- disableGoogleFont,
75
- templateOptions
76
- });
79
+ `}
80
+ </body>
81
+
82
+ </html>`;
77
83
  }
78
84
  //#endregion
79
85
  //#region src/plugin.ts
86
+ /**
87
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
88
+ * cross-plugin dependency references.
89
+ */
80
90
  const pluginRedocName = "plugin-redoc";
81
- const pluginRedoc = (0, _kubb_core.definePlugin)((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) => {
82
111
  const { output = { path: "docs.html" } } = options;
112
+ const extname = node_path.default.extname(output.path);
113
+ const name = extname ? output.path.slice(0, -extname.length) : output.path;
83
114
  return {
84
115
  name: pluginRedocName,
85
116
  version,
@@ -87,7 +118,7 @@ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
87
118
  hooks: { async "kubb:plugin:setup"(ctx) {
88
119
  ctx.setOptions({
89
120
  output,
90
- name: trimExtName(output.path),
121
+ name,
91
122
  exclude: [],
92
123
  override: []
93
124
  });
@@ -95,14 +126,14 @@ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
95
126
  if (adapter?.name !== _kubb_adapter_oas.adapterOasName) throw new Error(`[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \`adapter: adapterOas()\`) in your Kubb config.`);
96
127
  const document = adapter.document;
97
128
  if (!document) throw new Error(`[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`);
98
- const root = node_path$1.default.resolve(ctx.config.root, ctx.config.output.path);
129
+ const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
99
130
  const pageHTML = await getPageHTML(document);
100
131
  ctx.injectFile({
101
132
  baseName: "docs.html",
102
- path: node_path$1.default.resolve(root, output.path || "./docs.html"),
103
- sources: [_kubb_core.ast.createSource({
133
+ path: node_path.default.resolve(root, output.path || "./docs.html"),
134
+ sources: [kubb_kit.ast.factory.createSource({
104
135
  name: "docs.html",
105
- nodes: [_kubb_core.ast.createText(pageHTML)]
136
+ nodes: [kubb_kit.ast.factory.createText(pageHTML)]
106
137
  })]
107
138
  });
108
139
  } }
@@ -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;CACtC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,SAAS,EAC/C,OAAO,KAAK,MAAM,GAAG,SAAS;CAEhC,OAAO;;;;;;;AE5DT,MAAMA,gBAAAA,G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AS,CAAC;KAClC,CAAC,CACH;IACF,CAAC;KAEL;EACF;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["path","adapterOasName","ast"],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\n\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,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AAA,IAAI,QAAQ,WAAW,QAAQ,CAAC;IAC1C,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _$_kubb_core0 from "@kubb/core";
3
- import { Exclude, Include, Output, Override, PluginFactoryOptions } from "@kubb/core";
4
-
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { Exclude, Include, Output, Override, PluginFactoryOptions } from "kubb/kit";
5
3
  //#region src/types.d.ts
6
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
+ */
7
9
  output?: {
8
10
  /**
9
- * Output path for the generated HTML documentation.
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.
10
13
  *
11
14
  * @default 'docs.html'
12
15
  */
@@ -14,7 +17,7 @@ type Options = {
14
17
  };
15
18
  };
16
19
  type ResolveOptions = {
17
- output: Output<never>;
20
+ output: Output;
18
21
  name: string;
19
22
  exclude: Array<Exclude>;
20
23
  include?: Array<Include>;
@@ -30,8 +33,31 @@ declare global {
30
33
  }
31
34
  //#endregion
32
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
+ */
33
40
  declare const pluginRedocName = "plugin-redoc";
34
- declare const pluginRedoc: (options?: Options | undefined) => _$_kubb_core0.Plugin<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>;
35
61
  //#endregion
36
62
  export { type PluginRedoc, pluginRedoc as default, pluginRedoc, pluginRedocName };
37
63
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,38 +1,47 @@
1
- import "./chunk--u3MIqq1.js";
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
2
  import path from "node:path";
3
3
  import { adapterOasName } from "@kubb/adapter-oas";
4
- import { ast, definePlugin } from "@kubb/core";
5
- import fs from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
- import pkg from "handlebars";
8
- //#region ../../internals/utils/src/string.ts
9
- /**
10
- * Strips the file extension from a path or file name.
11
- * Only removes the last `.ext` segment when the dot is not part of a directory name.
12
- *
13
- * @example
14
- * trimExtName('petStore.ts') // 'petStore'
15
- * trimExtName('/src/models/pet.ts') // '/src/models/pet'
16
- * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
17
- * trimExtName('noExtension') // 'noExtension'
18
- */
19
- function trimExtName(text) {
20
- const dotIndex = text.lastIndexOf(".");
21
- if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
22
- return text;
23
- }
24
- //#endregion
4
+ import { ast, definePlugin } from "kubb/kit";
25
5
  //#region package.json
26
- var version = "5.0.0-beta.10";
6
+ var version = "5.0.0-beta.103";
27
7
  //#endregion
28
8
  //#region src/redoc.tsx
29
- const __filename = fileURLToPath(import.meta.url);
30
- const __dirname = path.dirname(__filename);
31
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
32
- const templateFileName = path.join(__dirname, "../static/redoc.hbs");
33
- return pkg.compile(fs.readFileSync(templateFileName).toString())({
34
- title: title || api.info.title || "ReDoc documentation",
35
- redocHTML: `
9
+ const htmlEscapes = {
10
+ "&": "&amp;",
11
+ "<": "&lt;",
12
+ ">": "&gt;",
13
+ "\"": "&quot;",
14
+ "'": "&#x27;",
15
+ "`": "&#x60;",
16
+ "=": "&#x3D;"
17
+ };
18
+ function escapeHtml(value) {
19
+ return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
20
+ }
21
+ /**
22
+ * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
23
+ * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
24
+ * the generated file works without further build steps.
25
+ */
26
+ async function getPageHTML(api) {
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
+ ${`
36
45
  <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
37
46
  <div id="redoc-container"></div>
38
47
  <script>
@@ -41,16 +50,41 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
41
50
  "expandResponses": "200,400"
42
51
  }, document.getElementById('redoc-container'))
43
52
  <\/script>
44
- `,
45
- disableGoogleFont,
46
- templateOptions
47
- });
53
+ `}
54
+ </body>
55
+
56
+ </html>`;
48
57
  }
49
58
  //#endregion
50
59
  //#region src/plugin.ts
60
+ /**
61
+ * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
62
+ * cross-plugin dependency references.
63
+ */
51
64
  const pluginRedocName = "plugin-redoc";
65
+ /**
66
+ * Generates a self-contained static HTML documentation page from your OpenAPI
67
+ * spec using Redoc. The file is regenerated on every Kubb build, so the docs
68
+ * stay in lockstep with the spec the rest of your code is generated from.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { defineConfig } from 'kubb/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
+ */
52
84
  const pluginRedoc = definePlugin((options) => {
53
85
  const { output = { path: "docs.html" } } = options;
86
+ const extname = path.extname(output.path);
87
+ const name = extname ? output.path.slice(0, -extname.length) : output.path;
54
88
  return {
55
89
  name: pluginRedocName,
56
90
  version,
@@ -58,7 +92,7 @@ const pluginRedoc = definePlugin((options) => {
58
92
  hooks: { async "kubb:plugin:setup"(ctx) {
59
93
  ctx.setOptions({
60
94
  output,
61
- name: trimExtName(output.path),
95
+ name,
62
96
  exclude: [],
63
97
  override: []
64
98
  });
@@ -71,9 +105,9 @@ const pluginRedoc = definePlugin((options) => {
71
105
  ctx.injectFile({
72
106
  baseName: "docs.html",
73
107
  path: path.resolve(root, output.path || "./docs.html"),
74
- sources: [ast.createSource({
108
+ sources: [ast.factory.createSource({
75
109
  name: "docs.html",
76
- nodes: [ast.createText(pageHTML)]
110
+ nodes: [ast.factory.createText(pageHTML)]
77
111
  })]
78
112
  });
79
113
  } }
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,M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AAO,CAAC,IAAI,WAAW,SAAS,CAAC;KAClC,CAAC,CACH;IACF,CAAC;KAEL;EACF;EACD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\n\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,K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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kubb/plugin-redoc",
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.",
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
6
  "api-docs",
7
7
  "api-reference",
@@ -9,9 +9,8 @@
9
9
  "codegen",
10
10
  "documentation",
11
11
  "kubb",
12
- "openapi",
12
+ "meta-framework",
13
13
  "redoc",
14
- "swagger",
15
14
  "typescript"
16
15
  ],
17
16
  "license": "MIT",
@@ -22,10 +21,7 @@
22
21
  "directory": "packages/plugin-redoc"
23
22
  },
24
23
  "files": [
25
- "src",
26
24
  "dist",
27
- "static",
28
- "extension.yaml",
29
25
  "!/**/**.test.**",
30
26
  "!/**/__tests__/**",
31
27
  "!/**/__snapshots__/**"
@@ -50,30 +46,22 @@
50
46
  "registry": "https://registry.npmjs.org/"
51
47
  },
52
48
  "dependencies": {
53
- "@kubb/adapter-oas": "5.0.0-beta.10",
54
- "@kubb/core": "5.0.0-beta.10",
55
- "handlebars": "^4.7.9"
49
+ "@kubb/adapter-oas": "5.0.0-beta.103"
56
50
  },
57
51
  "devDependencies": {
58
- "@internals/utils": "0.0.0"
52
+ "kubb": "5.0.0-beta.103"
53
+ },
54
+ "peerDependencies": {
55
+ "kubb": "5.0.0-beta.103"
59
56
  },
60
- "size-limit": [
61
- {
62
- "path": "./dist/*.js",
63
- "limit": "510 KiB",
64
- "gzip": true
65
- }
66
- ],
67
57
  "engines": {
68
58
  "node": ">=22"
69
59
  },
70
60
  "scripts": {
71
- "build": "tsdown && size-limit",
72
- "clean": "npx rimraf ./dist",
61
+ "build": "tsdown",
62
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
73
63
  "lint": "oxlint .",
74
64
  "lint:fix": "oxlint --fix .",
75
- "release": "pnpm publish --no-git-check",
76
- "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
77
65
  "start": "tsdown --watch",
78
66
  "test": "vitest --passWithNoTests",
79
67
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
package/extension.yaml DELETED
@@ -1,67 +0,0 @@
1
- $schema: https://kubb.dev/schemas/extension.json
2
- kind: plugin
3
- id: plugin-redoc
4
- name: Redoc
5
- description: Generate API documentation with Redoc from OpenAPI specifications.
6
- category: documentation
7
- type: official
8
- npmPackage: '@kubb/plugin-redoc'
9
- docsPath: /plugins/plugin-redoc
10
- repo: https://github.com/kubb-labs/plugins
11
- maintainers:
12
- - name: Stijn Van Hulle
13
- github: stijnvanhulle
14
- compatibility:
15
- kubb: '>=5.0.0'
16
- node: '>=22'
17
- tags:
18
- - redoc
19
- - api-docs
20
- - documentation
21
- - interactive-docs
22
- - codegen
23
- - openapi
24
- dependencies: []
25
- resources:
26
- documentation: https://kubb.dev/plugins/plugin-redoc
27
- repository: https://github.com/kubb-labs/plugins
28
- issues: https://github.com/kubb-labs/plugins/issues
29
- changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-redoc/CHANGELOG.md
30
- codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/simple-single
31
- featured: false
32
- icon:
33
- light: https://kubb.dev/feature/openapi.svg
34
- intro: |
35
- Generate interactive API documentation from your OpenAPI schema using [Redoc](https://redocly.com/).
36
- options:
37
- - name: output
38
- type: '{ path: string }'
39
- required: false
40
- description: Specify the output path for the generated documentation HTML file.
41
- properties:
42
- - name: path
43
- type: string
44
- required: true
45
- description: |
46
- The output file path for the generated documentation HTML.
47
- tip: |
48
- if `output.path` is a file, `group` cannot be used.
49
- default: "'docs.html'"
50
- examples:
51
- - name: kubb.config.ts
52
- files:
53
- - lang: typescript
54
- code: |
55
- import { defineConfig } from 'kubb'
56
- import { pluginRedoc } from '@kubb/plugin-redoc'
57
-
58
- export default defineConfig({
59
- input: { path: './petStore.yaml' },
60
- output: { path: './src/gen' },
61
- plugins: [
62
- pluginRedoc({
63
- output: { path: 'docs.html' },
64
- }),
65
- ],
66
- })
67
- twoslash: false
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { default, pluginRedoc, pluginRedocName } from './plugin.ts'
2
- export type { PluginRedoc } from './types.ts'
package/src/plugin.ts DELETED
@@ -1,63 +0,0 @@
1
- import path from 'node:path'
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'
8
- import { getPageHTML } from './redoc.tsx'
9
- import type { PluginRedoc } from './types.ts'
10
-
11
- export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
12
-
13
- export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
14
- const { output = { path: 'docs.html' } } = options
15
-
16
- return {
17
- name: pluginRedocName,
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
- },
59
- },
60
- }
61
- })
62
-
63
- export default pluginRedoc
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 { AdapterOas } from '@kubb/adapter-oas'
5
- import pkg from 'handlebars'
6
-
7
- const __filename = fileURLToPath(import.meta.url)
8
- const __dirname = path.dirname(__filename)
9
-
10
- type BuildDocsOptions = {
11
- title?: string
12
- disableGoogleFont?: boolean
13
- templateOptions?: any
14
- }
15
-
16
- export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
17
- const templateFileName = path.join(__dirname, '../static/redoc.hbs')
18
- const template = pkg.compile(fs.readFileSync(templateFileName).toString())
19
- return template({
20
- title: title || api.info.title || 'ReDoc documentation',
21
- redocHTML: `
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,30 +0,0 @@
1
- import type { Exclude, Include, Output, Override, PluginFactoryOptions } from '@kubb/core'
2
-
3
- export type Options = {
4
- output?: {
5
- /**
6
- * Output path for the generated HTML documentation.
7
- *
8
- * @default 'docs.html'
9
- */
10
- path: string
11
- }
12
- }
13
-
14
- type ResolveOptions = {
15
- output: Output<never>
16
- name: string
17
- exclude: Array<Exclude>
18
- include?: Array<Include>
19
- override: Array<Override<ResolveOptions>>
20
- }
21
-
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 DELETED
@@ -1,21 +0,0 @@
1
- <html>
2
-
3
- <head>
4
- <meta charset='utf8' />
5
- <title>{{title}}</title>
6
- <!-- needed for adaptive design -->
7
- <meta name='viewport' content='width=device-width, initial-scale=1' />
8
- <style>
9
- body {
10
- padding: 0;
11
- margin: 0;
12
- }
13
- </style>
14
- {{#unless disableGoogleFont}}<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />{{/unless}}
15
- </head>
16
-
17
- <body>
18
- {{{redocHTML}}}
19
- </body>
20
-
21
- </html>