@kubb/plugin-redoc 3.7.3 → 3.7.5

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 CHANGED
@@ -5,25 +5,14 @@ var core = require('@kubb/core');
5
5
  var pluginOas = require('@kubb/plugin-oas');
6
6
  var fs = require('fs');
7
7
  var pkg = require('handlebars');
8
- var server = require('react-dom/server');
9
- var redoc = require('redoc');
10
- var styledComponents = require('styled-components');
11
- var jsxRuntime = require('react/jsx-runtime');
12
8
 
13
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
10
 
15
11
  var path2__default = /*#__PURE__*/_interopDefault(path2);
16
12
  var fs__default = /*#__PURE__*/_interopDefault(fs);
17
13
  var pkg__default = /*#__PURE__*/_interopDefault(pkg);
18
- var redoc__default = /*#__PURE__*/_interopDefault(redoc);
19
14
 
20
15
  var __getOwnPropNames = Object.getOwnPropertyNames;
21
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
22
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
23
- }) : x)(function(x) {
24
- if (typeof require !== "undefined") return require.apply(this, arguments);
25
- throw Error('Dynamic require of "' + x + '" is not supported');
26
- });
27
16
  var __esm = (fn, res) => function __init() {
28
17
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
29
18
  };
@@ -48,46 +37,21 @@ function trimExtName(text) {
48
37
 
49
38
  // src/redoc.tsx
50
39
  init_cjs_shims();
51
- function escapeClosingScriptTag(str) {
52
- return str.replace(/<\/script>/g, "<\\/script>");
53
- }
54
- function escapeUnicode(str) {
55
- return str.replace(/\u2028|\u2029/g, (m) => "\\u202" + (m === "\u2028" ? "8" : "9"));
56
- }
57
- function sanitizeJSONString(str) {
58
- return escapeClosingScriptTag(escapeUnicode(str));
59
- }
60
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions, redocOptions = {} } = {}) {
61
- const apiUrl = redocOptions.specUrl;
62
- const { Redoc, createStore } = redoc__default.default || __require("redoc");
63
- const store = await createStore(api, apiUrl, redocOptions);
64
- const sheet = new styledComponents.ServerStyleSheet();
65
- const error = console.error;
66
- console.error = (...args) => {
67
- if (/defaultProps/.test(args[0])) return;
68
- error(...args);
69
- };
70
- const App = Redoc;
71
- const html = server.renderToString(sheet.collectStyles(/* @__PURE__ */ jsxRuntime.jsx(App, { ...{ store } })));
72
- const state = await store.toJS();
73
- const css = sheet.getStyleTags();
40
+ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
74
41
  const templateFileName = path2__default.default.join(__dirname, "../static/redoc.hbs");
75
42
  const template = pkg__default.default.compile(fs__default.default.readFileSync(templateFileName).toString());
76
43
  return template({
77
- redocHTML: `
78
- <div id="redoc">${html || ""}</div>
79
- <script>
80
- ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ""}
81
-
82
- var container = document.getElementById('redoc');
83
- Redoc.${"hydrate(__redoc_state, container)"};
84
-
85
- </script>`,
86
- redocHead: (
87
- // biome-ignore lint/style/useTemplate: <explanation>
88
- `<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>` + css
89
- ),
90
44
  title: title || api.info.title || "ReDoc documentation",
45
+ redocHTML: `
46
+ <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
47
+ <div id="redoc-container"></div>
48
+ <script>
49
+ const data = ${JSON.stringify(api, null, 2)};
50
+ Redoc.init(data, {
51
+ "expandResponses": "200,400"
52
+ }, document.getElementById('redoc-container'))
53
+ </script>
54
+ `,
91
55
  disableGoogleFont,
92
56
  templateOptions
93
57
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.52.3_@types+node@20.17.30__jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["redoc","ServerStyleSheet","renderToString","jsx","path","pkg","fs","createPlugin","pluginOasName","PluginManager"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,sLAAA,GAAA;AAAA;AAAA,CAAA,CAAA;;;ACAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;AAIO,SAAS,YAAY,IAAsB,EAAA;AAChD,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,WAAA,EAAa,EAAE,CAAA;AACrC;;;ACNA,cAAA,EAAA;AAgBA,SAAS,uBAAuB,GAAqB,EAAA;AACnD,EAAO,OAAA,GAAA,CAAI,OAAQ,CAAA,aAAA,EAAe,aAAa,CAAA;AACjD;AAGA,SAAS,cAAc,GAAqB,EAAA;AAE1C,EAAO,OAAA,GAAA,CAAI,QAAQ,gBAAkB,EAAA,CAAC,MAAM,QAAY,IAAA,CAAA,KAAM,QAAW,GAAA,GAAA,GAAM,GAAI,CAAA,CAAA;AACrF;AAEA,SAAS,mBAAmB,GAAqB,EAAA;AAC/C,EAAO,OAAA,sBAAA,CAAuB,aAAc,CAAA,GAAG,CAAC,CAAA;AAClD;AAEA,eAAsB,WAAA,CAAY,GAA2B,EAAA,EAAE,KAAO,EAAA,iBAAA,EAAmB,eAAiB,EAAA,YAAA,GAAe,EAAC,EAAwB,GAAA,EAAI,EAAA;AACpJ,EAAA,MAAM,SAAS,YAAa,CAAA,OAAA;AAC5B,EAAA,MAAM,EAAE,KAAO,EAAA,WAAA,EAAgB,GAAAA,sBAAA,IAAS,UAAQ,OAAO,CAAA;AACvD,EAAA,MAAM,KAAQ,GAAA,MAAM,WAAY,CAAA,GAAA,EAAK,QAAQ,YAAY,CAAA;AACzD,EAAM,MAAA,KAAA,GAAQ,IAAIC,iCAAiB,EAAA;AAEnC,EAAA,MAAM,QAAQ,OAAQ,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AY,KAAA;AAChE,EAAA,MAAM,EAAE,MAAS,GAAA,EAAE,IAAM,EAAA,WAAA,IAAkB,GAAA,OAAA;AAE3C,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,eAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,IAAA,EAAM,WAAY,CAAA,MAAA,CAAO,IAAI;AAAA,KAC/B;AAAA,IACA,GAAA,EAAK,CAACC,uBAAa,CAAA;AAAA,IACnB,MAAM,UAAa,GAAA;AACjB,MAAM,MAAA,CAAC,aAAa,CAAyB,GAAAC,kBAAA,CAAc,mBAA8B,IAAK,CAAA,OAAA,EAAS,CAACD,uBAAa,CAAC,CAAA;AACtH,MAAA,MAAM,GAAM,GAAA,MAAM,aAAc,CAAA,OAAA,CAAQ,MAAO,EAAA;AAE/C,MAAA,MAAM,IAAI,WAAY,EAAA;AAEtB,MAAM,MAAA,IAAA,GAAOJ,uBAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,GAAA,CAAI,GAAG,CAAA;AAE1C,MAAM,MAAA,IAAA,CAAK,WAAY,CAAA,KAAA,CAAMA,sBAAK,CAAA,OAAA,CAAQ,MAAM,MAAO,CAAA,IAAA,IAAQ,aAAa,CAAA,EAAG,QAAQ,CAAA;AAAA;AACzF,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","export { pluginRedoc, pluginRedocName } from './plugin.ts'\nexport type { PluginRedoc } from './types.ts'\n","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName } from '@kubb/fs'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.context.getOas()\n\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)\n },\n }\n})\n","export { clean } from './clean.ts'\nexport { getRelativePath, read, readSync } from './read.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\nimport { renderToString } from 'react-dom/server'\nimport redoc from 'redoc'\nimport { ServerStyleSheet } from 'styled-components'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n redocOptions?: any\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeClosingScriptTag(str: string): string {\n return str.replace(/<\\/script>/g, '<\\\\/script>')\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeUnicode(str: string): string {\n // biome-ignore lint/style/useTemplate: <explanation>\n return str.replace(/\\u2028|\\u2029/g, (m) => '\\\\u202' + (m === '\\u2028' ? '8' : '9'))\n}\n\nfunction sanitizeJSONString(str: string): string {\n return escapeClosingScriptTag(escapeUnicode(str))\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions, redocOptions = {} }: BuildDocsOptions = {}) {\n const apiUrl = redocOptions.specUrl\n const { Redoc, createStore } = redoc || require('redoc')\n const store = await createStore(api, apiUrl, redocOptions)\n const sheet = new ServerStyleSheet()\n\n const error = console.error\n console.error = (...args: any) => {\n if (/defaultProps/.test(args[0])) return\n error(...args)\n }\n\n const App = Redoc as any\n\n const html = renderToString(sheet.collectStyles(<App {...{ store }} />))\n const state = await store.toJS()\n const css = sheet.getStyleTags()\n\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n redocHTML: `\n <div id=\"redoc\">${html || ''}</div>\n <script>\n ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}\n\n var container = document.getElementById('redoc');\n Redoc.${'hydrate(__redoc_state, container)'};\n\n </script>`,\n redocHead:\n // biome-ignore lint/style/useTemplate: <explanation>\n `<script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"></script>` + css,\n title: title || api.info.title || 'ReDoc documentation',\n disableGoogleFont,\n templateOptions,\n })\n}\n"]}
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.52.3_@types+node@20.17.30__jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/assets/cjs_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["path","pkg","fs","createPlugin","pluginOasName","PluginManager"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,sLAAA,GAAA;AAAA;AAAA,CAAA,CAAA;;;ACAA,cAAA,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c,mBAA8B,IAAK,CAAA,OAAA,EAAS,CAACD,uBAAa,CAAC,CAAA;AACtH,MAAA,MAAM,GAAM,GAAA,MAAM,aAAc,CAAA,OAAA,CAAQ,MAAO,EAAA;AAE/C,MAAA,MAAM,IAAI,WAAY,EAAA;AAEtB,MAAM,MAAA,IAAA,GAAOJ,uBAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,GAAA,CAAI,GAAG,CAAA;AAE1C,MAAM,MAAA,IAAA,CAAK,WAAY,CAAA,KAAA,CAAMA,sBAAK,CAAA,OAAA,CAAQ,MAAM,MAAO,CAAA,IAAA,IAAQ,aAAa,CAAA,EAAG,QAAQ,CAAA;AAAA;AACzF,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","export { pluginRedoc, pluginRedocName } from './plugin.ts'\nexport type { PluginRedoc } from './types.ts'\n","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName } from '@kubb/fs'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.context.getOas()\n\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)\n },\n }\n})\n","export { clean } from './clean.ts'\nexport { getRelativePath, read, readSync } from './read.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n 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 disableGoogleFont,\n templateOptions,\n })\n}\n"]}
package/dist/index.js CHANGED
@@ -5,18 +5,8 @@ import { createPlugin, PluginManager } from '@kubb/core';
5
5
  import { pluginOasName } from '@kubb/plugin-oas';
6
6
  import fs from 'node:fs';
7
7
  import pkg from 'handlebars';
8
- import { renderToString } from 'react-dom/server';
9
- import redoc from 'redoc';
10
- import { ServerStyleSheet } from 'styled-components';
11
- import { jsx } from 'react/jsx-runtime';
12
8
 
13
9
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
15
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
16
- }) : x)(function(x) {
17
- if (typeof require !== "undefined") return require.apply(this, arguments);
18
- throw Error('Dynamic require of "' + x + '" is not supported');
19
- });
20
10
  var __esm = (fn, res) => function __init() {
21
11
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
22
12
  };
@@ -43,46 +33,21 @@ function trimExtName(text) {
43
33
 
44
34
  // src/redoc.tsx
45
35
  init_esm_shims();
46
- function escapeClosingScriptTag(str) {
47
- return str.replace(/<\/script>/g, "<\\/script>");
48
- }
49
- function escapeUnicode(str) {
50
- return str.replace(/\u2028|\u2029/g, (m) => "\\u202" + (m === "\u2028" ? "8" : "9"));
51
- }
52
- function sanitizeJSONString(str) {
53
- return escapeClosingScriptTag(escapeUnicode(str));
54
- }
55
- async function getPageHTML(api, { title, disableGoogleFont, templateOptions, redocOptions = {} } = {}) {
56
- const apiUrl = redocOptions.specUrl;
57
- const { Redoc, createStore } = redoc || __require("redoc");
58
- const store = await createStore(api, apiUrl, redocOptions);
59
- const sheet = new ServerStyleSheet();
60
- const error = console.error;
61
- console.error = (...args) => {
62
- if (/defaultProps/.test(args[0])) return;
63
- error(...args);
64
- };
65
- const App = Redoc;
66
- const html = renderToString(sheet.collectStyles(/* @__PURE__ */ jsx(App, { ...{ store } })));
67
- const state = await store.toJS();
68
- const css = sheet.getStyleTags();
36
+ async function getPageHTML(api, { title, disableGoogleFont, templateOptions } = {}) {
69
37
  const templateFileName = path3.join(__dirname, "../static/redoc.hbs");
70
38
  const template = pkg.compile(fs.readFileSync(templateFileName).toString());
71
39
  return template({
72
- redocHTML: `
73
- <div id="redoc">${html || ""}</div>
74
- <script>
75
- ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ""}
76
-
77
- var container = document.getElementById('redoc');
78
- Redoc.${"hydrate(__redoc_state, container)"};
79
-
80
- </script>`,
81
- redocHead: (
82
- // biome-ignore lint/style/useTemplate: <explanation>
83
- `<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>` + css
84
- ),
85
40
  title: title || api.info.title || "ReDoc documentation",
41
+ redocHTML: `
42
+ <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
43
+ <div id="redoc-container"></div>
44
+ <script>
45
+ const data = ${JSON.stringify(api, null, 2)};
46
+ Redoc.init(data, {
47
+ "expandResponses": "200,400"
48
+ }, document.getElementById('redoc-container'))
49
+ </script>
50
+ `,
86
51
  disableGoogleFont,
87
52
  templateOptions
88
53
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.52.3_@types+node@20.17.30__jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAIM,aACA,UAEO,EAAA,SAAA;AAPb,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,sLAAA,GAAA;AAIA,IAAM,WAAc,GAAA,MAAM,aAAc,CAAA,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AACvD,IAAM,UAAa,GAAA,MAAM,IAAK,CAAA,OAAA,CAAQ,aAAa,CAAA;AAE5C,IAAM,4BAAuC,UAAA,EAAA;AAAA;AAAA,CAAA,CAAA;;;ACPpD,cAAA,EAAA;;;ACAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;AAIO,SAAS,YAAY,IAAsB,EAAA;AAChD,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,WAAA,EAAa,EAAE,CAAA;AACrC;;;ACNA,cAAA,EAAA;AAgBA,SAAS,uBAAuB,GAAqB,EAAA;A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,OAAA,CAAQ,MAAO,EAAA;AAE/C,MAAA,MAAM,IAAI,WAAY,EAAA;AAEtB,MAAM,MAAA,IAAA,GAAOA,MAAK,OAAQ,CAAA,IAAA,CAAK,OAAO,IAAM,EAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA;AACnE,MAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,GAAA,CAAI,GAAG,CAAA;AAE1C,MAAM,MAAA,IAAA,CAAK,WAAY,CAAA,KAAA,CAAMA,KAAK,CAAA,OAAA,CAAQ,MAAM,MAAO,CAAA,IAAA,IAAQ,aAAa,CAAA,EAAG,QAAQ,CAAA;AAAA;AACzF,GACF;AACF,CAAC","file":"index.js","sourcesContent":["// Shim globals in esm bundle\nimport { fileURLToPath } from 'url'\nimport path from 'path'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","export { pluginRedoc, pluginRedocName } from './plugin.ts'\nexport type { PluginRedoc } from './types.ts'\n","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName } from '@kubb/fs'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.context.getOas()\n\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)\n },\n }\n})\n","export { clean } from './clean.ts'\nexport { getRelativePath, read, readSync } from './read.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\nimport { renderToString } from 'react-dom/server'\nimport redoc from 'redoc'\nimport { ServerStyleSheet } from 'styled-components'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n redocOptions?: any\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeClosingScriptTag(str: string): string {\n return str.replace(/<\\/script>/g, '<\\\\/script>')\n}\n\n// see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/\nfunction escapeUnicode(str: string): string {\n // biome-ignore lint/style/useTemplate: <explanation>\n return str.replace(/\\u2028|\\u2029/g, (m) => '\\\\u202' + (m === '\\u2028' ? '8' : '9'))\n}\n\nfunction sanitizeJSONString(str: string): string {\n return escapeClosingScriptTag(escapeUnicode(str))\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions, redocOptions = {} }: BuildDocsOptions = {}) {\n const apiUrl = redocOptions.specUrl\n const { Redoc, createStore } = redoc || require('redoc')\n const store = await createStore(api, apiUrl, redocOptions)\n const sheet = new ServerStyleSheet()\n\n const error = console.error\n console.error = (...args: any) => {\n if (/defaultProps/.test(args[0])) return\n error(...args)\n }\n\n const App = Redoc as any\n\n const html = renderToString(sheet.collectStyles(<App {...{ store }} />))\n const state = await store.toJS()\n const css = sheet.getStyleTags()\n\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n redocHTML: `\n <div id=\"redoc\">${html || ''}</div>\n <script>\n ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}\n\n var container = document.getElementById('redoc');\n Redoc.${'hydrate(__redoc_state, container)'};\n\n </script>`,\n redocHead:\n // biome-ignore lint/style/useTemplate: <explanation>\n `<script src=\"https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js\"></script>` + css,\n title: title || api.info.title || 'ReDoc documentation',\n disableGoogleFont,\n templateOptions,\n })\n}\n"]}
1
+ {"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.52.3_@types+node@20.17.30__jiti@2.4.2_postcss@8.5.3_typescript@5.8.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js","../src/index.ts","../src/plugin.ts","../../fs/src/index.ts","../src/redoc.tsx"],"names":["path"],"mappings":";;;;;;;;;;;;AAAA,IAIM,aACA,UAEO,EAAA,SAAA;AAPb,IAAA,cAAA,GAAA,KAAA,CAAA;AAAA,EAAA,sLAAA,GAAA;AAIA,IAAM,WAAc,GAAA,MAAM,aAAc,CAAA,MAAA,CAAA,IAAA,CAAY,GAAG,CAAA;AACvD,IAAM,UAAa,GAAA,MAAM,IAAK,CAAA,OAAA,CAAQ,aAAa,CAAA;AAE5C,IAAM,4BAAuC,UAAA,EAAA;AAAA;AAAA,CAAA,CAAA;;;ACPpD,cAAA,EAAA;;;ACAA,cAAA,EAAA;;;ACAA,cAAA,EAAA;AAIO,SAAS,YAAY,IAAsB,EAAA;AAChD,EAAO,OAAA,IAAA,CAAK,OAAQ,CAAA,WAAA,EAAa,EAAE,CAAA;AACrC;;;ACNA,cAAA,EAAA;AAWA,eAAsB,WAAA,CAAY,KAA2B,EAAE,KAAA,EAAO,mBAAmB,eAAgB,EAAA,GAAsB,EAAI,EAAA;AACjI,EAAA,MAAM,gBAAmBA,GAAAA,KAAAA,CAAK,IAAK,CAAA,SAAA,EAAW,qBAAqB,CAAA;AACnE,EAAM,MAAA,QAAA,GAAW,IAAI,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,CAAK,WAAY,CAAA,KAAA,CAAMA,KAAK,CAAA,OAAA,CAAQ,MAAM,MAAO,CAAA,IAAA,IAAQ,aAAa,CAAA,EAAG,QAAQ,CAAA;AAAA;AACzF,GACF;AACF,CAAC","file":"index.js","sourcesContent":["// Shim globals in esm bundle\nimport { fileURLToPath } from 'url'\nimport path from 'path'\n\nconst getFilename = () => fileURLToPath(import.meta.url)\nconst getDirname = () => path.dirname(getFilename())\n\nexport const __dirname = /* @__PURE__ */ getDirname()\nexport const __filename = /* @__PURE__ */ getFilename()\n","export { pluginRedoc, pluginRedocName } from './plugin.ts'\nexport type { PluginRedoc } from './types.ts'\n","import path from 'node:path'\n\nimport { PluginManager, createPlugin } from '@kubb/core'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport { trimExtName } from '@kubb/fs'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { getPageHTML } from './redoc.tsx'\nimport type { PluginRedoc } from './types.ts'\n\nexport const pluginRedocName = 'plugin-redoc' satisfies PluginRedoc['name']\n\nexport const pluginRedoc = createPlugin<PluginRedoc>((options) => {\n const { output = { path: 'docs.html' } } = options\n\n return {\n name: pluginRedocName,\n options: {\n output,\n name: trimExtName(output.path),\n },\n pre: [pluginOasName],\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n const oas = await swaggerPlugin.context.getOas()\n\n await oas.dereference()\n\n const root = path.resolve(this.config.root, this.config.output.path)\n const pageHTML = await getPageHTML(oas.api)\n\n await this.fileManager.write(path.resolve(root, output.path || './docs.html'), pageHTML)\n },\n }\n})\n","export { clean } from './clean.ts'\nexport { getRelativePath, read, readSync } from './read.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\nimport type { OasTypes } from '@kubb/oas'\nimport pkg from 'handlebars'\n\ntype BuildDocsOptions = {\n title?: string\n disableGoogleFont?: boolean\n templateOptions?: any\n}\n\nexport async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {\n const templateFileName = path.join(__dirname, '../static/redoc.hbs')\n const template = pkg.compile(fs.readFileSync(templateFileName).toString())\n return template({\n title: title || api.info.title || 'ReDoc documentation',\n 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 disableGoogleFont,\n templateOptions,\n })\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-redoc",
3
- "version": "3.7.3",
3
+ "version": "3.7.5",
4
4
  "description": "Beautiful docs with Redoc",
5
5
  "keywords": [
6
6
  "typescript",
@@ -42,22 +42,15 @@
42
42
  ],
43
43
  "dependencies": {
44
44
  "handlebars": "^4.7.8",
45
- "mobx": "^6.13.7",
46
- "react": "^18.3.1",
47
- "react-dom": "^18.3.1",
48
- "redoc": "^2.4.0",
49
- "styled-components": "^6.1.17",
50
- "@kubb/core": "3.7.3",
51
- "@kubb/oas": "3.7.3",
52
- "@kubb/plugin-oas": "3.7.3"
45
+ "@kubb/core": "3.7.5",
46
+ "@kubb/oas": "3.7.5",
47
+ "@kubb/plugin-oas": "3.7.5"
53
48
  },
54
49
  "devDependencies": {
55
- "@types/react": "^18.3.20",
56
- "@types/react-dom": "^18.3.6",
57
50
  "tsup": "^8.4.0",
58
51
  "typescript": "^5.8.3",
59
- "@kubb/config-ts": "3.7.3",
60
- "@kubb/config-tsup": "3.7.3"
52
+ "@kubb/config-ts": "3.7.5",
53
+ "@kubb/config-tsup": "3.7.5"
61
54
  },
62
55
  "peerDependencies": {
63
56
  "@kubb/react": "^3.0.0"
package/src/redoc.tsx CHANGED
@@ -2,66 +2,28 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import type { OasTypes } from '@kubb/oas'
4
4
  import pkg from 'handlebars'
5
- import { renderToString } from 'react-dom/server'
6
- import redoc from 'redoc'
7
- import { ServerStyleSheet } from 'styled-components'
8
5
 
9
6
  type BuildDocsOptions = {
10
7
  title?: string
11
8
  disableGoogleFont?: boolean
12
9
  templateOptions?: any
13
- redocOptions?: any
14
10
  }
15
11
 
16
- // see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
17
- function escapeClosingScriptTag(str: string): string {
18
- return str.replace(/<\/script>/g, '<\\/script>')
19
- }
20
-
21
- // see http://www.thespanner.co.uk/2011/07/25/the-json-specification-is-now-wrong/
22
- function escapeUnicode(str: string): string {
23
- // biome-ignore lint/style/useTemplate: <explanation>
24
- return str.replace(/\u2028|\u2029/g, (m) => '\\u202' + (m === '\u2028' ? '8' : '9'))
25
- }
26
-
27
- function sanitizeJSONString(str: string): string {
28
- return escapeClosingScriptTag(escapeUnicode(str))
29
- }
30
-
31
- export async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions, redocOptions = {} }: BuildDocsOptions = {}) {
32
- const apiUrl = redocOptions.specUrl
33
- const { Redoc, createStore } = redoc || require('redoc')
34
- const store = await createStore(api, apiUrl, redocOptions)
35
- const sheet = new ServerStyleSheet()
36
-
37
- const error = console.error
38
- console.error = (...args: any) => {
39
- if (/defaultProps/.test(args[0])) return
40
- error(...args)
41
- }
42
-
43
- const App = Redoc as any
44
-
45
- const html = renderToString(sheet.collectStyles(<App {...{ store }} />))
46
- const state = await store.toJS()
47
- const css = sheet.getStyleTags()
48
-
12
+ export async function getPageHTML(api: OasTypes.OASDocument, { title, disableGoogleFont, templateOptions }: BuildDocsOptions = {}) {
49
13
  const templateFileName = path.join(__dirname, '../static/redoc.hbs')
50
14
  const template = pkg.compile(fs.readFileSync(templateFileName).toString())
51
15
  return template({
52
- redocHTML: `
53
- <div id="redoc">${html || ''}</div>
54
- <script>
55
- ${`const __redoc_state = ${sanitizeJSONString(JSON.stringify(state))};` || ''}
56
-
57
- var container = document.getElementById('redoc');
58
- Redoc.${'hydrate(__redoc_state, container)'};
59
-
60
- </script>`,
61
- redocHead:
62
- // biome-ignore lint/style/useTemplate: <explanation>
63
- `<script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"></script>` + css,
64
16
  title: title || api.info.title || 'ReDoc documentation',
17
+ redocHTML: `
18
+ <script src="https://cdn.redoc.ly/redoc/latest/bundles/redoc.standalone.js"> </script>
19
+ <div id="redoc-container"></div>
20
+ <script>
21
+ const data = ${JSON.stringify(api, null, 2)};
22
+ Redoc.init(data, {
23
+ "expandResponses": "200,400"
24
+ }, document.getElementById('redoc-container'))
25
+ </script>
26
+ `,
65
27
  disableGoogleFont,
66
28
  templateOptions,
67
29
  })
package/static/redoc.hbs CHANGED
@@ -12,7 +12,6 @@
12
12
  margin: 0;
13
13
  }
14
14
  </style>
15
- {{{redocHead}}}
16
15
  {{#unless disableGoogleFont}}<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">{{/unless}}
17
16
  </head>
18
17