@kubb/plugin-redoc 5.0.0-beta.10 → 5.0.0-beta.106
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 +22 -25
- package/dist/index.cjs +75 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -7
- package/dist/index.js +71 -37
- package/dist/index.js.map +1 -1
- package/package.json +10 -22
- package/extension.yaml +0 -67
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -63
- package/src/redoc.tsx +0 -34
- package/src/types.ts +0 -30
- package/static/redoc.hbs +0 -21
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/README.md
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>@kubb/plugin-redoc</h1>
|
|
3
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
5
4
|
</a>
|
|
6
5
|
|
|
7
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
8
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
9
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
10
9
|
[![License][license-src]][license-href]
|
|
11
|
-
[![
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
12
11
|
|
|
13
12
|
<h4>
|
|
14
|
-
<a href="https://codesandbox.io/s/github/kubb-labs/plugins/tree/main/examples/typescript" target="_blank">View Demo</a>
|
|
15
|
-
<span> · </span>
|
|
16
13
|
<a href="https://kubb.dev/plugins/redoc" target="_blank">Documentation</a>
|
|
17
14
|
<span> · </span>
|
|
18
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
@@ -21,13 +18,13 @@
|
|
|
21
18
|
</h4>
|
|
22
19
|
</div>
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/plugin-redoc
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
### Generate a ReDoc API reference with Kubb
|
|
27
26
|
|
|
28
|
-
-
|
|
29
|
-
- Supports theming and branding via ReDoc configuration options
|
|
30
|
-
- Works with any valid OpenAPI 3.0 or 3.1 specification
|
|
27
|
+
`@kubb/plugin-redoc` generates a ReDoc API reference page with Kubb. The output is a standalone HTML file you can host without a build step or server.
|
|
31
28
|
|
|
32
29
|
## Installation
|
|
33
30
|
|
|
@@ -45,7 +42,7 @@ See the [full documentation](https://kubb.dev/plugins/redoc) for configuration o
|
|
|
45
42
|
|
|
46
43
|
## Supporting Kubb
|
|
47
44
|
|
|
48
|
-
Kubb is an
|
|
45
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
49
46
|
|
|
50
47
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
51
48
|
|
|
@@ -55,19 +52,19 @@ Kubb is an MIT-licensed open source project with its ongoing development made po
|
|
|
55
52
|
</a>
|
|
56
53
|
</p>
|
|
57
54
|
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
|
|
58
|
+
|
|
58
59
|
<!-- Badges -->
|
|
59
60
|
|
|
60
|
-
[npm-version-src]: https://
|
|
61
|
-
[npm-version-href]: https://
|
|
62
|
-
[npm-downloads-src]: https://
|
|
63
|
-
[npm-downloads-href]: https://
|
|
64
|
-
[
|
|
61
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
62
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/plugin-redoc
|
|
63
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
64
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/plugin-redoc
|
|
65
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
66
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
67
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc
|
|
65
68
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
|
|
69
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
|
|
70
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
71
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
|
|
72
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
73
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
69
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/plugin-redoc.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
70
|
+
[node-href]: https://npmx.dev/package/@kubb/plugin-redoc
|
package/dist/index.cjs
CHANGED
|
@@ -19,49 +19,55 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
}
|
|
20
20
|
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
27
|
let node_path = require("node:path");
|
|
28
|
-
|
|
29
|
-
node_path = __toESM(node_path);
|
|
28
|
+
node_path = __toESM(node_path, 1);
|
|
30
29
|
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
31
|
-
let
|
|
32
|
-
let node_fs = require("node:fs");
|
|
33
|
-
node_fs = __toESM(node_fs);
|
|
34
|
-
let node_url = require("node:url");
|
|
35
|
-
let handlebars = require("handlebars");
|
|
36
|
-
handlebars = __toESM(handlebars);
|
|
37
|
-
//#region ../../internals/utils/src/string.ts
|
|
38
|
-
/**
|
|
39
|
-
* Strips the file extension from a path or file name.
|
|
40
|
-
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* trimExtName('petStore.ts') // 'petStore'
|
|
44
|
-
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
45
|
-
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
46
|
-
* trimExtName('noExtension') // 'noExtension'
|
|
47
|
-
*/
|
|
48
|
-
function trimExtName(text) {
|
|
49
|
-
const dotIndex = text.lastIndexOf(".");
|
|
50
|
-
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
51
|
-
return text;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
30
|
+
let kubb_kit = require("kubb/kit");
|
|
54
31
|
//#region package.json
|
|
55
|
-
var version = "5.0.0-beta.
|
|
32
|
+
var version = "5.0.0-beta.106";
|
|
56
33
|
//#endregion
|
|
57
34
|
//#region src/redoc.tsx
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
35
|
+
const htmlEscapes = {
|
|
36
|
+
"&": "&",
|
|
37
|
+
"<": "<",
|
|
38
|
+
">": ">",
|
|
39
|
+
"\"": """,
|
|
40
|
+
"'": "'",
|
|
41
|
+
"`": "`",
|
|
42
|
+
"=": "="
|
|
43
|
+
};
|
|
44
|
+
function escapeHtml(value) {
|
|
45
|
+
return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Renders a self-contained Redoc HTML page for an OpenAPI document. The page
|
|
49
|
+
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
50
|
+
* the generated file works without further build steps.
|
|
51
|
+
*/
|
|
52
|
+
async function getPageHTML(api) {
|
|
53
|
+
return `<html>
|
|
54
|
+
|
|
55
|
+
<head>
|
|
56
|
+
<meta charset='utf8' />
|
|
57
|
+
<title>${escapeHtml(api.info.title || "ReDoc documentation")}</title>
|
|
58
|
+
<!-- needed for adaptive design -->
|
|
59
|
+
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
|
60
|
+
<style>
|
|
61
|
+
body {
|
|
62
|
+
padding: 0;
|
|
63
|
+
margin: 0;
|
|
64
|
+
}
|
|
65
|
+
</style>
|
|
66
|
+
<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />
|
|
67
|
+
</head>
|
|
68
|
+
|
|
69
|
+
<body>
|
|
70
|
+
${`
|
|
65
71
|
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
|
|
66
72
|
<div id="redoc-container"></div>
|
|
67
73
|
<script>
|
|
@@ -70,16 +76,41 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
|
|
|
70
76
|
"expandResponses": "200,400"
|
|
71
77
|
}, document.getElementById('redoc-container'))
|
|
72
78
|
<\/script>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
79
|
+
`}
|
|
80
|
+
</body>
|
|
81
|
+
|
|
82
|
+
</html>`;
|
|
77
83
|
}
|
|
78
84
|
//#endregion
|
|
79
85
|
//#region src/plugin.ts
|
|
86
|
+
/**
|
|
87
|
+
* Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
|
|
88
|
+
* cross-plugin dependency references.
|
|
89
|
+
*/
|
|
80
90
|
const pluginRedocName = "plugin-redoc";
|
|
81
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Generates a self-contained static HTML documentation page from your OpenAPI
|
|
93
|
+
* spec using Redoc. The file is regenerated on every Kubb build, so the docs
|
|
94
|
+
* stay in lockstep with the spec the rest of your code is generated from.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { defineConfig } from 'kubb/config'
|
|
99
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
100
|
+
*
|
|
101
|
+
* export default defineConfig({
|
|
102
|
+
* input: './petStore.yaml',
|
|
103
|
+
* output: { path: './src/gen' },
|
|
104
|
+
* plugins: [
|
|
105
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
106
|
+
* ],
|
|
107
|
+
* })
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
const pluginRedoc = (0, kubb_kit.definePlugin)((options) => {
|
|
82
111
|
const { output = { path: "docs.html" } } = options;
|
|
112
|
+
const extname = node_path.default.extname(output.path);
|
|
113
|
+
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
83
114
|
return {
|
|
84
115
|
name: pluginRedocName,
|
|
85
116
|
version,
|
|
@@ -87,7 +118,7 @@ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
|
|
|
87
118
|
hooks: { async "kubb:plugin:setup"(ctx) {
|
|
88
119
|
ctx.setOptions({
|
|
89
120
|
output,
|
|
90
|
-
name
|
|
121
|
+
name,
|
|
91
122
|
exclude: [],
|
|
92
123
|
override: []
|
|
93
124
|
});
|
|
@@ -95,14 +126,14 @@ const pluginRedoc = (0, _kubb_core.definePlugin)((options) => {
|
|
|
95
126
|
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.`);
|
|
96
127
|
const document = adapter.document;
|
|
97
128
|
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.`);
|
|
98
|
-
const root = node_path
|
|
129
|
+
const root = node_path.default.resolve(ctx.config.root, ctx.config.output.path);
|
|
99
130
|
const pageHTML = await getPageHTML(document);
|
|
100
131
|
ctx.injectFile({
|
|
101
132
|
baseName: "docs.html",
|
|
102
|
-
path: node_path
|
|
103
|
-
sources: [
|
|
133
|
+
path: node_path.default.resolve(root, output.path || "./docs.html"),
|
|
134
|
+
sources: [kubb_kit.ast.factory.createSource({
|
|
104
135
|
name: "docs.html",
|
|
105
|
-
nodes: [
|
|
136
|
+
nodes: [kubb_kit.ast.factory.createText(pageHTML)]
|
|
106
137
|
})]
|
|
107
138
|
});
|
|
108
139
|
} }
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
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) => {\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 return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name,\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.factory.createSource({\n name: 'docs.html',\n nodes: [ast.factory.createText(pageHTML)],\n }),\n ],\n })\n },\n },\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,EAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAC3C,MAAM,UAAUC,UAAAA,QAAK,QAAQ,OAAO,IAAI;CACxC,MAAM,OAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAI,OAAO;CAEtE,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA;IACA,SAAS,CAAC;IACV,UAAU,CAAC;GACb,CAAC;GAED,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAASC,kBAAAA,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;GAGF,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;GAGF,MAAM,OAAOD,UAAAA,QAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,WAAW,MAAM,YAAY,QAAQ;GAE3C,IAAI,WAAW;IACb,UAAU;IACV,MAAMA,UAAAA,QAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACPE,SAAAA,IAAI,QAAQ,aAAa;KACvB,MAAM;KACN,OAAO,CAACA,SAAAA,IAAI,QAAQ,WAAW,QAAQ,CAAC;IAC1C,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { t as __name } from "./
|
|
2
|
-
import
|
|
3
|
-
import { Exclude, Include, Output, Override, PluginFactoryOptions } from "@kubb/core";
|
|
4
|
-
|
|
1
|
+
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { Exclude, Include, Output, Override, PluginFactoryOptions } from "kubb/kit";
|
|
5
3
|
//#region src/types.d.ts
|
|
6
4
|
type Options = {
|
|
5
|
+
/**
|
|
6
|
+
* Output location of the generated Redoc HTML file. The path is resolved
|
|
7
|
+
* against the global `output.path` set on `defineConfig`.
|
|
8
|
+
*/
|
|
7
9
|
output?: {
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
11
|
+
* File path of the generated HTML, relative to the global `output.path`.
|
|
12
|
+
* Unlike most plugins, this points at a single file rather than a directory.
|
|
10
13
|
*
|
|
11
14
|
* @default 'docs.html'
|
|
12
15
|
*/
|
|
@@ -14,7 +17,7 @@ type Options = {
|
|
|
14
17
|
};
|
|
15
18
|
};
|
|
16
19
|
type ResolveOptions = {
|
|
17
|
-
output: Output
|
|
20
|
+
output: Output;
|
|
18
21
|
name: string;
|
|
19
22
|
exclude: Array<Exclude>;
|
|
20
23
|
include?: Array<Include>;
|
|
@@ -30,8 +33,31 @@ declare global {
|
|
|
30
33
|
}
|
|
31
34
|
//#endregion
|
|
32
35
|
//#region src/plugin.d.ts
|
|
36
|
+
/**
|
|
37
|
+
* Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
|
|
38
|
+
* cross-plugin dependency references.
|
|
39
|
+
*/
|
|
33
40
|
declare const pluginRedocName = "plugin-redoc";
|
|
34
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Generates a self-contained static HTML documentation page from your OpenAPI
|
|
43
|
+
* spec using Redoc. The file is regenerated on every Kubb build, so the docs
|
|
44
|
+
* stay in lockstep with the spec the rest of your code is generated from.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { defineConfig } from 'kubb/config'
|
|
49
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
50
|
+
*
|
|
51
|
+
* export default defineConfig({
|
|
52
|
+
* input: './petStore.yaml',
|
|
53
|
+
* output: { path: './src/gen' },
|
|
54
|
+
* plugins: [
|
|
55
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
56
|
+
* ],
|
|
57
|
+
* })
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare const pluginRedoc: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginRedoc>;
|
|
35
61
|
//#endregion
|
|
36
62
|
export { type PluginRedoc, pluginRedoc as default, pluginRedoc, pluginRedocName };
|
|
37
63
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
import "./
|
|
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 "
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import pkg from "handlebars";
|
|
8
|
-
//#region ../../internals/utils/src/string.ts
|
|
9
|
-
/**
|
|
10
|
-
* Strips the file extension from a path or file name.
|
|
11
|
-
* Only removes the last `.ext` segment when the dot is not part of a directory name.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* trimExtName('petStore.ts') // 'petStore'
|
|
15
|
-
* trimExtName('/src/models/pet.ts') // '/src/models/pet'
|
|
16
|
-
* trimExtName('/project.v2/gen/pet.ts') // '/project.v2/gen/pet'
|
|
17
|
-
* trimExtName('noExtension') // 'noExtension'
|
|
18
|
-
*/
|
|
19
|
-
function trimExtName(text) {
|
|
20
|
-
const dotIndex = text.lastIndexOf(".");
|
|
21
|
-
if (dotIndex > 0 && !text.includes("/", dotIndex)) return text.slice(0, dotIndex);
|
|
22
|
-
return text;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
4
|
+
import { ast, definePlugin } from "kubb/kit";
|
|
25
5
|
//#region package.json
|
|
26
|
-
var version = "5.0.0-beta.
|
|
6
|
+
var version = "5.0.0-beta.106";
|
|
27
7
|
//#endregion
|
|
28
8
|
//#region src/redoc.tsx
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
9
|
+
const htmlEscapes = {
|
|
10
|
+
"&": "&",
|
|
11
|
+
"<": "<",
|
|
12
|
+
">": ">",
|
|
13
|
+
"\"": """,
|
|
14
|
+
"'": "'",
|
|
15
|
+
"`": "`",
|
|
16
|
+
"=": "="
|
|
17
|
+
};
|
|
18
|
+
function escapeHtml(value) {
|
|
19
|
+
return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Renders a self-contained Redoc HTML page for an OpenAPI document. The page
|
|
23
|
+
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
24
|
+
* the generated file works without further build steps.
|
|
25
|
+
*/
|
|
26
|
+
async function getPageHTML(api) {
|
|
27
|
+
return `<html>
|
|
28
|
+
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset='utf8' />
|
|
31
|
+
<title>${escapeHtml(api.info.title || "ReDoc documentation")}</title>
|
|
32
|
+
<!-- needed for adaptive design -->
|
|
33
|
+
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
|
34
|
+
<style>
|
|
35
|
+
body {
|
|
36
|
+
padding: 0;
|
|
37
|
+
margin: 0;
|
|
38
|
+
}
|
|
39
|
+
</style>
|
|
40
|
+
<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />
|
|
41
|
+
</head>
|
|
42
|
+
|
|
43
|
+
<body>
|
|
44
|
+
${`
|
|
36
45
|
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> <\/script>
|
|
37
46
|
<div id="redoc-container"></div>
|
|
38
47
|
<script>
|
|
@@ -41,16 +50,41 @@ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } =
|
|
|
41
50
|
"expandResponses": "200,400"
|
|
42
51
|
}, document.getElementById('redoc-container'))
|
|
43
52
|
<\/script>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
`}
|
|
54
|
+
</body>
|
|
55
|
+
|
|
56
|
+
</html>`;
|
|
48
57
|
}
|
|
49
58
|
//#endregion
|
|
50
59
|
//#region src/plugin.ts
|
|
60
|
+
/**
|
|
61
|
+
* Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
|
|
62
|
+
* cross-plugin dependency references.
|
|
63
|
+
*/
|
|
51
64
|
const pluginRedocName = "plugin-redoc";
|
|
65
|
+
/**
|
|
66
|
+
* Generates a self-contained static HTML documentation page from your OpenAPI
|
|
67
|
+
* spec using Redoc. The file is regenerated on every Kubb build, so the docs
|
|
68
|
+
* stay in lockstep with the spec the rest of your code is generated from.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { defineConfig } from 'kubb/config'
|
|
73
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
74
|
+
*
|
|
75
|
+
* export default defineConfig({
|
|
76
|
+
* input: './petStore.yaml',
|
|
77
|
+
* output: { path: './src/gen' },
|
|
78
|
+
* plugins: [
|
|
79
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
80
|
+
* ],
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
52
84
|
const pluginRedoc = definePlugin((options) => {
|
|
53
85
|
const { output = { path: "docs.html" } } = options;
|
|
86
|
+
const extname = path.extname(output.path);
|
|
87
|
+
const name = extname ? output.path.slice(0, -extname.length) : output.path;
|
|
54
88
|
return {
|
|
55
89
|
name: pluginRedocName,
|
|
56
90
|
version,
|
|
@@ -58,7 +92,7 @@ const pluginRedoc = definePlugin((options) => {
|
|
|
58
92
|
hooks: { async "kubb:plugin:setup"(ctx) {
|
|
59
93
|
ctx.setOptions({
|
|
60
94
|
output,
|
|
61
|
-
name
|
|
95
|
+
name,
|
|
62
96
|
exclude: [],
|
|
63
97
|
override: []
|
|
64
98
|
});
|
|
@@ -71,9 +105,9 @@ const pluginRedoc = definePlugin((options) => {
|
|
|
71
105
|
ctx.injectFile({
|
|
72
106
|
baseName: "docs.html",
|
|
73
107
|
path: path.resolve(root, output.path || "./docs.html"),
|
|
74
|
-
sources: [ast.createSource({
|
|
108
|
+
sources: [ast.factory.createSource({
|
|
75
109
|
name: "docs.html",
|
|
76
|
-
nodes: [ast.createText(pageHTML)]
|
|
110
|
+
nodes: [ast.factory.createText(pageHTML)]
|
|
77
111
|
})]
|
|
78
112
|
});
|
|
79
113
|
} }
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["
|
|
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) => {\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 return {\n name: pluginRedocName,\n version,\n options,\n hooks: {\n async 'kubb:plugin:setup'(ctx) {\n ctx.setOptions({\n output,\n name,\n exclude: [],\n override: [],\n })\n\n const adapter = ctx.config.adapter\n\n if (adapter?.name !== adapterOasName) {\n throw new Error(\n `[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \\`adapter: adapterOas()\\`) in your Kubb config.`,\n )\n }\n\n const document = (adapter as Adapter<AdapterOas>).document\n\n if (!document) {\n throw new Error(\n `[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,\n )\n }\n\n const root = path.resolve(ctx.config.root, ctx.config.output.path)\n const pageHTML = await getPageHTML(document)\n\n ctx.injectFile({\n baseName: 'docs.html',\n path: path.resolve(root, output.path || './docs.html'),\n sources: [\n ast.factory.createSource({\n name: 'docs.html',\n nodes: [ast.factory.createText(pageHTML)],\n }),\n ],\n })\n },\n },\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,cAA2B,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAC3C,MAAM,UAAU,KAAK,QAAQ,OAAO,IAAI;CACxC,MAAM,OAAO,UAAU,OAAO,KAAK,MAAM,GAAG,CAAC,QAAQ,MAAM,IAAI,OAAO;CAEtE,OAAO;EACL,MAAM;EACN;EACA;EACA,OAAO,EACL,MAAM,oBAAoB,KAAK;GAC7B,IAAI,WAAW;IACb;IACA;IACA,SAAS,CAAC;IACV,UAAU,CAAC;GACb,CAAC;GAED,MAAM,UAAU,IAAI,OAAO;GAE3B,IAAI,SAAS,SAAS,gBACpB,MAAM,IAAI,MACR,IAAI,gBAAgB,sIACtB;GAGF,MAAM,WAAY,QAAgC;GAElD,IAAI,CAAC,UACH,MAAM,IAAI,MACR,IAAI,gBAAgB,wHACtB;GAGF,MAAM,OAAO,KAAK,QAAQ,IAAI,OAAO,MAAM,IAAI,OAAO,OAAO,IAAI;GACjE,MAAM,WAAW,MAAM,YAAY,QAAQ;GAE3C,IAAI,WAAW;IACb,UAAU;IACV,MAAM,KAAK,QAAQ,MAAM,OAAO,QAAQ,aAAa;IACrD,SAAS,CACP,IAAI,QAAQ,aAAa;KACvB,MAAM;KACN,OAAO,CAAC,IAAI,QAAQ,WAAW,QAAQ,CAAC;IAC1C,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
4
|
-
"description": "Generate a
|
|
3
|
+
"version": "5.0.0-beta.106",
|
|
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",
|
|
7
7
|
"api-reference",
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
"codegen",
|
|
10
10
|
"documentation",
|
|
11
11
|
"kubb",
|
|
12
|
-
"
|
|
12
|
+
"meta-framework",
|
|
13
13
|
"redoc",
|
|
14
|
-
"swagger",
|
|
15
14
|
"typescript"
|
|
16
15
|
],
|
|
17
16
|
"license": "MIT",
|
|
@@ -22,10 +21,7 @@
|
|
|
22
21
|
"directory": "packages/plugin-redoc"
|
|
23
22
|
},
|
|
24
23
|
"files": [
|
|
25
|
-
"src",
|
|
26
24
|
"dist",
|
|
27
|
-
"static",
|
|
28
|
-
"extension.yaml",
|
|
29
25
|
"!/**/**.test.**",
|
|
30
26
|
"!/**/__tests__/**",
|
|
31
27
|
"!/**/__snapshots__/**"
|
|
@@ -50,30 +46,22 @@
|
|
|
50
46
|
"registry": "https://registry.npmjs.org/"
|
|
51
47
|
},
|
|
52
48
|
"dependencies": {
|
|
53
|
-
"@kubb/adapter-oas": "5.0.0-beta.
|
|
54
|
-
"@kubb/core": "5.0.0-beta.10",
|
|
55
|
-
"handlebars": "^4.7.9"
|
|
49
|
+
"@kubb/adapter-oas": "^5.0.0-beta.106"
|
|
56
50
|
},
|
|
57
51
|
"devDependencies": {
|
|
58
|
-
"
|
|
52
|
+
"kubb": "^5.0.0-beta.106"
|
|
53
|
+
},
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"kubb": "^5.0.0-beta.106"
|
|
59
56
|
},
|
|
60
|
-
"size-limit": [
|
|
61
|
-
{
|
|
62
|
-
"path": "./dist/*.js",
|
|
63
|
-
"limit": "510 KiB",
|
|
64
|
-
"gzip": true
|
|
65
|
-
}
|
|
66
|
-
],
|
|
67
57
|
"engines": {
|
|
68
58
|
"node": ">=22"
|
|
69
59
|
},
|
|
70
60
|
"scripts": {
|
|
71
|
-
"build": "tsdown
|
|
72
|
-
"clean": "
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
73
63
|
"lint": "oxlint .",
|
|
74
64
|
"lint:fix": "oxlint --fix .",
|
|
75
|
-
"release": "pnpm publish --no-git-check",
|
|
76
|
-
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
77
65
|
"start": "tsdown --watch",
|
|
78
66
|
"test": "vitest --passWithNoTests",
|
|
79
67
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/extension.yaml
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
$schema: https://kubb.dev/schemas/extension.json
|
|
2
|
-
kind: plugin
|
|
3
|
-
id: plugin-redoc
|
|
4
|
-
name: Redoc
|
|
5
|
-
description: Generate API documentation with Redoc from OpenAPI specifications.
|
|
6
|
-
category: documentation
|
|
7
|
-
type: official
|
|
8
|
-
npmPackage: '@kubb/plugin-redoc'
|
|
9
|
-
docsPath: /plugins/plugin-redoc
|
|
10
|
-
repo: https://github.com/kubb-labs/plugins
|
|
11
|
-
maintainers:
|
|
12
|
-
- name: Stijn Van Hulle
|
|
13
|
-
github: stijnvanhulle
|
|
14
|
-
compatibility:
|
|
15
|
-
kubb: '>=5.0.0'
|
|
16
|
-
node: '>=22'
|
|
17
|
-
tags:
|
|
18
|
-
- redoc
|
|
19
|
-
- api-docs
|
|
20
|
-
- documentation
|
|
21
|
-
- interactive-docs
|
|
22
|
-
- codegen
|
|
23
|
-
- openapi
|
|
24
|
-
dependencies: []
|
|
25
|
-
resources:
|
|
26
|
-
documentation: https://kubb.dev/plugins/plugin-redoc
|
|
27
|
-
repository: https://github.com/kubb-labs/plugins
|
|
28
|
-
issues: https://github.com/kubb-labs/plugins/issues
|
|
29
|
-
changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-redoc/CHANGELOG.md
|
|
30
|
-
codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/simple-single
|
|
31
|
-
featured: false
|
|
32
|
-
icon:
|
|
33
|
-
light: https://kubb.dev/feature/openapi.svg
|
|
34
|
-
intro: |
|
|
35
|
-
Generate interactive API documentation from your OpenAPI schema using [Redoc](https://redocly.com/).
|
|
36
|
-
options:
|
|
37
|
-
- name: output
|
|
38
|
-
type: '{ path: string }'
|
|
39
|
-
required: false
|
|
40
|
-
description: Specify the output path for the generated documentation HTML file.
|
|
41
|
-
properties:
|
|
42
|
-
- name: path
|
|
43
|
-
type: string
|
|
44
|
-
required: true
|
|
45
|
-
description: |
|
|
46
|
-
The output file path for the generated documentation HTML.
|
|
47
|
-
tip: |
|
|
48
|
-
if `output.path` is a file, `group` cannot be used.
|
|
49
|
-
default: "'docs.html'"
|
|
50
|
-
examples:
|
|
51
|
-
- name: kubb.config.ts
|
|
52
|
-
files:
|
|
53
|
-
- lang: typescript
|
|
54
|
-
code: |
|
|
55
|
-
import { defineConfig } from 'kubb'
|
|
56
|
-
import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
57
|
-
|
|
58
|
-
export default defineConfig({
|
|
59
|
-
input: { path: './petStore.yaml' },
|
|
60
|
-
output: { path: './src/gen' },
|
|
61
|
-
plugins: [
|
|
62
|
-
pluginRedoc({
|
|
63
|
-
output: { path: 'docs.html' },
|
|
64
|
-
}),
|
|
65
|
-
],
|
|
66
|
-
})
|
|
67
|
-
twoslash: false
|
package/src/index.ts
DELETED
package/src/plugin.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { trimExtName } from '@internals/utils'
|
|
3
|
-
import type { AdapterOas } from '@kubb/adapter-oas'
|
|
4
|
-
import { adapterOasName } from '@kubb/adapter-oas'
|
|
5
|
-
|
|
6
|
-
import { type Adapter, ast, definePlugin } from '@kubb/core'
|
|
7
|
-
import { version } from '../package.json'
|
|
8
|
-
import { getPageHTML } from './redoc.tsx'
|
|
9
|
-
import type { PluginRedoc } from './types.ts'
|
|
10
|
-
|
|
11
|
-
export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
|
|
12
|
-
|
|
13
|
-
export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
|
|
14
|
-
const { output = { path: 'docs.html' } } = options
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
name: pluginRedocName,
|
|
18
|
-
version,
|
|
19
|
-
options,
|
|
20
|
-
hooks: {
|
|
21
|
-
async 'kubb:plugin:setup'(ctx) {
|
|
22
|
-
ctx.setOptions({
|
|
23
|
-
output,
|
|
24
|
-
name: trimExtName(output.path),
|
|
25
|
-
exclude: [],
|
|
26
|
-
override: [],
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const adapter = ctx.config.adapter
|
|
30
|
-
|
|
31
|
-
if (adapter?.name !== adapterOasName) {
|
|
32
|
-
throw new Error(
|
|
33
|
-
`[${pluginRedocName}] plugin-redoc requires the OpenAPI adapter. Make sure you are using adapterOas (e.g. \`adapter: adapterOas()\`) in your Kubb config.`,
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const document = (adapter as Adapter<AdapterOas>).document
|
|
38
|
-
|
|
39
|
-
if (!document) {
|
|
40
|
-
throw new Error(
|
|
41
|
-
`[${pluginRedocName}] No OpenAPI document found. The adapterOas did not produce a document — ensure the adapter has run before this plugin.`,
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const root = path.resolve(ctx.config.root, ctx.config.output.path)
|
|
46
|
-
const pageHTML = await getPageHTML(document)
|
|
47
|
-
|
|
48
|
-
ctx.injectFile({
|
|
49
|
-
baseName: 'docs.html',
|
|
50
|
-
path: path.resolve(root, output.path || './docs.html'),
|
|
51
|
-
sources: [
|
|
52
|
-
ast.createSource({
|
|
53
|
-
name: 'docs.html',
|
|
54
|
-
nodes: [ast.createText(pageHTML)],
|
|
55
|
-
}),
|
|
56
|
-
],
|
|
57
|
-
})
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
export default pluginRedoc
|
package/src/redoc.tsx
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
|
-
import type { AdapterOas } from '@kubb/adapter-oas'
|
|
5
|
-
import pkg from 'handlebars'
|
|
6
|
-
|
|
7
|
-
const __filename = fileURLToPath(import.meta.url)
|
|
8
|
-
const __dirname = path.dirname(__filename)
|
|
9
|
-
|
|
10
|
-
type BuildDocsOptions = {
|
|
11
|
-
title?: string
|
|
12
|
-
disableGoogleFont?: boolean
|
|
13
|
-
templateOptions?: any
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
|
|
17
|
-
const templateFileName = path.join(__dirname, '../static/redoc.hbs')
|
|
18
|
-
const template = pkg.compile(fs.readFileSync(templateFileName).toString())
|
|
19
|
-
return template({
|
|
20
|
-
title: title || api.info.title || 'ReDoc documentation',
|
|
21
|
-
redocHTML: `
|
|
22
|
-
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
|
|
23
|
-
<div id="redoc-container"></div>
|
|
24
|
-
<script>
|
|
25
|
-
const data = ${JSON.stringify(api, null, 2)};
|
|
26
|
-
Redoc.init(data, {
|
|
27
|
-
"expandResponses": "200,400"
|
|
28
|
-
}, document.getElementById('redoc-container'))
|
|
29
|
-
</script>
|
|
30
|
-
`,
|
|
31
|
-
disableGoogleFont,
|
|
32
|
-
templateOptions,
|
|
33
|
-
})
|
|
34
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Exclude, Include, Output, Override, PluginFactoryOptions } from '@kubb/core'
|
|
2
|
-
|
|
3
|
-
export type Options = {
|
|
4
|
-
output?: {
|
|
5
|
-
/**
|
|
6
|
-
* Output path for the generated HTML documentation.
|
|
7
|
-
*
|
|
8
|
-
* @default 'docs.html'
|
|
9
|
-
*/
|
|
10
|
-
path: string
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
type ResolveOptions = {
|
|
15
|
-
output: Output<never>
|
|
16
|
-
name: string
|
|
17
|
-
exclude: Array<Exclude>
|
|
18
|
-
include?: Array<Include>
|
|
19
|
-
override: Array<Override<ResolveOptions>>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type PluginRedoc = PluginFactoryOptions<'plugin-redoc', Options, ResolveOptions>
|
|
23
|
-
|
|
24
|
-
declare global {
|
|
25
|
-
namespace Kubb {
|
|
26
|
-
interface PluginRegistry {
|
|
27
|
-
'plugin-redoc': PluginRedoc
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
package/static/redoc.hbs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset='utf8' />
|
|
5
|
-
<title>{{title}}</title>
|
|
6
|
-
<!-- needed for adaptive design -->
|
|
7
|
-
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
|
8
|
-
<style>
|
|
9
|
-
body {
|
|
10
|
-
padding: 0;
|
|
11
|
-
margin: 0;
|
|
12
|
-
}
|
|
13
|
-
</style>
|
|
14
|
-
{{#unless disableGoogleFont}}<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />{{/unless}}
|
|
15
|
-
</head>
|
|
16
|
-
|
|
17
|
-
<body>
|
|
18
|
-
{{{redocHTML}}}
|
|
19
|
-
</body>
|
|
20
|
-
|
|
21
|
-
</html>
|
|
File without changes
|