@kubb/plugin-redoc 5.0.3 → 5.0.5
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 +2 -2
- package/dist/index.cjs +31 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +32 -31
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[![Node][node-src]][node-href]
|
|
11
11
|
|
|
12
12
|
<h4>
|
|
13
|
-
<a href="https://kubb.dev/plugins/redoc" target="_blank">Documentation</a>
|
|
13
|
+
<a href="https://kubb.dev/plugins/plugin-redoc" target="_blank">Documentation</a>
|
|
14
14
|
<span> · </span>
|
|
15
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
16
16
|
<span> · </span>
|
|
@@ -38,7 +38,7 @@ npm install @kubb/plugin-redoc
|
|
|
38
38
|
|
|
39
39
|
## Documentation
|
|
40
40
|
|
|
41
|
-
See the [full documentation](https://kubb.dev/plugins/redoc) for configuration options and examples.
|
|
41
|
+
See the [full documentation](https://kubb.dev/plugins/plugin-redoc) for configuration options and examples.
|
|
42
42
|
|
|
43
43
|
## Supporting Kubb
|
|
44
44
|
|
package/dist/index.cjs
CHANGED
|
@@ -29,7 +29,7 @@ node_path = __toESM(node_path, 1);
|
|
|
29
29
|
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
30
30
|
let kubb_kit = require("kubb/kit");
|
|
31
31
|
//#region package.json
|
|
32
|
-
var version = "5.0.
|
|
32
|
+
var version = "5.0.5";
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region src/redoc.tsx
|
|
35
35
|
const htmlEscapes = {
|
|
@@ -107,37 +107,38 @@ const pluginRedocName = "plugin-redoc";
|
|
|
107
107
|
* })
|
|
108
108
|
* ```
|
|
109
109
|
*/
|
|
110
|
-
const pluginRedoc = (0, kubb_kit.definePlugin)(
|
|
111
|
-
|
|
112
|
-
const extname = node_path.default.extname(output.path);
|
|
113
|
-
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
114
|
-
return {
|
|
110
|
+
const pluginRedoc = (0, kubb_kit.definePlugin)({
|
|
111
|
+
meta: {
|
|
115
112
|
name: pluginRedocName,
|
|
116
113
|
version,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
114
|
+
compatibility: { kubb: ">=5.8.0" }
|
|
115
|
+
},
|
|
116
|
+
async setup(options) {
|
|
117
|
+
const config = (0, kubb_kit.useConfig)();
|
|
118
|
+
const { output = { path: "docs.html" } } = options;
|
|
119
|
+
const extname = node_path.default.extname(output.path);
|
|
120
|
+
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
121
|
+
const adapter = config.adapter;
|
|
122
|
+
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.`);
|
|
123
|
+
const document = adapter.document;
|
|
124
|
+
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.`);
|
|
125
|
+
const root = node_path.default.resolve(config.root, config.output.path);
|
|
126
|
+
const pageHTML = await getPageHTML(document);
|
|
127
|
+
(0, kubb_kit.injectFile)({
|
|
128
|
+
baseName: "docs.html",
|
|
129
|
+
path: node_path.default.resolve(root, output.path || "./docs.html"),
|
|
130
|
+
sources: [kubb_kit.ast.factory.createSource({
|
|
131
|
+
name: "docs.html",
|
|
132
|
+
nodes: [kubb_kit.ast.factory.createText(pageHTML)]
|
|
133
|
+
})]
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
output,
|
|
137
|
+
name,
|
|
138
|
+
exclude: [],
|
|
139
|
+
override: []
|
|
140
|
+
};
|
|
141
|
+
}
|
|
141
142
|
});
|
|
142
143
|
//#endregion
|
|
143
144
|
exports.default = pluginRedoc;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["definePlugin","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 '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n '=': '=',\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)
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["definePlugin","useConfig","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 '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n '=': '=',\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, injectFile, useConfig } 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>({\n meta: { name: pluginRedocName, version, compatibility: { kubb: '>=5.8.0' } },\n async setup(options) {\n const config = useConfig()\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 const adapter = 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(config.root, config.output.path)\n const pageHTML = await getPageHTML(document)\n\n 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 return { output, name, exclude: [], override: [] }\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,GAAcA,SAAAA,aAAAA,CAA0B;CACnD,MAAM;EAAE,MAAM;EAAiB;EAAS,eAAe,EAAE,MAAM,UAAU;CAAE;CAC3E,MAAM,MAAM,SAAS;EACnB,MAAM,UAAA,GAASC,SAAAA,UAAAA,CAAU;EACzB,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;EAC3C,MAAM,UAAUC,UAAAA,QAAK,QAAQ,OAAO,IAAI;EACxC,MAAM,OAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAI,OAAO;EAEtE,MAAM,UAAU,OAAO;EAEvB,IAAI,SAAS,SAASC,kBAAAA,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;EAGF,MAAM,WAAY,QAAgC;EAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;EAGF,MAAM,OAAOD,UAAAA,QAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,IAAI;EACzD,MAAM,WAAW,MAAM,YAAY,QAAQ;EAE3C,CAAA,GAAA,SAAA,WAAA,CAAW;GACT,UAAU;GACV,MAAMA,UAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;GACrD,SAAS,CACPE,SAAAA,IAAI,QAAQ,aAAa;IACvB,MAAM;IACN,OAAO,CAACA,SAAAA,IAAI,QAAQ,WAAW,QAAQ,CAAC;GAC1C,CAAC,CACH;EACF,CAAC;EAED,OAAO;GAAE;GAAQ;GAAM,SAAS,CAAC;GAAG,UAAU,CAAC;EAAE;CACnD;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export declare const pluginRedocName = "plugin-redoc";
|
|
|
57
57
|
* })
|
|
58
58
|
* ```
|
|
59
59
|
*/
|
|
60
|
-
export declare const pluginRedoc:
|
|
60
|
+
export declare const pluginRedoc: import("kubb/kit").PluginFactory<PluginRedoc>;
|
|
61
61
|
//#endregion
|
|
62
62
|
export { type PluginRedoc, pluginRedoc as default };
|
|
63
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
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/kit";
|
|
4
|
+
import { ast, definePlugin, injectFile, useConfig } from "kubb/kit";
|
|
5
5
|
//#region package.json
|
|
6
|
-
var version = "5.0.
|
|
6
|
+
var version = "5.0.5";
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/redoc.tsx
|
|
9
9
|
const htmlEscapes = {
|
|
@@ -81,37 +81,38 @@ const pluginRedocName = "plugin-redoc";
|
|
|
81
81
|
* })
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
|
-
const pluginRedoc = definePlugin(
|
|
85
|
-
|
|
86
|
-
const extname = path.extname(output.path);
|
|
87
|
-
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
88
|
-
return {
|
|
84
|
+
const pluginRedoc = definePlugin({
|
|
85
|
+
meta: {
|
|
89
86
|
name: pluginRedocName,
|
|
90
87
|
version,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
88
|
+
compatibility: { kubb: ">=5.8.0" }
|
|
89
|
+
},
|
|
90
|
+
async setup(options) {
|
|
91
|
+
const config = useConfig();
|
|
92
|
+
const { output = { path: "docs.html" } } = options;
|
|
93
|
+
const extname = path.extname(output.path);
|
|
94
|
+
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
95
|
+
const adapter = config.adapter;
|
|
96
|
+
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.`);
|
|
97
|
+
const document = adapter.document;
|
|
98
|
+
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.`);
|
|
99
|
+
const root = path.resolve(config.root, config.output.path);
|
|
100
|
+
const pageHTML = await getPageHTML(document);
|
|
101
|
+
injectFile({
|
|
102
|
+
baseName: "docs.html",
|
|
103
|
+
path: path.resolve(root, output.path || "./docs.html"),
|
|
104
|
+
sources: [ast.factory.createSource({
|
|
105
|
+
name: "docs.html",
|
|
106
|
+
nodes: [ast.factory.createText(pageHTML)]
|
|
107
|
+
})]
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
output,
|
|
111
|
+
name,
|
|
112
|
+
exclude: [],
|
|
113
|
+
override: []
|
|
114
|
+
};
|
|
115
|
+
}
|
|
115
116
|
});
|
|
116
117
|
//#endregion
|
|
117
118
|
export { pluginRedoc as default, pluginRedoc, pluginRedocName };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n '=': '=',\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)
|
|
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 '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n '`': '`',\n '=': '=',\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, injectFile, useConfig } 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>({\n meta: { name: pluginRedocName, version, compatibility: { kubb: '>=5.8.0' } },\n async setup(options) {\n const config = useConfig()\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 const adapter = 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(config.root, config.output.path)\n const pageHTML = await getPageHTML(document)\n\n 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 return { output, name, exclude: [], override: [] }\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,aAA0B;CACnD,MAAM;EAAE,MAAM;EAAiB;EAAS,eAAe,EAAE,MAAM,UAAU;CAAE;CAC3E,MAAM,MAAM,SAAS;EACnB,MAAM,SAAS,UAAU;EACzB,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;EAC3C,MAAM,UAAU,KAAK,QAAQ,OAAO,IAAI;EACxC,MAAM,OAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAI,OAAO;EAEtE,MAAM,UAAU,OAAO;EAEvB,IAAI,SAAS,SAAS,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;EAGF,MAAM,WAAY,QAAgC;EAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;EAGF,MAAM,OAAO,KAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,IAAI;EACzD,MAAM,WAAW,MAAM,YAAY,QAAQ;EAE3C,WAAW;GACT,UAAU;GACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;GACrD,SAAS,CACP,IAAI,QAAQ,aAAa;IACvB,MAAM;IACN,OAAO,CAAC,IAAI,QAAQ,WAAW,QAAQ,CAAC;GAC1C,CAAC,CACH;EACF,CAAC;EAED,OAAO;GAAE;GAAQ;GAAM,SAAS,CAAC;GAAG,UAAU,CAAC;EAAE;CACnD;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.5",
|
|
4
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",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"registry": "https://registry.npmjs.org/"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@kubb/adapter-oas": "^5.
|
|
65
|
+
"@kubb/adapter-oas": "^5.8.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"kubb": "^5.
|
|
68
|
+
"kubb": "^5.8.0"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"kubb": "^5.
|
|
71
|
+
"kubb": "^5.8.0"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
74
|
"node": ">=22"
|
|
@@ -76,10 +76,7 @@
|
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "tsdown",
|
|
78
78
|
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
79
|
-
"lint": "oxlint .",
|
|
80
|
-
"lint:fix": "oxlint --fix .",
|
|
81
79
|
"start": "tsdown --watch",
|
|
82
|
-
"
|
|
83
|
-
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
80
|
+
"typecheck": "tsc"
|
|
84
81
|
}
|
|
85
82
|
}
|