@kubb/plugin-redoc 5.0.9 → 5.0.12
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/dist/index.cjs +21 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +1 -6
- package/dist/index.js +23 -19
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +13 -8
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.cjs
CHANGED
|
@@ -31,13 +31,13 @@ let kubb_kit = require("kubb/kit");
|
|
|
31
31
|
//#region kubb-extension.json
|
|
32
32
|
var compatibility = {
|
|
33
33
|
"kubb": ">=5.8.3",
|
|
34
|
-
"node": ">=22"
|
|
34
|
+
"node": ">=22.12"
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region package.json
|
|
38
|
-
var version = "5.0.
|
|
38
|
+
var version = "5.0.12";
|
|
39
39
|
//#endregion
|
|
40
|
-
//#region src/redoc.
|
|
40
|
+
//#region src/redoc.ts
|
|
41
41
|
const htmlEscapes = {
|
|
42
42
|
"&": "&",
|
|
43
43
|
"<": "<",
|
|
@@ -81,7 +81,7 @@ const redocBundle = {
|
|
|
81
81
|
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
82
82
|
* the generated file works without further build steps.
|
|
83
83
|
*/
|
|
84
|
-
|
|
84
|
+
function getPageHTML(api) {
|
|
85
85
|
return `<html>
|
|
86
86
|
|
|
87
87
|
<head>
|
|
@@ -149,28 +149,32 @@ const pluginRedoc = (0, kubb_kit.defineExtension)({
|
|
|
149
149
|
async setup(options) {
|
|
150
150
|
const config = (0, kubb_kit.useConfig)();
|
|
151
151
|
const { output = { path: "docs.html" } } = options;
|
|
152
|
-
const extname = node_path.default.extname(output.path);
|
|
153
|
-
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
154
152
|
const adapter = config.adapter;
|
|
155
|
-
if (adapter?.name !== _kubb_adapter_oas.adapterOasName) throw new Error(
|
|
153
|
+
if (adapter?.name !== _kubb_adapter_oas.adapterOasName) throw new kubb_kit.Diagnostics.Error({
|
|
154
|
+
code: kubb_kit.Diagnostics.code.adapterRequired,
|
|
155
|
+
severity: "error",
|
|
156
|
+
message: `Plugin "${pluginRedocName}" requires the OpenAPI adapter, but the config uses ${adapter ? `"${adapter.name}"` : "no adapter"}.`,
|
|
157
|
+
help: "Set `adapter: adapterOas()` in kubb.config.ts.",
|
|
158
|
+
location: { kind: "config" },
|
|
159
|
+
plugin: pluginRedocName
|
|
160
|
+
});
|
|
156
161
|
const document = adapter.document;
|
|
157
|
-
if (!document) throw new Error(
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
if (!document) throw new kubb_kit.Diagnostics.Error({
|
|
163
|
+
code: kubb_kit.Diagnostics.code.pluginFailed,
|
|
164
|
+
severity: "error",
|
|
165
|
+
message: `No OpenAPI document found. \`adapterOas\` did not produce a document before ${pluginRedocName} ran.`,
|
|
166
|
+
plugin: pluginRedocName
|
|
167
|
+
});
|
|
168
|
+
const pageHTML = getPageHTML(document);
|
|
160
169
|
(0, kubb_kit.injectFile)({
|
|
161
170
|
baseName: "docs.html",
|
|
162
|
-
path: node_path.default.resolve(root, output.path || "./docs.html"),
|
|
171
|
+
path: node_path.default.resolve(config.root, config.output.path, output.path || "./docs.html"),
|
|
163
172
|
sources: [kubb_kit.ast.factory.createSource({
|
|
164
173
|
name: "docs.html",
|
|
165
174
|
nodes: [kubb_kit.ast.factory.createText(pageHTML)]
|
|
166
175
|
})]
|
|
167
176
|
});
|
|
168
|
-
return {
|
|
169
|
-
output,
|
|
170
|
-
name,
|
|
171
|
-
exclude: [],
|
|
172
|
-
override: []
|
|
173
|
-
};
|
|
177
|
+
return { output };
|
|
174
178
|
}
|
|
175
179
|
});
|
|
176
180
|
//#endregion
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["defineExtension","useConfig","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["defineExtension","useConfig","adapterOasName","Diagnostics","path","ast"],"sources":["../kubb-extension.json","../package.json","../src/redoc.ts","../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\nconst scriptEscapes: Record<string, string> = {\n '<': '\\\\u003c',\n '>': '\\\\u003e',\n '&': '\\\\u0026',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n}\n\n/**\n * Serializes `value` as JSON that is safe to inline in a `<script>` tag.\n * JSON only allows these characters inside strings, where the `\\uXXXX` escapes\n * parse back to the same value, so a spec string such as `</script>` can no\n * longer close the tag early.\n */\nfunction toScriptJSON(value: unknown) {\n return JSON.stringify(value, null, 2).replace(/[<>&\\u2028\\u2029]/g, (char) => scriptEscapes[char] ?? char)\n}\n\n/**\n * Redoc bundle the page loads, pinned to one release with a Subresource\n * Integrity hash so a changed or compromised CDN file does not run. When\n * bumping the version, recompute the hash from the npm tarball:\n * `openssl dgst -sha384 -binary package/bundles/redoc.standalone.js | openssl base64 -A`.\n */\nconst redocBundle = {\n src: 'https://cdn.jsdelivr.net/npm/redoc@2.5.4/bundles/redoc.standalone.js',\n integrity: 'sha384-w447zOpYfw/1Tv/5AK9NfHTlQIqE3RVR6KY62jCyy9zNDgO64cMwGGP1Fj0zJVf5',\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 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=\"${redocBundle.src}\" integrity=\"${redocBundle.integrity}\" crossorigin=\"anonymous\"></script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${toScriptJSON(api)};\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, defineExtension, Diagnostics, injectFile, useConfig } from 'kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.ts'\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 = defineExtension<PluginRedoc>({\n kind: 'plugin',\n meta: { name: pluginRedocName, version, compatibility },\n async setup(options) {\n const config = useConfig()\n const { output = { path: 'docs.html' } } = options\n\n const adapter = config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.adapterRequired,\n severity: 'error',\n message: `Plugin \"${pluginRedocName}\" requires the OpenAPI adapter, but the config uses ${adapter ? `\"${adapter.name}\"` : 'no adapter'}.`,\n help: 'Set `adapter: adapterOas()` in kubb.config.ts.',\n location: { kind: 'config' },\n plugin: pluginRedocName,\n })\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.pluginFailed,\n severity: 'error',\n message: `No OpenAPI document found. \\`adapterOas\\` did not produce a document before ${pluginRedocName} ran.`,\n plugin: pluginRedocName,\n })\n }\n\n const pageHTML = getPageHTML(document)\n\n injectFile({\n baseName: 'docs.html',\n path: path.resolve(config.root, config.output.path, 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 }\n },\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AEEA,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;AAEA,MAAM,gBAAwC;CAC5C,KAAK;CACL,KAAK;CACL,KAAK;CACL,UAAU;CACV,UAAU;AACZ;;;;;;;AAQA,SAAS,aAAa,OAAgB;CACpC,OAAO,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC,CAAC,QAAQ,uBAAuB,SAAS,cAAc,SAAS,IAAI;AAC3G;;;;;;;AAQA,MAAM,cAAc;CAClB,KAAK;CACL,WAAW;AACb;;;;;;AAOA,SAAgB,YAAY,KAA6B;CAcvD,OAAO;;;;aAbW,WAAW,IAAI,KAAK,SAAS,qBAiB5B,EA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58 @@
|
|
|
1
|
+
import { Output, PluginType } from "kubb/kit";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
type Options = {
|
|
4
|
+
/**
|
|
5
|
+
* Output location of the generated Redoc HTML file. The path is resolved
|
|
6
|
+
* against the global `output.path` set on `defineConfig`.
|
|
7
|
+
*/
|
|
8
|
+
output?: {
|
|
9
|
+
/**
|
|
10
|
+
* File path of the generated HTML, relative to the global `output.path`.
|
|
11
|
+
* Unlike most plugins, this points at a single file rather than a directory.
|
|
12
|
+
*
|
|
13
|
+
* @default 'docs.html'
|
|
14
|
+
*/
|
|
15
|
+
path: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
type ResolveOptions = {
|
|
19
|
+
output: Output;
|
|
20
|
+
};
|
|
21
|
+
type PluginRedoc = PluginType<'plugin-redoc', Options, ResolveOptions>;
|
|
22
|
+
declare global {
|
|
23
|
+
namespace Kubb {
|
|
24
|
+
interface PluginRegistry {
|
|
25
|
+
'plugin-redoc': PluginRedoc;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/plugin.d.ts
|
|
31
|
+
/**
|
|
32
|
+
* Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
|
|
33
|
+
* cross-plugin dependency references.
|
|
34
|
+
*/
|
|
35
|
+
export declare const pluginRedocName = "plugin-redoc";
|
|
36
|
+
/**
|
|
37
|
+
* Generates a self-contained static HTML documentation page from your OpenAPI
|
|
38
|
+
* spec using Redoc. The file is regenerated on every Kubb build, so the docs
|
|
39
|
+
* stay in lockstep with the spec the rest of your code is generated from.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { defineConfig } from 'kubb/config'
|
|
44
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
45
|
+
*
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* input: './petStore.yaml',
|
|
48
|
+
* output: { path: './src/gen' },
|
|
49
|
+
* plugins: [
|
|
50
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
51
|
+
* ],
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const pluginRedoc: import("kubb/kit").PluginFactory<PluginRedoc>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { type PluginRedoc, pluginRedoc as default };
|
|
58
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Exclude, Include, Output, Override, PluginType } from "kubb/kit";
|
|
1
|
+
import { Output, PluginType } from "kubb/kit";
|
|
3
2
|
//#region src/types.d.ts
|
|
4
3
|
type Options = {
|
|
5
4
|
/**
|
|
@@ -18,10 +17,6 @@ type Options = {
|
|
|
18
17
|
};
|
|
19
18
|
type ResolveOptions = {
|
|
20
19
|
output: Output;
|
|
21
|
-
name: string;
|
|
22
|
-
exclude: Array<Exclude>;
|
|
23
|
-
include?: Array<Include>;
|
|
24
|
-
override: Array<Override<ResolveOptions>>;
|
|
25
20
|
};
|
|
26
21
|
type PluginRedoc = PluginType<'plugin-redoc', Options, ResolveOptions>;
|
|
27
22
|
declare global {
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
1
|
import path from "node:path";
|
|
3
2
|
import { adapterOasName } from "@kubb/adapter-oas";
|
|
4
|
-
import { ast, defineExtension, injectFile, useConfig } from "kubb/kit";
|
|
3
|
+
import { Diagnostics, ast, defineExtension, injectFile, useConfig } from "kubb/kit";
|
|
4
|
+
//#endregion
|
|
5
5
|
//#region kubb-extension.json
|
|
6
6
|
var compatibility = {
|
|
7
7
|
"kubb": ">=5.8.3",
|
|
8
|
-
"node": ">=22"
|
|
8
|
+
"node": ">=22.12"
|
|
9
9
|
};
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "5.0.
|
|
12
|
+
var version = "5.0.12";
|
|
13
13
|
//#endregion
|
|
14
|
-
//#region src/redoc.
|
|
14
|
+
//#region src/redoc.ts
|
|
15
15
|
const htmlEscapes = {
|
|
16
16
|
"&": "&",
|
|
17
17
|
"<": "<",
|
|
@@ -55,7 +55,7 @@ const redocBundle = {
|
|
|
55
55
|
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
56
56
|
* the generated file works without further build steps.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
function getPageHTML(api) {
|
|
59
59
|
return `<html>
|
|
60
60
|
|
|
61
61
|
<head>
|
|
@@ -123,28 +123,32 @@ const pluginRedoc = defineExtension({
|
|
|
123
123
|
async setup(options) {
|
|
124
124
|
const config = useConfig();
|
|
125
125
|
const { output = { path: "docs.html" } } = options;
|
|
126
|
-
const extname = path.extname(output.path);
|
|
127
|
-
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
128
126
|
const adapter = config.adapter;
|
|
129
|
-
if (adapter?.name !== adapterOasName) throw new Error(
|
|
127
|
+
if (adapter?.name !== adapterOasName) throw new Diagnostics.Error({
|
|
128
|
+
code: Diagnostics.code.adapterRequired,
|
|
129
|
+
severity: "error",
|
|
130
|
+
message: `Plugin "${pluginRedocName}" requires the OpenAPI adapter, but the config uses ${adapter ? `"${adapter.name}"` : "no adapter"}.`,
|
|
131
|
+
help: "Set `adapter: adapterOas()` in kubb.config.ts.",
|
|
132
|
+
location: { kind: "config" },
|
|
133
|
+
plugin: pluginRedocName
|
|
134
|
+
});
|
|
130
135
|
const document = adapter.document;
|
|
131
|
-
if (!document) throw new Error(
|
|
132
|
-
|
|
133
|
-
|
|
136
|
+
if (!document) throw new Diagnostics.Error({
|
|
137
|
+
code: Diagnostics.code.pluginFailed,
|
|
138
|
+
severity: "error",
|
|
139
|
+
message: `No OpenAPI document found. \`adapterOas\` did not produce a document before ${pluginRedocName} ran.`,
|
|
140
|
+
plugin: pluginRedocName
|
|
141
|
+
});
|
|
142
|
+
const pageHTML = getPageHTML(document);
|
|
134
143
|
injectFile({
|
|
135
144
|
baseName: "docs.html",
|
|
136
|
-
path: path.resolve(root, output.path || "./docs.html"),
|
|
145
|
+
path: path.resolve(config.root, config.output.path, output.path || "./docs.html"),
|
|
137
146
|
sources: [ast.factory.createSource({
|
|
138
147
|
name: "docs.html",
|
|
139
148
|
nodes: [ast.factory.createText(pageHTML)]
|
|
140
149
|
})]
|
|
141
150
|
});
|
|
142
|
-
return {
|
|
143
|
-
output,
|
|
144
|
-
name,
|
|
145
|
-
exclude: [],
|
|
146
|
-
override: []
|
|
147
|
-
};
|
|
151
|
+
return { output };
|
|
148
152
|
}
|
|
149
153
|
});
|
|
150
154
|
//#endregion
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../kubb-extension.json","../package.json","../src/redoc.
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../kubb-extension.json","../package.json","../src/redoc.ts","../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\nconst scriptEscapes: Record<string, string> = {\n '<': '\\\\u003c',\n '>': '\\\\u003e',\n '&': '\\\\u0026',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n}\n\n/**\n * Serializes `value` as JSON that is safe to inline in a `<script>` tag.\n * JSON only allows these characters inside strings, where the `\\uXXXX` escapes\n * parse back to the same value, so a spec string such as `</script>` can no\n * longer close the tag early.\n */\nfunction toScriptJSON(value: unknown) {\n return JSON.stringify(value, null, 2).replace(/[<>&\\u2028\\u2029]/g, (char) => scriptEscapes[char] ?? char)\n}\n\n/**\n * Redoc bundle the page loads, pinned to one release with a Subresource\n * Integrity hash so a changed or compromised CDN file does not run. When\n * bumping the version, recompute the hash from the npm tarball:\n * `openssl dgst -sha384 -binary package/bundles/redoc.standalone.js | openssl base64 -A`.\n */\nconst redocBundle = {\n src: 'https://cdn.jsdelivr.net/npm/redoc@2.5.4/bundles/redoc.standalone.js',\n integrity: 'sha384-w447zOpYfw/1Tv/5AK9NfHTlQIqE3RVR6KY62jCyy9zNDgO64cMwGGP1Fj0zJVf5',\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 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=\"${redocBundle.src}\" integrity=\"${redocBundle.integrity}\" crossorigin=\"anonymous\"></script>\n <div id=\"redoc-container\"></div>\n <script>\n const data = ${toScriptJSON(api)};\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, defineExtension, Diagnostics, injectFile, useConfig } from 'kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\nimport { version } from '../package.json'\nimport { getPageHTML } from './redoc.ts'\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 = defineExtension<PluginRedoc>({\n kind: 'plugin',\n meta: { name: pluginRedocName, version, compatibility },\n async setup(options) {\n const config = useConfig()\n const { output = { path: 'docs.html' } } = options\n\n const adapter = config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.adapterRequired,\n severity: 'error',\n message: `Plugin \"${pluginRedocName}\" requires the OpenAPI adapter, but the config uses ${adapter ? `\"${adapter.name}\"` : 'no adapter'}.`,\n help: 'Set `adapter: adapterOas()` in kubb.config.ts.',\n location: { kind: 'config' },\n plugin: pluginRedocName,\n })\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Diagnostics.Error({\n code: Diagnostics.code.pluginFailed,\n severity: 'error',\n message: `No OpenAPI document found. \\`adapterOas\\` did not produce a document before ${pluginRedocName} ran.`,\n plugin: pluginRedocName,\n })\n }\n\n const pageHTML = getPageHTML(document)\n\n injectFile({\n baseName: 'docs.html',\n path: path.resolve(config.root, config.output.path, 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 }\n },\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;AEEA,MAAM,cAAsC;CAC1C,KAAK;CACL,KAAK;CACL,K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gBAAgB;GACxG,QAAQ;EACV,CAAC;EAGH,MAAM,WAAW,YAAY,QAAQ;EAErC,WAAW;GACT,UAAU;GACV,MAAM,KAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAM,OAAO,QAAQ,aAAa;GAChF,SAAS,CACP,IAAI,QAAQ,aAAa;IACvB,MAAM;IACN,OAAO,CAAC,IAAI,QAAQ,WAAW,QAAQ,CAAC;GAC1C,CAAC,CACH;EACF,CAAC;EAED,OAAO,EAAE,OAAO;CAClB;AACF,CAAC"}
|
package/kubb-extension.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.12",
|
|
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",
|
|
@@ -53,9 +53,14 @@
|
|
|
53
53
|
},
|
|
54
54
|
"exports": {
|
|
55
55
|
".": {
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
"import": {
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"default": "./dist/index.js"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/index.d.cts",
|
|
62
|
+
"default": "./dist/index.cjs"
|
|
63
|
+
}
|
|
59
64
|
},
|
|
60
65
|
"./package.json": "./package.json",
|
|
61
66
|
"./kubb-extension.json": "./kubb-extension.json"
|
|
@@ -65,16 +70,16 @@
|
|
|
65
70
|
"registry": "https://registry.npmjs.org/"
|
|
66
71
|
},
|
|
67
72
|
"dependencies": {
|
|
68
|
-
"@kubb/adapter-oas": "^5.
|
|
73
|
+
"@kubb/adapter-oas": "^5.10.3"
|
|
69
74
|
},
|
|
70
75
|
"devDependencies": {
|
|
71
|
-
"kubb": "^5.
|
|
76
|
+
"kubb": "^5.10.3"
|
|
72
77
|
},
|
|
73
78
|
"peerDependencies": {
|
|
74
|
-
"kubb": "^5.
|
|
79
|
+
"kubb": "^5.10.3"
|
|
75
80
|
},
|
|
76
81
|
"engines": {
|
|
77
|
-
"node": ">=22"
|
|
82
|
+
"node": ">=22.12"
|
|
78
83
|
},
|
|
79
84
|
"scripts": {
|
|
80
85
|
"build": "tsdown",
|