@kubb/plugin-redoc 5.2.0-canary.20261029T093900 → 5.2.0
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 +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -26,14 +26,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
let node_path = require("node:path");
|
|
27
27
|
node_path = __toESM(node_path, 1);
|
|
28
28
|
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
29
|
-
let
|
|
29
|
+
let _kubb_kit = require("@kubb/kit");
|
|
30
30
|
// kubb-extension.json
|
|
31
31
|
var compatibility = {
|
|
32
32
|
"kubb": ">=5.8.3",
|
|
33
33
|
"node": ">=22.22"
|
|
34
34
|
};
|
|
35
35
|
// package.json
|
|
36
|
-
var version = "5.2.0
|
|
36
|
+
var version = "5.2.0";
|
|
37
37
|
// src/redoc.ts
|
|
38
38
|
const htmlEscapes = {
|
|
39
39
|
"&": "&",
|
|
@@ -135,7 +135,7 @@ const pluginRedocName = "plugin-redoc";
|
|
|
135
135
|
* })
|
|
136
136
|
* ```
|
|
137
137
|
*/
|
|
138
|
-
const pluginRedoc = (0,
|
|
138
|
+
const pluginRedoc = (0, _kubb_kit.defineExtension)({
|
|
139
139
|
kind: "plugin",
|
|
140
140
|
meta: {
|
|
141
141
|
name: pluginRedocName,
|
|
@@ -143,11 +143,11 @@ const pluginRedoc = (0, kubb_kit.defineExtension)({
|
|
|
143
143
|
compatibility
|
|
144
144
|
},
|
|
145
145
|
async setup(options) {
|
|
146
|
-
const config = (0,
|
|
146
|
+
const config = (0, _kubb_kit.useConfig)();
|
|
147
147
|
const { output = { path: "docs.html" } } = options;
|
|
148
148
|
const adapter = config.adapter;
|
|
149
|
-
if (adapter?.name !== _kubb_adapter_oas.adapterOasName) throw new
|
|
150
|
-
code:
|
|
149
|
+
if (adapter?.name !== _kubb_adapter_oas.adapterOasName) throw new _kubb_kit.Diagnostics.Error({
|
|
150
|
+
code: _kubb_kit.Diagnostics.code.adapterRequired,
|
|
151
151
|
severity: "error",
|
|
152
152
|
message: `Plugin "${pluginRedocName}" requires the OpenAPI adapter, but the config uses ${adapter ? `"${adapter.name}"` : "no adapter"}.`,
|
|
153
153
|
help: "Set `adapter: adapterOas()` in kubb.config.ts.",
|
|
@@ -155,19 +155,19 @@ const pluginRedoc = (0, kubb_kit.defineExtension)({
|
|
|
155
155
|
plugin: pluginRedocName
|
|
156
156
|
});
|
|
157
157
|
const document = adapter.document;
|
|
158
|
-
if (!document) throw new
|
|
159
|
-
code:
|
|
158
|
+
if (!document) throw new _kubb_kit.Diagnostics.Error({
|
|
159
|
+
code: _kubb_kit.Diagnostics.code.pluginFailed,
|
|
160
160
|
severity: "error",
|
|
161
161
|
message: `No OpenAPI document found. \`adapterOas\` did not produce a document before ${pluginRedocName} ran.`,
|
|
162
162
|
plugin: pluginRedocName
|
|
163
163
|
});
|
|
164
164
|
const pageHTML = getPageHTML(document);
|
|
165
|
-
(0,
|
|
165
|
+
(0, _kubb_kit.injectFile)({
|
|
166
166
|
baseName: "docs.html",
|
|
167
167
|
path: node_path.default.resolve(config.root, config.output.path, output.path || "./docs.html"),
|
|
168
|
-
sources: [
|
|
168
|
+
sources: [_kubb_kit.ast.factory.createSource({
|
|
169
169
|
name: "docs.html",
|
|
170
|
-
nodes: [
|
|
170
|
+
nodes: [_kubb_kit.ast.factory.createText(pageHTML)]
|
|
171
171
|
})]
|
|
172
172
|
});
|
|
173
173
|
return { output };
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EAAE;;;;;;;;;;;;;MAajB;oBA3Bc,YAAY,IAAI,eAAe,YAAY,UAAU;;;kBAGvD,aAAa,GAAG,EAAE;;;;;MAwBpB;;;;AAIhB;;;;;;ACvEA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,eAAA,GAAcA,
|
|
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,WAA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/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output, PluginType } from "kubb/kit";
|
|
1
|
+
import { Output, PluginType } from "@kubb/kit";
|
|
2
2
|
type Options = {
|
|
3
3
|
/**
|
|
4
4
|
* Output location of the generated Redoc HTML file. The path is resolved
|
|
@@ -49,6 +49,6 @@ export declare const pluginRedocName = "plugin-redoc";
|
|
|
49
49
|
* })
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
|
-
export declare const pluginRedoc: import("kubb/kit").PluginFactory<PluginRedoc>;
|
|
52
|
+
export declare const pluginRedoc: import("@kubb/kit").PluginFactory<PluginRedoc>;
|
|
53
53
|
export { type PluginRedoc, pluginRedoc as default };
|
|
54
54
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Output, PluginType } from "kubb/kit";
|
|
1
|
+
import { Output, PluginType } from "@kubb/kit";
|
|
2
2
|
type Options = {
|
|
3
3
|
/**
|
|
4
4
|
* Output location of the generated Redoc HTML file. The path is resolved
|
|
@@ -49,6 +49,6 @@ export declare const pluginRedocName = "plugin-redoc";
|
|
|
49
49
|
* })
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
|
-
export declare const pluginRedoc: import("kubb/kit").PluginFactory<PluginRedoc>;
|
|
52
|
+
export declare const pluginRedoc: import("@kubb/kit").PluginFactory<PluginRedoc>;
|
|
53
53
|
export { type PluginRedoc, pluginRedoc as default };
|
|
54
54
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { adapterOasName } from "@kubb/adapter-oas";
|
|
3
|
-
import { Diagnostics, ast, defineExtension, injectFile, useConfig } from "kubb/kit";
|
|
3
|
+
import { Diagnostics, ast, defineExtension, injectFile, useConfig } from "@kubb/kit";
|
|
4
4
|
// kubb-extension.json
|
|
5
5
|
var compatibility = {
|
|
6
6
|
"kubb": ">=5.8.3",
|
|
7
7
|
"node": ">=22.22"
|
|
8
8
|
};
|
|
9
9
|
// package.json
|
|
10
|
-
var version = "5.2.0
|
|
10
|
+
var version = "5.2.0";
|
|
11
11
|
// src/redoc.ts
|
|
12
12
|
const htmlEscapes = {
|
|
13
13
|
"&": "&",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,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,SA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
{"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,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,EAAE;;;;;;;;;;;;;MAajB;oBA3Bc,YAAY,IAAI,eAAe,YAAY,UAAU;;;kBAGvD,aAAa,GAAG,EAAE;;;;;MAwBpB;;;;AAIhB;;;;;;ACvEA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,cAAc,gBAA6B;CACtD,MAAM;CACN,MAAM;EAAE,MAAM;EAAiB;EAAS;CAAc;CACtD,MAAM,MAAM,SAAS;EACnB,MAAM,SAAS,UAAU;EACzB,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;EAE3C,MAAM,UAAU,OAAO;EAEvB,IAAI,SAAS,SAAS,gBACpB,MAAM,IAAI,YAAY,MAAM;GAC1B,MAAM,YAAY,KAAK;GACvB,UAAU;GACV,SAAS,WAAW,gBAAgB,sDAAsD,UAAU,IAAI,QAAQ,KAAK,KAAK,aAAa;GACvI,MAAM;GACN,UAAU,EAAE,MAAM,SAAS;GAC3B,QAAQ;EACV,CAAC;EAGH,MAAM,WAAY,QAAgC;EAElD,IAAI,CAAC,UACH,MAAM,IAAI,YAAY,MAAM;GAC1B,MAAM,YAAY,KAAK;GACvB,UAAU;GACV,SAAS,+EAA+E,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.2.0
|
|
3
|
+
"version": "5.2.0",
|
|
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",
|
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
"registry": "https://registry.npmjs.org/"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@kubb/
|
|
73
|
+
"@kubb/kit": "^5.15.2"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"kubb": "^5.15.
|
|
76
|
+
"@kubb/adapter-oas": "^5.15.2"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"kubb": "^5.15.
|
|
79
|
+
"@kubb/adapter-oas": "^5.15.2"
|
|
80
80
|
},
|
|
81
81
|
"engines": {
|
|
82
82
|
"node": ">=22.22"
|