@kubb/plugin-redoc 5.0.0-beta.4 → 5.0.0-beta.56
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 +39 -22
- package/dist/index.cjs +70 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +68 -34
- package/dist/index.js.map +1 -1
- package/package.json +9 -19
- package/src/plugin.ts +26 -2
- package/src/redoc.tsx +48 -17
- package/src/types.ts +6 -1
- package/extension.yaml +0 -67
- package/static/redoc.hbs +0 -21
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/README.md
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>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://
|
|
15
|
-
<span> · </span>
|
|
16
|
-
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
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>
|
|
19
16
|
<span> · </span>
|
|
@@ -21,11 +18,31 @@
|
|
|
21
18
|
</h4>
|
|
22
19
|
</div>
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/plugin-redoc
|
|
24
|
+
|
|
25
|
+
### Generate a ReDoc API reference from OpenAPI
|
|
26
|
+
|
|
27
|
+
`@kubb/plugin-redoc` generates a ReDoc API reference page from your OpenAPI specification. The output is a standalone HTML file you can host without a build step or server.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
bun add @kubb/plugin-redoc
|
|
33
|
+
# or
|
|
34
|
+
pnpm add @kubb/plugin-redoc
|
|
35
|
+
# or
|
|
36
|
+
npm install @kubb/plugin-redoc
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
|
|
41
|
+
See the [full documentation](https://kubb.dev/plugins/redoc) for configuration options and examples.
|
|
25
42
|
|
|
26
43
|
## Supporting Kubb
|
|
27
44
|
|
|
28
|
-
Kubb
|
|
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:
|
|
29
46
|
|
|
30
47
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
31
48
|
|
|
@@ -35,19 +52,19 @@ Kubb uses an MIT-licensed open source project with its ongoing development made
|
|
|
35
52
|
</a>
|
|
36
53
|
</p>
|
|
37
54
|
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
[MIT](https://github.com/kubb-labs/plugins/blob/main/LICENSE)
|
|
58
|
+
|
|
38
59
|
<!-- Badges -->
|
|
39
60
|
|
|
40
|
-
[npm-version-src]: https://
|
|
41
|
-
[npm-version-href]: https://
|
|
42
|
-
[npm-downloads-src]: https://
|
|
43
|
-
[npm-downloads-href]: https://
|
|
44
|
-
[
|
|
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
|
|
45
68
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
46
|
-
[
|
|
47
|
-
[
|
|
48
|
-
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-redoc?style=flat&colorA=18181B&colorB=f58517
|
|
49
|
-
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
|
|
50
|
-
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
51
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-redoc
|
|
52
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
53
|
-
[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
|
@@ -25,43 +25,49 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
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
30
|
let _kubb_core = require("@kubb/core");
|
|
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
|
|
54
31
|
//#region package.json
|
|
55
|
-
var version = "5.0.0-beta.
|
|
32
|
+
var version = "5.0.0-beta.56";
|
|
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, { title, disableGoogleFont } = {}) {
|
|
53
|
+
return `<html>
|
|
54
|
+
|
|
55
|
+
<head>
|
|
56
|
+
<meta charset='utf8' />
|
|
57
|
+
<title>${escapeHtml(title || 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
|
+
${disableGoogleFont ? "" : `<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";
|
|
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'
|
|
99
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
100
|
+
*
|
|
101
|
+
* export default defineConfig({
|
|
102
|
+
* input: { path: './petStore.yaml' },
|
|
103
|
+
* output: { path: './src/gen' },
|
|
104
|
+
* plugins: [
|
|
105
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
106
|
+
* ],
|
|
107
|
+
* })
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
81
110
|
const pluginRedoc = (0, _kubb_core.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,11 +126,11 @@ 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
|
|
133
|
+
path: node_path.default.resolve(root, output.path || "./docs.html"),
|
|
103
134
|
sources: [_kubb_core.ast.createSource({
|
|
104
135
|
name: "docs.html",
|
|
105
136
|
nodes: [_kubb_core.ast.createText(pageHTML)]
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["path","adapterOasName","ast"],"sources":["../package.json","../src/redoc.tsx","../src/plugin.ts"],"sourcesContent":["","import type { AdapterOas } from '@kubb/adapter-oas'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\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'], { title, disableGoogleFont }: BuildDocsOptions = {}) {\n const pageTitle = escapeHtml(title || api.info.title || 'ReDoc documentation')\n const googleFont = disableGoogleFont\n ? ''\n : `<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/core'\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'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './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.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACQA,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,EAAE,OAAO,sBAAwC,CAAC,GAAG;CAgBlH,OAAO;;;;aAfW,WAAW,SAAS,IAAI,KAAK,SAAS,qBAmBrC,EAAE;;;;;;;;;MAlBF,oBACf,KACA,qHAyBW;;;;MAIX;;;;kBAxBY,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;MAwB/B;;;;AAIhB;;;;;;;ACnDA,MAAa,kBAAkB;;;;;;;;;;;;;;;;;;;;AAqB/B,MAAa,eAAA,GAAA,WAAA,aAAA,EAAyC,YAAY;CAChE,MAAM,EAAE,SAAS,EAAE,MAAM,YAAY,MAAM;CAC3C,MAAM,UAAUA,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,WAAAA,IAAI,aAAa;KACf,MAAM;KACN,OAAO,CAACA,WAAAA,IAAI,WAAW,QAAQ,CAAC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
2
|
-
import * as _$_kubb_core0 from "@kubb/core";
|
|
1
|
+
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
3
2
|
import { Exclude, Include, Output, Override, PluginFactoryOptions } from "@kubb/core";
|
|
4
3
|
|
|
5
4
|
//#region src/types.d.ts
|
|
6
5
|
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Output location of the generated Redoc HTML file. The path is resolved
|
|
8
|
+
* against the global `output.path` set on `defineConfig`.
|
|
9
|
+
*/
|
|
7
10
|
output?: {
|
|
8
11
|
/**
|
|
9
|
-
*
|
|
12
|
+
* File path of the generated HTML, relative to the global `output.path`.
|
|
13
|
+
* Unlike most plugins, this points at a single file rather than a directory.
|
|
10
14
|
*
|
|
11
15
|
* @default 'docs.html'
|
|
12
16
|
*/
|
|
@@ -30,8 +34,31 @@ declare global {
|
|
|
30
34
|
}
|
|
31
35
|
//#endregion
|
|
32
36
|
//#region src/plugin.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
|
|
39
|
+
* cross-plugin dependency references.
|
|
40
|
+
*/
|
|
33
41
|
declare const pluginRedocName = "plugin-redoc";
|
|
34
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Generates a self-contained static HTML documentation page from your OpenAPI
|
|
44
|
+
* spec using Redoc. The file is regenerated on every Kubb build, so the docs
|
|
45
|
+
* stay in lockstep with the spec the rest of your code is generated from.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { defineConfig } from 'kubb'
|
|
50
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
51
|
+
*
|
|
52
|
+
* export default defineConfig({
|
|
53
|
+
* input: { path: './petStore.yaml' },
|
|
54
|
+
* output: { path: './src/gen' },
|
|
55
|
+
* plugins: [
|
|
56
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
57
|
+
* ],
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare const pluginRedoc: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginRedoc>;
|
|
35
62
|
//#endregion
|
|
36
63
|
export { type PluginRedoc, pluginRedoc as default, pluginRedoc, pluginRedocName };
|
|
37
64
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,47 @@
|
|
|
1
|
-
import "./chunk
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { adapterOasName } from "@kubb/adapter-oas";
|
|
4
4
|
import { ast, definePlugin } from "@kubb/core";
|
|
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
|
|
25
5
|
//#region package.json
|
|
26
|
-
var version = "5.0.0-beta.
|
|
6
|
+
var version = "5.0.0-beta.56";
|
|
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, { title, disableGoogleFont } = {}) {
|
|
27
|
+
return `<html>
|
|
28
|
+
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset='utf8' />
|
|
31
|
+
<title>${escapeHtml(title || 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
|
+
${disableGoogleFont ? "" : `<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'
|
|
73
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
74
|
+
*
|
|
75
|
+
* export default defineConfig({
|
|
76
|
+
* input: { path: './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
|
});
|
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\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\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'], { title, disableGoogleFont }: BuildDocsOptions = {}) {\n const pageTitle = escapeHtml(title || api.info.title || 'ReDoc documentation')\n const googleFont = disableGoogleFont\n ? ''\n : `<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/core'\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'\n * import { pluginRedoc } from '@kubb/plugin-redoc'\n *\n * export default defineConfig({\n * input: { path: './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.createSource({\n name: 'docs.html',\n nodes: [ast.createText(pageHTML)],\n }),\n ],\n })\n },\n },\n }\n})\n\nexport default pluginRedoc\n"],"mappings":";;;;;;;;ACQA,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,EAAE,OAAO,sBAAwC,CAAC,GAAG;CAgBlH,OAAO;;;;aAfW,WAAW,SAAS,IAAI,KAAK,SAAS,qBAmBrC,EAAE;;;;;;;;;MAlBF,oBACf,KACA,qHAyBW;;;;MAIX;;;;kBAxBY,KAAK,UAAU,KAAK,MAAM,CAAC,EAAE;;;;;MAwB/B;;;;AAIhB;;;;;;;ACnDA,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,aAAa;KACf,MAAM;KACN,OAAO,CAAC,IAAI,WAAW,QAAQ,CAAC;IAClC,CAAC,CACH;GACF,CAAC;EACH,EACF;CACF;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-redoc",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.0-beta.56",
|
|
4
|
+
"description": "Generate a beautiful, interactive ReDoc API reference page from your OpenAPI specification. Produces a standalone HTML file with a responsive, developer-friendly UI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-docs",
|
|
7
|
-
"
|
|
7
|
+
"api-reference",
|
|
8
|
+
"code-generation",
|
|
8
9
|
"codegen",
|
|
9
10
|
"documentation",
|
|
10
|
-
"interactive-docs",
|
|
11
11
|
"kubb",
|
|
12
12
|
"openapi",
|
|
13
|
-
"plugins",
|
|
14
13
|
"redoc",
|
|
15
14
|
"swagger",
|
|
16
15
|
"typescript"
|
|
@@ -25,8 +24,6 @@
|
|
|
25
24
|
"files": [
|
|
26
25
|
"src",
|
|
27
26
|
"dist",
|
|
28
|
-
"static",
|
|
29
|
-
"extension.yaml",
|
|
30
27
|
"!/**/**.test.**",
|
|
31
28
|
"!/**/__tests__/**",
|
|
32
29
|
"!/**/__snapshots__/**"
|
|
@@ -51,30 +48,23 @@
|
|
|
51
48
|
"registry": "https://registry.npmjs.org/"
|
|
52
49
|
},
|
|
53
50
|
"dependencies": {
|
|
54
|
-
"@kubb/adapter-oas": "5.0.0-beta.
|
|
55
|
-
"@kubb/core": "5.0.0-beta.
|
|
56
|
-
"handlebars": "^4.7.9"
|
|
51
|
+
"@kubb/adapter-oas": "5.0.0-beta.55",
|
|
52
|
+
"@kubb/core": "5.0.0-beta.55"
|
|
57
53
|
},
|
|
58
54
|
"devDependencies": {
|
|
59
55
|
"@internals/utils": "0.0.0"
|
|
60
56
|
},
|
|
61
|
-
"size-limit": [
|
|
62
|
-
{
|
|
63
|
-
"path": "./dist/*.js",
|
|
64
|
-
"limit": "510 KiB",
|
|
65
|
-
"gzip": true
|
|
66
|
-
}
|
|
67
|
-
],
|
|
68
57
|
"engines": {
|
|
69
58
|
"node": ">=22"
|
|
70
59
|
},
|
|
71
60
|
"scripts": {
|
|
72
|
-
"build": "tsdown
|
|
73
|
-
"clean": "
|
|
61
|
+
"build": "tsdown",
|
|
62
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
74
63
|
"lint": "oxlint .",
|
|
75
64
|
"lint:fix": "oxlint --fix .",
|
|
76
65
|
"release": "pnpm publish --no-git-check",
|
|
77
66
|
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
67
|
+
"release:stage": "pnpm stage publish --no-git-check",
|
|
78
68
|
"start": "tsdown --watch",
|
|
79
69
|
"test": "vitest --passWithNoTests",
|
|
80
70
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/src/plugin.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import { trimExtName } from '@internals/utils'
|
|
3
2
|
import type { AdapterOas } from '@kubb/adapter-oas'
|
|
4
3
|
import { adapterOasName } from '@kubb/adapter-oas'
|
|
5
4
|
|
|
@@ -8,10 +7,35 @@ import { version } from '../package.json'
|
|
|
8
7
|
import { getPageHTML } from './redoc.tsx'
|
|
9
8
|
import type { PluginRedoc } from './types.ts'
|
|
10
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Canonical plugin name for `@kubb/plugin-redoc`. Used for driver lookups and
|
|
12
|
+
* cross-plugin dependency references.
|
|
13
|
+
*/
|
|
11
14
|
export const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Generates a self-contained static HTML documentation page from your OpenAPI
|
|
18
|
+
* spec using Redoc. The file is regenerated on every Kubb build, so the docs
|
|
19
|
+
* stay in lockstep with the spec the rest of your code is generated from.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { defineConfig } from 'kubb'
|
|
24
|
+
* import { pluginRedoc } from '@kubb/plugin-redoc'
|
|
25
|
+
*
|
|
26
|
+
* export default defineConfig({
|
|
27
|
+
* input: { path: './petStore.yaml' },
|
|
28
|
+
* output: { path: './src/gen' },
|
|
29
|
+
* plugins: [
|
|
30
|
+
* pluginRedoc({ output: { path: 'docs.html' } }),
|
|
31
|
+
* ],
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
13
35
|
export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
|
|
14
36
|
const { output = { path: 'docs.html' } } = options
|
|
37
|
+
const extname = path.extname(output.path)
|
|
38
|
+
const name = extname ? output.path.slice(0, -extname.length) : output.path
|
|
15
39
|
|
|
16
40
|
return {
|
|
17
41
|
name: pluginRedocName,
|
|
@@ -21,7 +45,7 @@ export const pluginRedoc = definePlugin<PluginRedoc>((options) => {
|
|
|
21
45
|
async 'kubb:plugin:setup'(ctx) {
|
|
22
46
|
ctx.setOptions({
|
|
23
47
|
output,
|
|
24
|
-
name
|
|
48
|
+
name,
|
|
25
49
|
exclude: [],
|
|
26
50
|
override: [],
|
|
27
51
|
})
|
package/src/redoc.tsx
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import fs from 'node:fs'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import { fileURLToPath } from 'node:url'
|
|
4
1
|
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
2
|
|
|
10
3
|
type BuildDocsOptions = {
|
|
11
4
|
title?: string
|
|
@@ -13,12 +6,31 @@ type BuildDocsOptions = {
|
|
|
13
6
|
templateOptions?: any
|
|
14
7
|
}
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
const htmlEscapes: Record<string, string> = {
|
|
10
|
+
'&': '&',
|
|
11
|
+
'<': '<',
|
|
12
|
+
'>': '>',
|
|
13
|
+
'"': '"',
|
|
14
|
+
"'": ''',
|
|
15
|
+
'`': '`',
|
|
16
|
+
'=': '=',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function escapeHtml(value: string) {
|
|
20
|
+
return value.replace(/[&<>"'`=]/g, (char) => htmlEscapes[char] ?? char)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Renders a self-contained Redoc HTML page for an OpenAPI document. The page
|
|
25
|
+
* embeds the spec inline and pulls Redoc's bundle from a CDN at runtime, so
|
|
26
|
+
* the generated file works without further build steps.
|
|
27
|
+
*/
|
|
28
|
+
export async function getPageHTML(api: AdapterOas['document'], { title, disableGoogleFont }: BuildDocsOptions = {}) {
|
|
29
|
+
const pageTitle = escapeHtml(title || api.info.title || 'ReDoc documentation')
|
|
30
|
+
const googleFont = disableGoogleFont
|
|
31
|
+
? ''
|
|
32
|
+
: `<link href='https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700' rel='stylesheet' />`
|
|
33
|
+
const redocHTML = `
|
|
22
34
|
<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
|
|
23
35
|
<div id="redoc-container"></div>
|
|
24
36
|
<script>
|
|
@@ -27,8 +39,27 @@ export async function getPageHTML(api: AdapterOas['document'], { title, disableG
|
|
|
27
39
|
"expandResponses": "200,400"
|
|
28
40
|
}, document.getElementById('redoc-container'))
|
|
29
41
|
</script>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
`
|
|
43
|
+
|
|
44
|
+
return `<html>
|
|
45
|
+
|
|
46
|
+
<head>
|
|
47
|
+
<meta charset='utf8' />
|
|
48
|
+
<title>${pageTitle}</title>
|
|
49
|
+
<!-- needed for adaptive design -->
|
|
50
|
+
<meta name='viewport' content='width=device-width, initial-scale=1' />
|
|
51
|
+
<style>
|
|
52
|
+
body {
|
|
53
|
+
padding: 0;
|
|
54
|
+
margin: 0;
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
57
|
+
${googleFont}
|
|
58
|
+
</head>
|
|
59
|
+
|
|
60
|
+
<body>
|
|
61
|
+
${redocHTML}
|
|
62
|
+
</body>
|
|
63
|
+
|
|
64
|
+
</html>`
|
|
34
65
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { Exclude, Include, Output, Override, PluginFactoryOptions } from '@kubb/core'
|
|
2
2
|
|
|
3
3
|
export type Options = {
|
|
4
|
+
/**
|
|
5
|
+
* Output location of the generated Redoc HTML file. The path is resolved
|
|
6
|
+
* against the global `output.path` set on `defineConfig`.
|
|
7
|
+
*/
|
|
4
8
|
output?: {
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
10
|
+
* File path of the generated HTML, relative to the global `output.path`.
|
|
11
|
+
* Unlike most plugins, this points at a single file rather than a directory.
|
|
7
12
|
*
|
|
8
13
|
* @default 'docs.html'
|
|
9
14
|
*/
|
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/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
|