@djangocfg/ui-tools 2.1.289 → 2.1.290
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 +14 -3
- package/dist/{DocsLayout-YDR7DSMM.cjs → DocsLayout-IKH7BLSU.cjs} +1537 -682
- package/dist/DocsLayout-IKH7BLSU.cjs.map +1 -0
- package/dist/{DocsLayout-TKJQ5W5E.mjs → DocsLayout-JPXFUKAR.mjs} +1429 -574
- package/dist/DocsLayout-JPXFUKAR.mjs.map +1 -0
- package/dist/{PrettyCode.client-5GABIN2I.cjs → PrettyCode.client-RPDIE5CH.cjs} +104 -3
- package/dist/PrettyCode.client-RPDIE5CH.cjs.map +1 -0
- package/dist/{PrettyCode.client-IZTXXYHG.mjs → PrettyCode.client-SPMTQEG4.mjs} +106 -5
- package/dist/PrettyCode.client-SPMTQEG4.mjs.map +1 -0
- package/dist/{chunk-IULI4XII.cjs → chunk-5Q4UMSWB.cjs} +355 -9
- package/dist/chunk-5Q4UMSWB.cjs.map +1 -0
- package/dist/{chunk-VZGQC3NG.mjs → chunk-EFWOJPA6.mjs} +349 -9
- package/dist/chunk-EFWOJPA6.mjs.map +1 -0
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +18 -14
- package/src/components/markdown/MarkdownMessage.tsx +46 -0
- package/src/tools/OpenapiViewer/OpenapiViewer.story.tsx +87 -178
- package/src/tools/OpenapiViewer/README.md +114 -6
- package/src/tools/OpenapiViewer/components/DocsLayout/ApiIntroSection.tsx +20 -6
- package/src/tools/OpenapiViewer/components/DocsLayout/DocsView.tsx +6 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/LanguageTabs.tsx +36 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/index.tsx +56 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/useCodeSnippet.ts +77 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/MetaActions.tsx +146 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/MethodBadge.tsx +6 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/PathDisplay.tsx +26 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/index.tsx +87 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/ParamGroup.tsx +30 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/ParamRow.tsx +36 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/index.tsx +22 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/RequestBody/index.tsx +33 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/ResponseBody.tsx +76 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/ResponseRow.tsx +80 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/StatusTag.tsx +32 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/index.tsx +21 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/FieldRow.tsx +106 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/buildTree.ts +127 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/index.tsx +31 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/types.ts +28 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/SectionHeader.tsx +87 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/defaults.ts +27 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/index.tsx +45 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/context.tsx +56 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/hooks/useSectionHash.ts +63 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/index.tsx +96 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/store/index.ts +133 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/store/selectors.ts +40 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/types.ts +17 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/SchemaCopyMenu.tsx +8 -2
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/BrandHeader.tsx +48 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/CategoryBlock.tsx +33 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/EndpointRow.tsx +73 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/MethodChips.tsx +43 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SchemaSection.tsx +27 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SearchInput.tsx +45 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SidebarBody.tsx +50 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/Toolbar.tsx +64 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/buildVM.ts +126 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/index.tsx +112 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/types.ts +42 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/useDebouncedValue.ts +14 -0
- package/src/tools/OpenapiViewer/components/DocsLayout/SlideInPlayground.tsx +10 -7
- package/src/tools/OpenapiViewer/components/DocsLayout/TryItSheet.tsx +9 -6
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/PrettyView.tsx +55 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/PreviewView.tsx +115 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/RawView.tsx +24 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/StatusBar.tsx +63 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/ViewTabs.tsx +45 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/detectContent.ts +97 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/index.tsx +93 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/types.ts +26 -0
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel/useResponseView.ts +62 -0
- package/src/tools/OpenapiViewer/hooks/useOpenApiSchema.ts +41 -71
- package/src/tools/OpenapiViewer/types.ts +10 -0
- package/src/tools/OpenapiViewer/utils/codeSamples.ts +287 -0
- package/src/tools/OpenapiViewer/utils/index.ts +3 -0
- package/src/tools/OpenapiViewer/utils/operationToHar.ts +119 -0
- package/src/tools/OpenapiViewer/utils/sampler.ts +72 -0
- package/src/tools/PrettyCode/PrettyCode.client.tsx +88 -1
- package/src/tools/PrettyCode/PrettyCode.story.tsx +114 -361
- package/src/tools/PrettyCode/index.tsx +13 -0
- package/src/tools/PrettyCode/lazy.tsx +5 -0
- package/src/tools/PrettyCode/registerPrismLanguages.ts +111 -0
- package/dist/DocsLayout-TKJQ5W5E.mjs.map +0 -1
- package/dist/DocsLayout-YDR7DSMM.cjs.map +0 -1
- package/dist/PrettyCode.client-5GABIN2I.cjs.map +0 -1
- package/dist/PrettyCode.client-IZTXXYHG.mjs.map +0 -1
- package/dist/chunk-IULI4XII.cjs.map +0 -1
- package/dist/chunk-VZGQC3NG.mjs.map +0 -1
- package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc.tsx +0 -273
- package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar.tsx +0 -439
- package/src/tools/OpenapiViewer/components/shared/ResponsePanel.tsx +0 -127
|
@@ -5,17 +5,22 @@ var React3 = require('react');
|
|
|
5
5
|
require('@djangocfg/ui-core/styles/palette');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var ReactMarkdown = require('react-markdown');
|
|
8
|
+
var rehypeRaw = require('rehype-raw');
|
|
9
|
+
var rehypeSanitize = require('rehype-sanitize');
|
|
8
10
|
var remarkGfm = require('remark-gfm');
|
|
9
11
|
var components = require('@djangocfg/ui-core/components');
|
|
10
12
|
var hooks = require('@djangocfg/ui-core/hooks');
|
|
11
|
-
var
|
|
13
|
+
var consola2 = require('consola');
|
|
14
|
+
var openapiSampler = require('openapi-sampler');
|
|
12
15
|
|
|
13
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
17
|
|
|
15
18
|
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
16
19
|
var ReactMarkdown__default = /*#__PURE__*/_interopDefault(ReactMarkdown);
|
|
20
|
+
var rehypeRaw__default = /*#__PURE__*/_interopDefault(rehypeRaw);
|
|
21
|
+
var rehypeSanitize__default = /*#__PURE__*/_interopDefault(rehypeSanitize);
|
|
17
22
|
var remarkGfm__default = /*#__PURE__*/_interopDefault(remarkGfm);
|
|
18
|
-
var
|
|
23
|
+
var consola2__default = /*#__PURE__*/_interopDefault(consola2);
|
|
19
24
|
|
|
20
25
|
var MermaidClient = React3.lazy(() => import('./Mermaid.client-RSWUUHIL.cjs'));
|
|
21
26
|
var LoadingFallback = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(() => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-center items-center min-h-[100px]", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-primary" }) }), "LoadingFallback");
|
|
@@ -23,7 +28,7 @@ var Mermaid = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((props) => {
|
|
|
23
28
|
return /* @__PURE__ */ jsxRuntime.jsx(React3.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(LoadingFallback, {}), children: /* @__PURE__ */ jsxRuntime.jsx(MermaidClient, { ...props }) });
|
|
24
29
|
}, "Mermaid");
|
|
25
30
|
var Mermaid_default = Mermaid;
|
|
26
|
-
var PrettyCodeClient = React3.lazy(() => import('./PrettyCode.client-
|
|
31
|
+
var PrettyCodeClient = React3.lazy(() => import('./PrettyCode.client-RPDIE5CH.cjs'));
|
|
27
32
|
var LoadingFallback2 = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(() => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative rounded-sm border border-border overflow-hidden bg-muted dark:bg-zinc-900", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
28
33
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-pulse h-4 w-4 rounded-full bg-muted-foreground/20" }),
|
|
29
34
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: "Loading code..." })
|
|
@@ -147,6 +152,26 @@ function useCollapsibleContent(content, options = {}) {
|
|
|
147
152
|
};
|
|
148
153
|
}
|
|
149
154
|
chunkWGEGR3DF_cjs.__name(useCollapsibleContent, "useCollapsibleContent");
|
|
155
|
+
var HTML_SCHEMA = {
|
|
156
|
+
...rehypeSanitize.defaultSchema,
|
|
157
|
+
tagNames: [
|
|
158
|
+
...rehypeSanitize.defaultSchema.tagNames ?? [],
|
|
159
|
+
"br",
|
|
160
|
+
"b",
|
|
161
|
+
"i",
|
|
162
|
+
"u",
|
|
163
|
+
"s",
|
|
164
|
+
"sub",
|
|
165
|
+
"sup",
|
|
166
|
+
"small",
|
|
167
|
+
"mark",
|
|
168
|
+
"kbd",
|
|
169
|
+
"code",
|
|
170
|
+
"pre",
|
|
171
|
+
"details",
|
|
172
|
+
"summary"
|
|
173
|
+
]
|
|
174
|
+
};
|
|
150
175
|
var extractTextFromChildren = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((children) => {
|
|
151
176
|
if (typeof children === "string") {
|
|
152
177
|
return children;
|
|
@@ -297,6 +322,9 @@ var hasMarkdownSyntax = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((text) => {
|
|
|
297
322
|
if (text.trim().includes("\n")) {
|
|
298
323
|
return true;
|
|
299
324
|
}
|
|
325
|
+
if (/<\/?[a-zA-Z][a-zA-Z0-9-]*(\s[^>]*)?\/?>/.test(text)) {
|
|
326
|
+
return true;
|
|
327
|
+
}
|
|
300
328
|
const markdownPatterns = [
|
|
301
329
|
/^#{1,6}\s/m,
|
|
302
330
|
// Headers
|
|
@@ -474,6 +502,7 @@ var MarkdownMessage = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(({
|
|
|
474
502
|
ReactMarkdown__default.default,
|
|
475
503
|
{
|
|
476
504
|
remarkPlugins: [remarkGfm__default.default],
|
|
505
|
+
rehypePlugins: [rehypeRaw__default.default, [rehypeSanitize__default.default, HTML_SCHEMA]],
|
|
477
506
|
components,
|
|
478
507
|
children: displayContent
|
|
479
508
|
}
|
|
@@ -500,6 +529,299 @@ function findApiKeyById(apiKeys, keyId) {
|
|
|
500
529
|
}
|
|
501
530
|
chunkWGEGR3DF_cjs.__name(findApiKeyById, "findApiKeyById");
|
|
502
531
|
|
|
532
|
+
// src/tools/OpenapiViewer/utils/codeSamples.ts
|
|
533
|
+
var CODE_SAMPLE_TARGETS = [
|
|
534
|
+
{ id: "curl", label: "cURL", prism: "bash" },
|
|
535
|
+
{ id: "fetch", label: "JavaScript", prism: "javascript" },
|
|
536
|
+
{ id: "axios", label: "Node (axios)", prism: "javascript" },
|
|
537
|
+
{ id: "python", label: "Python", prism: "python" },
|
|
538
|
+
{ id: "go", label: "Go", prism: "go" },
|
|
539
|
+
{ id: "php", label: "PHP", prism: "php" },
|
|
540
|
+
{ id: "ruby", label: "Ruby", prism: "ruby" },
|
|
541
|
+
{ id: "java", label: "Java", prism: "java" }
|
|
542
|
+
];
|
|
543
|
+
function goRawString(s) {
|
|
544
|
+
return s.includes("`") ? JSON.stringify(s) : `\`${s}\``;
|
|
545
|
+
}
|
|
546
|
+
chunkWGEGR3DF_cjs.__name(goRawString, "goRawString");
|
|
547
|
+
function rubyHeredoc(s) {
|
|
548
|
+
return `<<~JSON
|
|
549
|
+
${s}
|
|
550
|
+
JSON`;
|
|
551
|
+
}
|
|
552
|
+
chunkWGEGR3DF_cjs.__name(rubyHeredoc, "rubyHeredoc");
|
|
553
|
+
function phpHeredoc(s) {
|
|
554
|
+
return `<<<JSON
|
|
555
|
+
${s}
|
|
556
|
+
JSON`;
|
|
557
|
+
}
|
|
558
|
+
chunkWGEGR3DF_cjs.__name(phpHeredoc, "phpHeredoc");
|
|
559
|
+
function javaTextBlock(s) {
|
|
560
|
+
if (s.includes('"""')) return JSON.stringify(s);
|
|
561
|
+
return `"""
|
|
562
|
+
${s}
|
|
563
|
+
"""`;
|
|
564
|
+
}
|
|
565
|
+
chunkWGEGR3DF_cjs.__name(javaTextBlock, "javaTextBlock");
|
|
566
|
+
function fullUrl(har) {
|
|
567
|
+
if (!har.queryString.length) return har.url;
|
|
568
|
+
const qs = har.queryString.map((p) => `${encodeURIComponent(p.name)}=${encodeURIComponent(p.value)}`).join("&");
|
|
569
|
+
const sep = har.url.includes("?") ? "&" : "?";
|
|
570
|
+
return `${har.url}${sep}${qs}`;
|
|
571
|
+
}
|
|
572
|
+
chunkWGEGR3DF_cjs.__name(fullUrl, "fullUrl");
|
|
573
|
+
function shellEscape(value) {
|
|
574
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
575
|
+
}
|
|
576
|
+
chunkWGEGR3DF_cjs.__name(shellEscape, "shellEscape");
|
|
577
|
+
function renderCurl(har) {
|
|
578
|
+
const lines = [`curl -X ${har.method} ${shellEscape(fullUrl(har))}`];
|
|
579
|
+
for (const h of har.headers) {
|
|
580
|
+
lines.push(` -H ${shellEscape(`${h.name}: ${h.value}`)}`);
|
|
581
|
+
}
|
|
582
|
+
if (har.postData?.text) {
|
|
583
|
+
lines.push(` -d ${shellEscape(har.postData.text)}`);
|
|
584
|
+
}
|
|
585
|
+
return lines.join(" \\\n");
|
|
586
|
+
}
|
|
587
|
+
chunkWGEGR3DF_cjs.__name(renderCurl, "renderCurl");
|
|
588
|
+
function jsHeadersLiteral(har, indent) {
|
|
589
|
+
if (!har.headers.length) return "{}";
|
|
590
|
+
const entries = har.headers.map((h) => `${indent} ${JSON.stringify(h.name)}: ${JSON.stringify(h.value)}`).join(",\n");
|
|
591
|
+
return `{
|
|
592
|
+
${entries},
|
|
593
|
+
${indent}}`;
|
|
594
|
+
}
|
|
595
|
+
chunkWGEGR3DF_cjs.__name(jsHeadersLiteral, "jsHeadersLiteral");
|
|
596
|
+
function jsTemplateLiteral(s) {
|
|
597
|
+
if (/[`$]/.test(s)) return JSON.stringify(s);
|
|
598
|
+
return `\`${s}\``;
|
|
599
|
+
}
|
|
600
|
+
chunkWGEGR3DF_cjs.__name(jsTemplateLiteral, "jsTemplateLiteral");
|
|
601
|
+
function renderFetch(har) {
|
|
602
|
+
const url = fullUrl(har);
|
|
603
|
+
const options = [` method: ${JSON.stringify(har.method)}`];
|
|
604
|
+
if (har.headers.length) {
|
|
605
|
+
options.push(` headers: ${jsHeadersLiteral(har, " ")}`);
|
|
606
|
+
}
|
|
607
|
+
if (har.postData?.text) {
|
|
608
|
+
options.push(` body: ${jsTemplateLiteral(har.postData.text)}`);
|
|
609
|
+
}
|
|
610
|
+
return `const response = await fetch(${JSON.stringify(url)}, {
|
|
611
|
+
${options.join(",\n")},
|
|
612
|
+
});
|
|
613
|
+
const data = await response.json();`;
|
|
614
|
+
}
|
|
615
|
+
chunkWGEGR3DF_cjs.__name(renderFetch, "renderFetch");
|
|
616
|
+
function renderAxios(har) {
|
|
617
|
+
const url = fullUrl(har);
|
|
618
|
+
const config = [
|
|
619
|
+
` method: ${JSON.stringify(har.method.toLowerCase())}`,
|
|
620
|
+
` url: ${JSON.stringify(url)}`
|
|
621
|
+
];
|
|
622
|
+
if (har.headers.length) {
|
|
623
|
+
config.push(` headers: ${jsHeadersLiteral(har, " ")}`);
|
|
624
|
+
}
|
|
625
|
+
if (har.postData?.text) {
|
|
626
|
+
config.push(` data: ${har.postData.text}`);
|
|
627
|
+
}
|
|
628
|
+
return `import axios from 'axios';
|
|
629
|
+
|
|
630
|
+
const { data } = await axios({
|
|
631
|
+
${config.join(",\n")},
|
|
632
|
+
});`;
|
|
633
|
+
}
|
|
634
|
+
chunkWGEGR3DF_cjs.__name(renderAxios, "renderAxios");
|
|
635
|
+
function renderPython(har) {
|
|
636
|
+
const lines = [`import requests`, ``];
|
|
637
|
+
lines.push(`url = ${JSON.stringify(fullUrl(har))}`);
|
|
638
|
+
if (har.headers.length) {
|
|
639
|
+
const headerEntries = har.headers.map((h) => ` ${JSON.stringify(h.name)}: ${JSON.stringify(h.value)}`).join(",\n");
|
|
640
|
+
lines.push(`headers = {
|
|
641
|
+
${headerEntries},
|
|
642
|
+
}`);
|
|
643
|
+
}
|
|
644
|
+
if (har.postData?.text) {
|
|
645
|
+
lines.push(`payload = ${har.postData.text}`);
|
|
646
|
+
}
|
|
647
|
+
const args = [`url`];
|
|
648
|
+
if (har.headers.length) args.push(`headers=headers`);
|
|
649
|
+
if (har.postData?.text) args.push(`json=payload`);
|
|
650
|
+
lines.push(``, `response = requests.${har.method.toLowerCase()}(${args.join(", ")})`);
|
|
651
|
+
lines.push(`data = response.json()`);
|
|
652
|
+
return lines.join("\n");
|
|
653
|
+
}
|
|
654
|
+
chunkWGEGR3DF_cjs.__name(renderPython, "renderPython");
|
|
655
|
+
function renderGo(har) {
|
|
656
|
+
const url = fullUrl(har);
|
|
657
|
+
const lines = [
|
|
658
|
+
`package main`,
|
|
659
|
+
``,
|
|
660
|
+
`import (`,
|
|
661
|
+
` "fmt"`,
|
|
662
|
+
` "io"`
|
|
663
|
+
];
|
|
664
|
+
if (har.postData?.text) lines.push(` "strings"`);
|
|
665
|
+
lines.push(` "net/http"`);
|
|
666
|
+
lines.push(`)`, ``, `func main() {`);
|
|
667
|
+
if (har.postData?.text) {
|
|
668
|
+
lines.push(` payload := strings.NewReader(${goRawString(har.postData.text)})`);
|
|
669
|
+
lines.push(` req, _ := http.NewRequest(${JSON.stringify(har.method)}, ${JSON.stringify(url)}, payload)`);
|
|
670
|
+
} else {
|
|
671
|
+
lines.push(` req, _ := http.NewRequest(${JSON.stringify(har.method)}, ${JSON.stringify(url)}, nil)`);
|
|
672
|
+
}
|
|
673
|
+
for (const h of har.headers) {
|
|
674
|
+
lines.push(` req.Header.Add(${JSON.stringify(h.name)}, ${JSON.stringify(h.value)})`);
|
|
675
|
+
}
|
|
676
|
+
lines.push(
|
|
677
|
+
``,
|
|
678
|
+
` res, _ := http.DefaultClient.Do(req)`,
|
|
679
|
+
` defer res.Body.Close()`,
|
|
680
|
+
` body, _ := io.ReadAll(res.Body)`,
|
|
681
|
+
` fmt.Println(string(body))`,
|
|
682
|
+
`}`
|
|
683
|
+
);
|
|
684
|
+
return lines.join("\n");
|
|
685
|
+
}
|
|
686
|
+
chunkWGEGR3DF_cjs.__name(renderGo, "renderGo");
|
|
687
|
+
function renderPhp(har) {
|
|
688
|
+
const lines = [`<?php`, ``, `$curl = curl_init();`, ``, `curl_setopt_array($curl, [`];
|
|
689
|
+
lines.push(` CURLOPT_URL => ${JSON.stringify(fullUrl(har))},`);
|
|
690
|
+
lines.push(` CURLOPT_RETURNTRANSFER => true,`);
|
|
691
|
+
lines.push(` CURLOPT_CUSTOMREQUEST => ${JSON.stringify(har.method)},`);
|
|
692
|
+
if (har.postData?.text) {
|
|
693
|
+
lines.push(` CURLOPT_POSTFIELDS => ${phpHeredoc(har.postData.text)},`);
|
|
694
|
+
}
|
|
695
|
+
if (har.headers.length) {
|
|
696
|
+
const headerList = har.headers.map((h) => ` ${JSON.stringify(`${h.name}: ${h.value}`)}`).join(",\n");
|
|
697
|
+
lines.push(` CURLOPT_HTTPHEADER => [
|
|
698
|
+
${headerList},
|
|
699
|
+
],`);
|
|
700
|
+
}
|
|
701
|
+
lines.push(`]);`, ``, `$response = curl_exec($curl);`, `curl_close($curl);`, `echo $response;`);
|
|
702
|
+
return lines.join("\n");
|
|
703
|
+
}
|
|
704
|
+
chunkWGEGR3DF_cjs.__name(renderPhp, "renderPhp");
|
|
705
|
+
function renderRuby(har) {
|
|
706
|
+
const lines = [
|
|
707
|
+
`require 'net/http'`,
|
|
708
|
+
`require 'uri'`,
|
|
709
|
+
`require 'json'`,
|
|
710
|
+
``,
|
|
711
|
+
`uri = URI(${JSON.stringify(fullUrl(har))})`,
|
|
712
|
+
`http = Net::HTTP.new(uri.host, uri.port)`,
|
|
713
|
+
`http.use_ssl = uri.scheme == 'https'`,
|
|
714
|
+
``
|
|
715
|
+
];
|
|
716
|
+
const methodClass = har.method.charAt(0) + har.method.slice(1).toLowerCase();
|
|
717
|
+
lines.push(`request = Net::HTTP::${methodClass}.new(uri)`);
|
|
718
|
+
for (const h of har.headers) {
|
|
719
|
+
lines.push(`request[${JSON.stringify(h.name)}] = ${JSON.stringify(h.value)}`);
|
|
720
|
+
}
|
|
721
|
+
if (har.postData?.text) {
|
|
722
|
+
lines.push(`request.body = ${rubyHeredoc(har.postData.text)}`);
|
|
723
|
+
}
|
|
724
|
+
lines.push(``, `response = http.request(request)`, `puts response.body`);
|
|
725
|
+
return lines.join("\n");
|
|
726
|
+
}
|
|
727
|
+
chunkWGEGR3DF_cjs.__name(renderRuby, "renderRuby");
|
|
728
|
+
function renderJava(har) {
|
|
729
|
+
const lines = [
|
|
730
|
+
`OkHttpClient client = new OkHttpClient();`,
|
|
731
|
+
``
|
|
732
|
+
];
|
|
733
|
+
if (har.postData?.text) {
|
|
734
|
+
lines.push(
|
|
735
|
+
`MediaType mediaType = MediaType.parse("application/json");`,
|
|
736
|
+
`RequestBody body = RequestBody.create(mediaType, ${javaTextBlock(har.postData.text)});`,
|
|
737
|
+
``
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
lines.push(`Request request = new Request.Builder()`);
|
|
741
|
+
lines.push(` .url(${JSON.stringify(fullUrl(har))})`);
|
|
742
|
+
if (har.postData?.text) {
|
|
743
|
+
lines.push(` .method(${JSON.stringify(har.method)}, body)`);
|
|
744
|
+
} else {
|
|
745
|
+
lines.push(` .method(${JSON.stringify(har.method)}, null)`);
|
|
746
|
+
}
|
|
747
|
+
for (const h of har.headers) {
|
|
748
|
+
lines.push(` .addHeader(${JSON.stringify(h.name)}, ${JSON.stringify(h.value)})`);
|
|
749
|
+
}
|
|
750
|
+
lines.push(` .build();`, ``, `Response response = client.newCall(request).execute();`);
|
|
751
|
+
return lines.join("\n");
|
|
752
|
+
}
|
|
753
|
+
chunkWGEGR3DF_cjs.__name(renderJava, "renderJava");
|
|
754
|
+
var RENDERERS = {
|
|
755
|
+
curl: renderCurl,
|
|
756
|
+
fetch: renderFetch,
|
|
757
|
+
axios: renderAxios,
|
|
758
|
+
python: renderPython,
|
|
759
|
+
go: renderGo,
|
|
760
|
+
php: renderPhp,
|
|
761
|
+
ruby: renderRuby,
|
|
762
|
+
java: renderJava
|
|
763
|
+
};
|
|
764
|
+
function renderSnippet(har, targetId) {
|
|
765
|
+
const renderer = RENDERERS[targetId];
|
|
766
|
+
if (!renderer) return null;
|
|
767
|
+
try {
|
|
768
|
+
return renderer(har);
|
|
769
|
+
} catch {
|
|
770
|
+
return null;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
chunkWGEGR3DF_cjs.__name(renderSnippet, "renderSnippet");
|
|
774
|
+
|
|
775
|
+
// src/tools/OpenapiViewer/utils/operationToHar.ts
|
|
776
|
+
function buildUrl(endpoint, parameters, baseUrl) {
|
|
777
|
+
const pathParamNames = new Set(
|
|
778
|
+
(endpoint.parameters ?? []).filter((p) => endpoint.path.includes(`{${p.name}}`)).map((p) => p.name)
|
|
779
|
+
);
|
|
780
|
+
let path = endpoint.path;
|
|
781
|
+
for (const name of pathParamNames) {
|
|
782
|
+
const value = parameters[name] ?? `{${name}}`;
|
|
783
|
+
path = path.replaceAll(`{${name}}`, encodeURIComponent(value));
|
|
784
|
+
}
|
|
785
|
+
const queryString = [];
|
|
786
|
+
for (const param of endpoint.parameters ?? []) {
|
|
787
|
+
if (pathParamNames.has(param.name)) continue;
|
|
788
|
+
const value = parameters[param.name];
|
|
789
|
+
if (value === void 0 || value === "") continue;
|
|
790
|
+
queryString.push({ name: param.name, value });
|
|
791
|
+
}
|
|
792
|
+
const url = baseUrl ? `${baseUrl.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}` : path;
|
|
793
|
+
return { url, queryString };
|
|
794
|
+
}
|
|
795
|
+
chunkWGEGR3DF_cjs.__name(buildUrl, "buildUrl");
|
|
796
|
+
function buildHarRequest(input) {
|
|
797
|
+
const { endpoint, body, parameters = {}, headers = {}, baseUrl } = input;
|
|
798
|
+
const { url, queryString } = buildUrl(endpoint, parameters, baseUrl);
|
|
799
|
+
const hasBody = Boolean(body && body.trim().length > 0);
|
|
800
|
+
const bodyMime = hasBody ? "application/json" : void 0;
|
|
801
|
+
const mergedHeaders = {};
|
|
802
|
+
if (hasBody && bodyMime) mergedHeaders["Content-Type"] = bodyMime;
|
|
803
|
+
mergedHeaders["Accept"] = "application/json";
|
|
804
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
805
|
+
if (v === void 0 || v === "") continue;
|
|
806
|
+
mergedHeaders[k] = v;
|
|
807
|
+
}
|
|
808
|
+
const har = {
|
|
809
|
+
method: endpoint.method.toUpperCase(),
|
|
810
|
+
url,
|
|
811
|
+
httpVersion: "HTTP/1.1",
|
|
812
|
+
headers: Object.entries(mergedHeaders).map(([name, value]) => ({ name, value })),
|
|
813
|
+
queryString,
|
|
814
|
+
cookies: [],
|
|
815
|
+
headersSize: -1,
|
|
816
|
+
bodySize: hasBody ? new TextEncoder().encode(body).length : 0
|
|
817
|
+
};
|
|
818
|
+
if (hasBody && bodyMime) {
|
|
819
|
+
har.postData = { mimeType: bodyMime, text: body };
|
|
820
|
+
}
|
|
821
|
+
return har;
|
|
822
|
+
}
|
|
823
|
+
chunkWGEGR3DF_cjs.__name(buildHarRequest, "buildHarRequest");
|
|
824
|
+
|
|
503
825
|
// src/tools/OpenapiViewer/utils/versionManager.ts
|
|
504
826
|
var API_VERSIONS = [
|
|
505
827
|
{
|
|
@@ -579,6 +901,26 @@ var parseRequestHeaders = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name((headersStrin
|
|
|
579
901
|
return { "Content-Type": "application/json" };
|
|
580
902
|
}
|
|
581
903
|
}, "parseRequestHeaders");
|
|
904
|
+
function sampleSchema(schema, options = {}, spec) {
|
|
905
|
+
if (!schema) return null;
|
|
906
|
+
try {
|
|
907
|
+
return openapiSampler.sample(schema, options, spec);
|
|
908
|
+
} catch (err) {
|
|
909
|
+
consola2__default.default.warn("[OpenapiViewer] sampleSchema failed:", err, { schema });
|
|
910
|
+
return null;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
chunkWGEGR3DF_cjs.__name(sampleSchema, "sampleSchema");
|
|
914
|
+
function sampleSchemaJson(schema, options = {}, spec) {
|
|
915
|
+
const value = sampleSchema(schema, options, spec);
|
|
916
|
+
if (value === null || value === void 0) return void 0;
|
|
917
|
+
try {
|
|
918
|
+
return JSON.stringify(value, null, 2);
|
|
919
|
+
} catch {
|
|
920
|
+
return void 0;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
chunkWGEGR3DF_cjs.__name(sampleSchemaJson, "sampleSchemaJson");
|
|
582
924
|
|
|
583
925
|
// src/tools/OpenapiViewer/utils/url.ts
|
|
584
926
|
var PATH_PARAM_RE = /\{([^{}]+)\}/g;
|
|
@@ -987,7 +1329,7 @@ var PlaygroundProvider = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(({ children, c
|
|
|
987
1329
|
dispatch({ type: "SYNC_API_KEY_HEADER", headers: JSON.stringify(headers, null, 2) });
|
|
988
1330
|
}
|
|
989
1331
|
} catch (error) {
|
|
990
|
-
|
|
1332
|
+
consola2__default.default.error("Error updating headers:", error);
|
|
991
1333
|
}
|
|
992
1334
|
}, [state.selectedApiKey, apiKeys]);
|
|
993
1335
|
React3.useEffect(() => {
|
|
@@ -1018,7 +1360,7 @@ var PlaygroundProvider = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(({ children, c
|
|
|
1018
1360
|
const clearAll = React3.useCallback(() => dispatch({ type: "RESET" }), []);
|
|
1019
1361
|
const sendRequest = React3.useCallback(async () => {
|
|
1020
1362
|
if (!state.requestUrl) {
|
|
1021
|
-
|
|
1363
|
+
consola2__default.default.error("No URL provided");
|
|
1022
1364
|
return;
|
|
1023
1365
|
}
|
|
1024
1366
|
abortControllerRef.current?.abort();
|
|
@@ -1062,10 +1404,10 @@ var PlaygroundProvider = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(({ children, c
|
|
|
1062
1404
|
duration
|
|
1063
1405
|
}
|
|
1064
1406
|
});
|
|
1065
|
-
|
|
1407
|
+
consola2__default.default.success(`${state.requestMethod} ${state.requestUrl} \u2192 ${response.status} (${duration}ms)`);
|
|
1066
1408
|
} catch (error) {
|
|
1067
1409
|
if (error instanceof DOMException && error.name === "AbortError") return;
|
|
1068
|
-
|
|
1410
|
+
consola2__default.default.error("Request failed:", error);
|
|
1069
1411
|
dispatch({
|
|
1070
1412
|
type: "REQUEST_ERROR",
|
|
1071
1413
|
response: {
|
|
@@ -1104,11 +1446,13 @@ var PlaygroundProvider = /* @__PURE__ */ chunkWGEGR3DF_cjs.__name(({ children, c
|
|
|
1104
1446
|
return /* @__PURE__ */ jsxRuntime.jsx(PlaygroundContext.Provider, { value: contextValue, children });
|
|
1105
1447
|
}, "PlaygroundProvider");
|
|
1106
1448
|
|
|
1449
|
+
exports.CODE_SAMPLE_TARGETS = CODE_SAMPLE_TARGETS;
|
|
1107
1450
|
exports.MarkdownMessage = MarkdownMessage;
|
|
1108
1451
|
exports.Mermaid_default = Mermaid_default;
|
|
1109
1452
|
exports.PlaygroundProvider = PlaygroundProvider;
|
|
1110
1453
|
exports.PrettyCode_default = PrettyCode_default;
|
|
1111
1454
|
exports.UrlBuilder = UrlBuilder;
|
|
1455
|
+
exports.buildHarRequest = buildHarRequest;
|
|
1112
1456
|
exports.deduplicateEndpoints = deduplicateEndpoints;
|
|
1113
1457
|
exports.dereferenceSchema = dereferenceSchema;
|
|
1114
1458
|
exports.endpointToMarkdown = endpointToMarkdown;
|
|
@@ -1118,12 +1462,14 @@ exports.isValidJson = isValidJson;
|
|
|
1118
1462
|
exports.joinUrl = joinUrl;
|
|
1119
1463
|
exports.parseRequestHeaders = parseRequestHeaders;
|
|
1120
1464
|
exports.relativePath = relativePath;
|
|
1465
|
+
exports.renderSnippet = renderSnippet;
|
|
1121
1466
|
exports.resolveAbsolute = resolveAbsolute;
|
|
1122
1467
|
exports.resolveBaseUrl = resolveBaseUrl;
|
|
1468
|
+
exports.sampleSchemaJson = sampleSchemaJson;
|
|
1123
1469
|
exports.toCompactJson = toCompactJson;
|
|
1124
1470
|
exports.toMarkdown = toMarkdown;
|
|
1125
1471
|
exports.toRawJson = toRawJson;
|
|
1126
1472
|
exports.useCollapsibleContent = useCollapsibleContent;
|
|
1127
1473
|
exports.usePlaygroundContext = usePlaygroundContext;
|
|
1128
|
-
//# sourceMappingURL=chunk-
|
|
1129
|
-
//# sourceMappingURL=chunk-
|
|
1474
|
+
//# sourceMappingURL=chunk-5Q4UMSWB.cjs.map
|
|
1475
|
+
//# sourceMappingURL=chunk-5Q4UMSWB.cjs.map
|