@kubb/plugin-redoc 5.0.7 → 5.0.9
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 +29 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -3
- package/dist/index.js.map +1 -1
- package/docs/overview.md +7 -10
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var compatibility = {
|
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region package.json
|
|
38
|
-
var version = "5.0.
|
|
38
|
+
var version = "5.0.9";
|
|
39
39
|
//#endregion
|
|
40
40
|
//#region src/redoc.tsx
|
|
41
41
|
const htmlEscapes = {
|
|
@@ -50,6 +50,32 @@ const htmlEscapes = {
|
|
|
50
50
|
function escapeHtml(value) {
|
|
51
51
|
return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
|
|
52
52
|
}
|
|
53
|
+
const scriptEscapes = {
|
|
54
|
+
"<": "\\u003c",
|
|
55
|
+
">": "\\u003e",
|
|
56
|
+
"&": "\\u0026",
|
|
57
|
+
"\u2028": "\\u2028",
|
|
58
|
+
"\u2029": "\\u2029"
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Serializes `value` as JSON that is safe to inline in a `<script>` tag.
|
|
62
|
+
* JSON only allows these characters inside strings, where the `\uXXXX` escapes
|
|
63
|
+
* parse back to the same value, so a spec string such as `<\/script>` can no
|
|
64
|
+
* longer close the tag early.
|
|
65
|
+
*/
|
|
66
|
+
function toScriptJSON(value) {
|
|
67
|
+
return JSON.stringify(value, null, 2).replace(/[<>&\u2028\u2029]/g, (char) => scriptEscapes[char] ?? char);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Redoc bundle the page loads, pinned to one release with a Subresource
|
|
71
|
+
* Integrity hash so a changed or compromised CDN file does not run. When
|
|
72
|
+
* bumping the version, recompute the hash from the npm tarball:
|
|
73
|
+
* `openssl dgst -sha384 -binary package/bundles/redoc.standalone.js | openssl base64 -A`.
|
|
74
|
+
*/
|
|
75
|
+
const redocBundle = {
|
|
76
|
+
src: "https://cdn.jsdelivr.net/npm/redoc@2.5.4/bundles/redoc.standalone.js",
|
|
77
|
+
integrity: "sha384-w447zOpYfw/1Tv/5AK9NfHTlQIqE3RVR6KY62jCyy9zNDgO64cMwGGP1Fj0zJVf5"
|
|
78
|
+
};
|
|
53
79
|
/**
|
|
54
80
|
* Renders a self-contained Redoc HTML page for an OpenAPI document. The page
|
|
55
81
|
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
@@ -74,10 +100,10 @@ async function getPageHTML(api) {
|
|
|
74
100
|
|
|
75
101
|
<body>
|
|
76
102
|
${`
|
|
77
|
-
<script src="
|
|
103
|
+
<script src="${redocBundle.src}" integrity="${redocBundle.integrity}" crossorigin="anonymous"><\/script>
|
|
78
104
|
<div id="redoc-container"></div>
|
|
79
105
|
<script>
|
|
80
|
-
const data = ${
|
|
106
|
+
const data = ${toScriptJSON(api)};
|
|
81
107
|
Redoc.init(data, {
|
|
82
108
|
"expandResponses": "200,400"
|
|
83
109
|
}, document.getElementById('redoc-container'))
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["defineExtension","useConfig","path","adapterOasName","ast"],"sources":["../kubb-extension.json","../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=\"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["defineExtension","useConfig","path","adapterOasName","ast"],"sources":["../kubb-extension.json","../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\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 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=\"${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, injectFile, useConfig } from 'kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\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 = 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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;AAO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"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { Exclude, Include, Output, Override,
|
|
2
|
+
import { Exclude, Include, Output, Override, PluginType } from "kubb/kit";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
type Options = {
|
|
5
5
|
/**
|
|
@@ -23,7 +23,7 @@ type ResolveOptions = {
|
|
|
23
23
|
include?: Array<Include>;
|
|
24
24
|
override: Array<Override<ResolveOptions>>;
|
|
25
25
|
};
|
|
26
|
-
type PluginRedoc =
|
|
26
|
+
type PluginRedoc = PluginType<'plugin-redoc', Options, ResolveOptions>;
|
|
27
27
|
declare global {
|
|
28
28
|
namespace Kubb {
|
|
29
29
|
interface PluginRegistry {
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var compatibility = {
|
|
|
9
9
|
};
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "5.0.
|
|
12
|
+
var version = "5.0.9";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/redoc.tsx
|
|
15
15
|
const htmlEscapes = {
|
|
@@ -24,6 +24,32 @@ const htmlEscapes = {
|
|
|
24
24
|
function escapeHtml(value) {
|
|
25
25
|
return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
|
|
26
26
|
}
|
|
27
|
+
const scriptEscapes = {
|
|
28
|
+
"<": "\\u003c",
|
|
29
|
+
">": "\\u003e",
|
|
30
|
+
"&": "\\u0026",
|
|
31
|
+
"\u2028": "\\u2028",
|
|
32
|
+
"\u2029": "\\u2029"
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Serializes `value` as JSON that is safe to inline in a `<script>` tag.
|
|
36
|
+
* JSON only allows these characters inside strings, where the `\uXXXX` escapes
|
|
37
|
+
* parse back to the same value, so a spec string such as `<\/script>` can no
|
|
38
|
+
* longer close the tag early.
|
|
39
|
+
*/
|
|
40
|
+
function toScriptJSON(value) {
|
|
41
|
+
return JSON.stringify(value, null, 2).replace(/[<>&\u2028\u2029]/g, (char) => scriptEscapes[char] ?? char);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Redoc bundle the page loads, pinned to one release with a Subresource
|
|
45
|
+
* Integrity hash so a changed or compromised CDN file does not run. When
|
|
46
|
+
* bumping the version, recompute the hash from the npm tarball:
|
|
47
|
+
* `openssl dgst -sha384 -binary package/bundles/redoc.standalone.js | openssl base64 -A`.
|
|
48
|
+
*/
|
|
49
|
+
const redocBundle = {
|
|
50
|
+
src: "https://cdn.jsdelivr.net/npm/redoc@2.5.4/bundles/redoc.standalone.js",
|
|
51
|
+
integrity: "sha384-w447zOpYfw/1Tv/5AK9NfHTlQIqE3RVR6KY62jCyy9zNDgO64cMwGGP1Fj0zJVf5"
|
|
52
|
+
};
|
|
27
53
|
/**
|
|
28
54
|
* Renders a self-contained Redoc HTML page for an OpenAPI document. The page
|
|
29
55
|
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
@@ -48,10 +74,10 @@ async function getPageHTML(api) {
|
|
|
48
74
|
|
|
49
75
|
<body>
|
|
50
76
|
${`
|
|
51
|
-
<script src="
|
|
77
|
+
<script src="${redocBundle.src}" integrity="${redocBundle.integrity}" crossorigin="anonymous"><\/script>
|
|
52
78
|
<div id="redoc-container"></div>
|
|
53
79
|
<script>
|
|
54
|
-
const data = ${
|
|
80
|
+
const data = ${toScriptJSON(api)};
|
|
55
81
|
Redoc.init(data, {
|
|
56
82
|
"expandResponses": "200,400"
|
|
57
83
|
}, document.getElementById('redoc-container'))
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../kubb-extension.json","../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=\"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../kubb-extension.json","../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\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 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=\"${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, injectFile, useConfig } from 'kubb/kit'\nimport { compatibility } from '../kubb-extension.json'\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 = 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 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":";;;;;;;;;;;;;;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,O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;GAAG,UAAU,CAAC;EAAE;CACnD;AACF,CAAC"}
|
package/docs/overview.md
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# Redoc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Redoc plugin generates a single HTML page that documents your OpenAPI spec with Redoc.
|
|
4
4
|
|
|
5
|
-
The spec is embedded in the page, so you can publish
|
|
5
|
+
The whole spec is embedded in the page, so you can publish the page to any static host without a build step. Viewing the page needs network access, because it loads a pinned Redoc bundle from jsDelivr, checked with a Subresource Integrity hash, and its fonts from Google Fonts.
|
|
6
6
|
|
|
7
7
|
## Setup
|
|
8
8
|
|
|
9
|
-
No other plugins or packages are needed. The plugin reads the spec through
|
|
9
|
+
No other plugins or packages are needed. The plugin reads the spec through the default OpenAPI adapter, `adapterOas`, and fails with any other adapter.
|
|
10
10
|
|
|
11
11
|
## Options worth knowing
|
|
12
12
|
|
|
13
|
-
- `output.path`
|
|
13
|
+
- `output.path` sets the HTML file path, relative to the root `output.path`. The default is `docs.html`. End it with `.html`, because it names a file, not a folder.
|
|
14
14
|
|
|
15
|
-
The plugin
|
|
15
|
+
The plugin has no other options. See [Options](https://kubb.dev/extensions/kubb-labs/plugin-redoc/options) for its type and default.
|
|
16
16
|
|
|
17
17
|
## Example
|
|
18
18
|
|
|
19
|
+
The config below writes the page to `src/gen/docs.html`.
|
|
20
|
+
|
|
19
21
|
```typescript [kubb.config.ts]
|
|
20
22
|
import { defineConfig } from 'kubb/config'
|
|
21
23
|
import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
@@ -28,8 +30,3 @@ export default defineConfig({
|
|
|
28
30
|
],
|
|
29
31
|
})
|
|
30
32
|
```
|
|
31
|
-
|
|
32
|
-
## See also
|
|
33
|
-
|
|
34
|
-
- [Redoc](https://redocly.com/redoc)
|
|
35
|
-
- [adapterOas](https://kubb.dev/extensions/kubb-labs/adapter-oas)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.9",
|
|
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",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"registry": "https://registry.npmjs.org/"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@kubb/adapter-oas": "^5.
|
|
68
|
+
"@kubb/adapter-oas": "^5.9.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"kubb": "^5.
|
|
71
|
+
"kubb": "^5.9.2"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"kubb": "^5.
|
|
74
|
+
"kubb": "^5.9.2"
|
|
75
75
|
},
|
|
76
76
|
"engines": {
|
|
77
77
|
"node": ">=22"
|