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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,9 +5,9 @@
5
5
 
6
6
  [![npm version][npm-version-src]][npm-version-href]
7
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
8
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
9
9
  [![License][license-src]][license-href]
10
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Node][node-src]][node-href]
11
11
 
12
12
  <h4>
13
13
  <a href="https://kubb.dev/plugins/redoc" target="_blank">Documentation</a>
@@ -58,17 +58,13 @@ Kubb is an open source project, and its development is funded entirely by sponso
58
58
 
59
59
  <!-- Badges -->
60
60
 
61
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
62
- [npm-version-href]: https://npmjs.com/package/@kubb/plugin-redoc
63
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-redoc?flat&colorA=18181B&colorB=f58517
64
- [npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-redoc
65
- [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
66
68
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
67
- [build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
68
- [build-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
69
- [minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
70
- [minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
71
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
72
- [coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
73
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
74
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
69
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
70
+ [node-href]: https://npmx.dev/package/@kubb/plugin-redoc
package/dist/index.cjs CHANGED
@@ -31,7 +31,6 @@ let _kubb_adapter_oas = require("@kubb/adapter-oas");
31
31
  let _kubb_core = require("@kubb/core");
32
32
  let node_fs = require("node:fs");
33
33
  node_fs = __toESM(node_fs);
34
- let node_url = require("node:url");
35
34
  let handlebars = require("handlebars");
36
35
  handlebars = __toESM(handlebars);
37
36
  //#region ../../internals/utils/src/string.ts
@@ -52,18 +51,16 @@ function trimExtName(text) {
52
51
  }
53
52
  //#endregion
54
53
  //#region package.json
55
- var version = "5.0.0-beta.36";
54
+ var version = "5.0.0-beta.42";
56
55
  //#endregion
57
56
  //#region src/redoc.tsx
58
- const __filename$1 = (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href);
59
- const __dirname$1 = node_path.default.dirname(__filename$1);
60
57
  /**
61
58
  * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
62
59
  * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
63
60
  * the generated file works without further build steps.
64
61
  */
65
62
  async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
66
- const templateFileName = node_path.default.join(__dirname$1, "../static/redoc.hbs");
63
+ const templateFileName = node_path.default.join(__dirname, "../static/redoc.hbs");
67
64
  return handlebars.default.compile(node_fs.default.readFileSync(templateFileName).toString())({
68
65
  title: title || api.info.title || "ReDoc documentation",
69
66
  redocHTML: `
@@ -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\n/**\n * Renders a self-contained Redoc HTML page for an OpenAPI document. The page\n * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so\n * the generated file works without further build steps.\n */\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\n/**\n * Generates a self-contained static HTML documentation page from your OpenAPI\n * spec using Redoc. The file is regenerated on every Kubb build, so the docs\n * stay in lockstep with the spec the rest of your code is generated from.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginRedoc({ output: { path: 'docs.html' } }),\n * ],\n * })\n * ```\n */\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,GAAG;CACrC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E3C,IAAI,WAAW;IACb,UAAU;IACV,MAAMA,YAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACPC,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAW,QAAQ,CAAC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"index.cjs","names":["path","pkg","fs","adapterOasName","path","ast"],"sources":["../../../internals/utils/src/string.ts","../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\n/**\n * Renders a self-contained Redoc HTML page for an OpenAPI document. The page\n * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so\n * the generated file works without further build steps.\n */\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(import.meta.dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\n/**\n * Generates a self-contained static HTML documentation page from your OpenAPI\n * spec using Redoc. The file is regenerated on every Kubb build, so the docs\n * stay in lockstep with the spec the rest of your code is generated from.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginRedoc({ output: { path: 'docs.html' } }),\n * ],\n * })\n * ```\n */\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,GAAG;CACrC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,QAAQ,GAC9C,OAAO,KAAK,MAAM,GAAG,QAAQ;CAE/B,OAAO;AACT;;;;;;;;;;;AEnDA,eAAsB,YAAY,KAA6B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
3
  import { adapterOasName } from "@kubb/adapter-oas";
4
4
  import { ast, definePlugin } from "@kubb/core";
5
5
  import fs from "node:fs";
6
- import { fileURLToPath } from "node:url";
7
6
  import pkg from "handlebars";
8
7
  //#region ../../internals/utils/src/string.ts
9
8
  /**
@@ -23,18 +22,16 @@ function trimExtName(text) {
23
22
  }
24
23
  //#endregion
25
24
  //#region package.json
26
- var version = "5.0.0-beta.36";
25
+ var version = "5.0.0-beta.42";
27
26
  //#endregion
28
27
  //#region src/redoc.tsx
29
- const __filename = fileURLToPath(import.meta.url);
30
- const __dirname = path.dirname(__filename);
31
28
  /**
32
29
  * Renders a self-contained Redoc HTML page for an OpenAPI document. The page
33
30
  * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
34
31
  * the generated file works without further build steps.
35
32
  */
36
33
  async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
37
- const templateFileName = path.join(__dirname, "../static/redoc.hbs");
34
+ const templateFileName = path.join(import.meta.dirname, "../static/redoc.hbs");
38
35
  return pkg.compile(fs.readFileSync(templateFileName).toString())({
39
36
  title: title || api.info.title || "ReDoc documentation",
40
37
  redocHTML: `
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\n/**\n * Renders a self-contained Redoc HTML page for an OpenAPI document. The page\n * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so\n * the generated file works without further build steps.\n */\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\n/**\n * Generates a self-contained static HTML documentation page from your OpenAPI\n * spec using Redoc. The file is regenerated on every Kubb build, so the docs\n * stay in lockstep with the spec the rest of your code is generated from.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginRedoc({ output: { path: 'docs.html' } }),\n * ],\n * })\n * ```\n */\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;AA6DA,SAAgB,YAAY,MAAsB;CAChD,MAAM,WAAW,KAAK,YAAY,GAAG;CACrC,IAAI,WAAW,KAAK,CAAC,KAAK,SAAS,KAAK,QAAQ,GAC9C,OAAO,KAAK,MAAM,GAAG,QAAQ;CAE/B,OAAO;AACT;;;;;;AE7DA,MAAM,aAAa,cAAc,OAAO,KAAK,GAAG;AAChD,MAAM,YAAY,KAAK,QAAQ,UAAU;;;;;;AAazC,eAAsB,YAAY,KAA6B,EAAE,OAAO,mBAAmB,oBAAsC,CAAC,GAAG;CACnI,MAAM,mBAAmB,KAAK,KAAK,WAAW,qBAAqB;CAEnE,OADiB,IAAI,QAAQ,GAAG,aAAa,gBAAgB,EAAE,SAAS,CAC1D,EAAE;EACd,OAAO,SAAS,IAAI,KAAK,SAAS;EAClC,WAAW;;;;kBAIG,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;;EAM3C;EACA;CACF,CAAC;AACH;;;;;;;ACxBA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,cAAc,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAE3C,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA,MAAM,YAAY,OAAO,IAAI;IAC7B,SAAS,CAAC;IACV,UAAU,CAAC;GACb,CAAC;GAED,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAAS,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;GAGF,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;GAGF,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,WAAW,MAAM,YAAY,QAAQ;GAE3C,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACP,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAW,QAAQ,CAAC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/string.ts","../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["/**\n * Strips a single matching pair of `\"...\"`, `'...'`, or `` `...` `` from both ends of `text`.\n * Returns the string unchanged when no balanced quote pair is found.\n *\n * @example\n * trimQuotes('\"hello\"') // 'hello'\n * trimQuotes('hello') // 'hello'\n */\nexport function trimQuotes(text: string): string {\n if (text.length >= 2) {\n const first = text[0]\n const last = text[text.length - 1]\n if ((first === '\"' && last === '\"') || (first === \"'\" && last === \"'\") || (first === '`' && last === '`')) {\n return text.slice(1, -1)\n }\n }\n return text\n}\n\n/**\n * Escapes characters that are not allowed inside JS string literals.\n * Handles quotes, backslashes, and Unicode line terminators (U+2028 / U+2029).\n *\n * @see http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4\n *\n * @example\n * ```ts\n * jsStringEscape('say \"hi\"\\nbye') // 'say \\\\\"hi\\\\\"\\\\nbye'\n * ```\n */\nexport function jsStringEscape(input: unknown): string {\n return `${input}`.replace(/[\"'\\\\\\n\\r\\u2028\\u2029]/g, (character) => {\n switch (character) {\n case '\"':\n case \"'\":\n case '\\\\':\n return `\\\\${character}`\n case '\\n':\n return '\\\\n'\n case '\\r':\n return '\\\\r'\n case '\\u2028':\n return '\\\\u2028'\n case '\\u2029':\n return '\\\\u2029'\n default:\n return ''\n }\n })\n}\n\n/**\n * Strips the file extension from a path or file name.\n * Only removes the last `.ext` segment when the dot is not part of a directory name.\n *\n * @example\n * trimExtName('petStore.ts') // 'petStore'\n * trimExtName('/src/models/pet.ts') // '/src/models/pet'\n * trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'\n * trimExtName('noExtension') // 'noExtension'\n */\nexport function trimExtName(text: string): string {\n const dotIndex = text.lastIndexOf('.')\n if (dotIndex > 0 && !text.includes('/', dotIndex)) {\n return text.slice(0, dotIndex)\n }\n return text\n}\n","","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\n/**\n * Renders a self-contained Redoc HTML page for an OpenAPI document. The page\n * embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so\n * the generated file works without further build steps.\n */\nexport async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(import.meta.dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n redocHTML: `\n <script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"> </script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${JSON.stringify(api, null, 2)};\n Redoc.init(data, {\n \"expandResponses\": \"200,400\"\n }, document.getElementById('redoc-container'))\n </script>\n `,\n disableGoogleFont,\n templateOptions,\n })\n}\n","import path from 'node:path'\nimport { trimExtName } from '@internals/utils'\nimport type { AdapterOas } from '@kubb/adapter-oas'\nimport { adapterOasName } from '@kubb/adapter-oas'\n\nimport { type Adapter, ast, definePlugin } from '@kubb/core'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\n/**\n * Generates a self-contained static HTML documentation page from your OpenAPI\n * spec using Redoc. The file is regenerated on every Kubb build, so the docs\n * stay in lockstep with the spec the rest of your code is generated from.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginRedoc({ output: { path: 'docs.html' } }),\n * ],\n * })\n * ```\n */\nexport const pluginRedoc = definePlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name: trimExtName(output.path),\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;AA6DA,SAAgB,YAAY,MAAsB;CAChD,MAAM,W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AC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-redoc",
3
- "version": "5.0.0-beta.36",
3
+ "version": "5.0.0-beta.42",
4
4
  "description": "Generate a beautiful, interactive ReDoc API reference page from your OpenAPI specification. Produces a standalone HTML file with a responsive, developer-friendly UI.",
5
5
  "keywords": [
6
6
  "api-docs",
@@ -50,8 +50,8 @@
50
50
  "registry": "https://registry.npmjs.org/"
51
51
  },
52
52
  "dependencies": {
53
- "@kubb/adapter-oas": "5.0.0-beta.36",
54
- "@kubb/core": "5.0.0-beta.36",
53
+ "@kubb/adapter-oas": "5.0.0-beta.42",
54
+ "@kubb/core": "5.0.0-beta.42",
55
55
  "handlebars": "^4.7.9"
56
56
  },
57
57
  "devDependencies": {
package/src/redoc.tsx CHANGED
@@ -1,12 +1,8 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
3
  import type { AdapterOas } from '@kubb/adapter-oas'
5
4
  import pkg from 'handlebars'
6
5
 
7
- const __filename = fileURLToPath(import.meta.url)
8
- const __dirname = path.dirname(__filename)
9
-
10
6
  type BuildDocsOptions = {
11
7
  title?: string
12
8
  disableGoogleFont?: boolean
@@ -19,7 +15,7 @@ type BuildDocsOptions = {
19
15
  * the generated file works without further build steps.
20
16
  */
21
17
  export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
22
- const templateFileName = path.join(__dirname, '../static/redoc.hbs')
18
+ const templateFileName = path.join(import.meta.dirname, '../static/redoc.hbs')
23
19
  const template = pkg.compile(fs.readFileSync(templateFileName).toString())
24
20
  return template({
25
21
  title: title || api.info.title || 'ReDoc documentation',