@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.
Files changed (97) hide show
  1. package/README.md +14 -3
  2. package/dist/{DocsLayout-YDR7DSMM.cjs → DocsLayout-IKH7BLSU.cjs} +1537 -682
  3. package/dist/DocsLayout-IKH7BLSU.cjs.map +1 -0
  4. package/dist/{DocsLayout-TKJQ5W5E.mjs → DocsLayout-JPXFUKAR.mjs} +1429 -574
  5. package/dist/DocsLayout-JPXFUKAR.mjs.map +1 -0
  6. package/dist/{PrettyCode.client-5GABIN2I.cjs → PrettyCode.client-RPDIE5CH.cjs} +104 -3
  7. package/dist/PrettyCode.client-RPDIE5CH.cjs.map +1 -0
  8. package/dist/{PrettyCode.client-IZTXXYHG.mjs → PrettyCode.client-SPMTQEG4.mjs} +106 -5
  9. package/dist/PrettyCode.client-SPMTQEG4.mjs.map +1 -0
  10. package/dist/{chunk-IULI4XII.cjs → chunk-5Q4UMSWB.cjs} +355 -9
  11. package/dist/chunk-5Q4UMSWB.cjs.map +1 -0
  12. package/dist/{chunk-VZGQC3NG.mjs → chunk-EFWOJPA6.mjs} +349 -9
  13. package/dist/chunk-EFWOJPA6.mjs.map +1 -0
  14. package/dist/index.cjs +10 -10
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +18 -0
  17. package/dist/index.d.ts +18 -0
  18. package/dist/index.mjs +5 -5
  19. package/dist/index.mjs.map +1 -1
  20. package/package.json +18 -14
  21. package/src/components/markdown/MarkdownMessage.tsx +46 -0
  22. package/src/tools/OpenapiViewer/OpenapiViewer.story.tsx +87 -178
  23. package/src/tools/OpenapiViewer/README.md +114 -6
  24. package/src/tools/OpenapiViewer/components/DocsLayout/ApiIntroSection.tsx +20 -6
  25. package/src/tools/OpenapiViewer/components/DocsLayout/DocsView.tsx +6 -0
  26. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/LanguageTabs.tsx +36 -0
  27. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/index.tsx +56 -0
  28. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/CodeSamples/useCodeSnippet.ts +77 -0
  29. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/MetaActions.tsx +146 -0
  30. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/MethodBadge.tsx +6 -0
  31. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/PathDisplay.tsx +26 -0
  32. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Header/index.tsx +87 -0
  33. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/ParamGroup.tsx +30 -0
  34. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/ParamRow.tsx +36 -0
  35. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Parameters/index.tsx +22 -0
  36. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/RequestBody/index.tsx +33 -0
  37. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/ResponseBody.tsx +76 -0
  38. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/ResponseRow.tsx +80 -0
  39. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/StatusTag.tsx +32 -0
  40. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Responses/index.tsx +21 -0
  41. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/FieldRow.tsx +106 -0
  42. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/buildTree.ts +127 -0
  43. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/index.tsx +31 -0
  44. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/SchemaFields/types.ts +28 -0
  45. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/SectionHeader.tsx +87 -0
  46. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/defaults.ts +27 -0
  47. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/Section/index.tsx +45 -0
  48. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/context.tsx +56 -0
  49. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/hooks/useSectionHash.ts +63 -0
  50. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/index.tsx +96 -0
  51. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/store/index.ts +133 -0
  52. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/store/selectors.ts +40 -0
  53. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc/types.ts +17 -0
  54. package/src/tools/OpenapiViewer/components/DocsLayout/SchemaCopyMenu.tsx +8 -2
  55. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/BrandHeader.tsx +48 -0
  56. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/CategoryBlock.tsx +33 -0
  57. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/EndpointRow.tsx +73 -0
  58. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/MethodChips.tsx +43 -0
  59. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SchemaSection.tsx +27 -0
  60. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SearchInput.tsx +45 -0
  61. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/SidebarBody.tsx +50 -0
  62. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/Toolbar.tsx +64 -0
  63. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/buildVM.ts +126 -0
  64. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/index.tsx +112 -0
  65. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/types.ts +42 -0
  66. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar/useDebouncedValue.ts +14 -0
  67. package/src/tools/OpenapiViewer/components/DocsLayout/SlideInPlayground.tsx +10 -7
  68. package/src/tools/OpenapiViewer/components/DocsLayout/TryItSheet.tsx +9 -6
  69. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/PrettyView.tsx +55 -0
  70. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/PreviewView.tsx +115 -0
  71. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/RawView.tsx +24 -0
  72. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/StatusBar.tsx +63 -0
  73. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/ViewTabs.tsx +45 -0
  74. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/detectContent.ts +97 -0
  75. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/index.tsx +93 -0
  76. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/types.ts +26 -0
  77. package/src/tools/OpenapiViewer/components/shared/ResponsePanel/useResponseView.ts +62 -0
  78. package/src/tools/OpenapiViewer/hooks/useOpenApiSchema.ts +41 -71
  79. package/src/tools/OpenapiViewer/types.ts +10 -0
  80. package/src/tools/OpenapiViewer/utils/codeSamples.ts +287 -0
  81. package/src/tools/OpenapiViewer/utils/index.ts +3 -0
  82. package/src/tools/OpenapiViewer/utils/operationToHar.ts +119 -0
  83. package/src/tools/OpenapiViewer/utils/sampler.ts +72 -0
  84. package/src/tools/PrettyCode/PrettyCode.client.tsx +88 -1
  85. package/src/tools/PrettyCode/PrettyCode.story.tsx +114 -361
  86. package/src/tools/PrettyCode/index.tsx +13 -0
  87. package/src/tools/PrettyCode/lazy.tsx +5 -0
  88. package/src/tools/PrettyCode/registerPrismLanguages.ts +111 -0
  89. package/dist/DocsLayout-TKJQ5W5E.mjs.map +0 -1
  90. package/dist/DocsLayout-YDR7DSMM.cjs.map +0 -1
  91. package/dist/PrettyCode.client-5GABIN2I.cjs.map +0 -1
  92. package/dist/PrettyCode.client-IZTXXYHG.mjs.map +0 -1
  93. package/dist/chunk-IULI4XII.cjs.map +0 -1
  94. package/dist/chunk-VZGQC3NG.mjs.map +0 -1
  95. package/src/tools/OpenapiViewer/components/DocsLayout/EndpointDoc.tsx +0 -273
  96. package/src/tools/OpenapiViewer/components/DocsLayout/Sidebar.tsx +0 -439
  97. package/src/tools/OpenapiViewer/components/shared/ResponsePanel.tsx +0 -127
@@ -3,10 +3,13 @@ import React3, { lazy, createContext, useState, useMemo, useCallback, Suspense,
3
3
  import '@djangocfg/ui-core/styles/palette';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import ReactMarkdown from 'react-markdown';
6
+ import rehypeRaw from 'rehype-raw';
7
+ import rehypeSanitize, { defaultSchema } from 'rehype-sanitize';
6
8
  import remarkGfm from 'remark-gfm';
7
9
  import { CopyButton } from '@djangocfg/ui-core/components';
8
10
  import { useSessionStorage, useResolvedTheme } from '@djangocfg/ui-core/hooks';
9
- import consola from 'consola';
11
+ import consola2 from 'consola';
12
+ import { sample } from 'openapi-sampler';
10
13
 
11
14
  var MermaidClient = lazy(() => import('./Mermaid.client-XFQ74OYN.mjs'));
12
15
  var LoadingFallback = /* @__PURE__ */ __name(() => /* @__PURE__ */ jsx("div", { className: "flex justify-center items-center min-h-[100px]", children: /* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full h-6 w-6 border-b-2 border-primary" }) }), "LoadingFallback");
@@ -14,7 +17,7 @@ var Mermaid = /* @__PURE__ */ __name((props) => {
14
17
  return /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(LoadingFallback, {}), children: /* @__PURE__ */ jsx(MermaidClient, { ...props }) });
15
18
  }, "Mermaid");
16
19
  var Mermaid_default = Mermaid;
17
- var PrettyCodeClient = lazy(() => import('./PrettyCode.client-IZTXXYHG.mjs'));
20
+ var PrettyCodeClient = lazy(() => import('./PrettyCode.client-SPMTQEG4.mjs'));
18
21
  var LoadingFallback2 = /* @__PURE__ */ __name(() => /* @__PURE__ */ jsx("div", { className: "relative rounded-sm border border-border overflow-hidden bg-muted dark:bg-zinc-900", children: /* @__PURE__ */ jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
19
22
  /* @__PURE__ */ jsx("div", { className: "animate-pulse h-4 w-4 rounded-full bg-muted-foreground/20" }),
20
23
  /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: "Loading code..." })
@@ -138,6 +141,26 @@ function useCollapsibleContent(content, options = {}) {
138
141
  };
139
142
  }
140
143
  __name(useCollapsibleContent, "useCollapsibleContent");
144
+ var HTML_SCHEMA = {
145
+ ...defaultSchema,
146
+ tagNames: [
147
+ ...defaultSchema.tagNames ?? [],
148
+ "br",
149
+ "b",
150
+ "i",
151
+ "u",
152
+ "s",
153
+ "sub",
154
+ "sup",
155
+ "small",
156
+ "mark",
157
+ "kbd",
158
+ "code",
159
+ "pre",
160
+ "details",
161
+ "summary"
162
+ ]
163
+ };
141
164
  var extractTextFromChildren = /* @__PURE__ */ __name((children) => {
142
165
  if (typeof children === "string") {
143
166
  return children;
@@ -288,6 +311,9 @@ var hasMarkdownSyntax = /* @__PURE__ */ __name((text) => {
288
311
  if (text.trim().includes("\n")) {
289
312
  return true;
290
313
  }
314
+ if (/<\/?[a-zA-Z][a-zA-Z0-9-]*(\s[^>]*)?\/?>/.test(text)) {
315
+ return true;
316
+ }
291
317
  const markdownPatterns = [
292
318
  /^#{1,6}\s/m,
293
319
  // Headers
@@ -465,6 +491,7 @@ var MarkdownMessage = /* @__PURE__ */ __name(({
465
491
  ReactMarkdown,
466
492
  {
467
493
  remarkPlugins: [remarkGfm],
494
+ rehypePlugins: [rehypeRaw, [rehypeSanitize, HTML_SCHEMA]],
468
495
  components,
469
496
  children: displayContent
470
497
  }
@@ -491,6 +518,299 @@ function findApiKeyById(apiKeys, keyId) {
491
518
  }
492
519
  __name(findApiKeyById, "findApiKeyById");
493
520
 
521
+ // src/tools/OpenapiViewer/utils/codeSamples.ts
522
+ var CODE_SAMPLE_TARGETS = [
523
+ { id: "curl", label: "cURL", prism: "bash" },
524
+ { id: "fetch", label: "JavaScript", prism: "javascript" },
525
+ { id: "axios", label: "Node (axios)", prism: "javascript" },
526
+ { id: "python", label: "Python", prism: "python" },
527
+ { id: "go", label: "Go", prism: "go" },
528
+ { id: "php", label: "PHP", prism: "php" },
529
+ { id: "ruby", label: "Ruby", prism: "ruby" },
530
+ { id: "java", label: "Java", prism: "java" }
531
+ ];
532
+ function goRawString(s) {
533
+ return s.includes("`") ? JSON.stringify(s) : `\`${s}\``;
534
+ }
535
+ __name(goRawString, "goRawString");
536
+ function rubyHeredoc(s) {
537
+ return `<<~JSON
538
+ ${s}
539
+ JSON`;
540
+ }
541
+ __name(rubyHeredoc, "rubyHeredoc");
542
+ function phpHeredoc(s) {
543
+ return `<<<JSON
544
+ ${s}
545
+ JSON`;
546
+ }
547
+ __name(phpHeredoc, "phpHeredoc");
548
+ function javaTextBlock(s) {
549
+ if (s.includes('"""')) return JSON.stringify(s);
550
+ return `"""
551
+ ${s}
552
+ """`;
553
+ }
554
+ __name(javaTextBlock, "javaTextBlock");
555
+ function fullUrl(har) {
556
+ if (!har.queryString.length) return har.url;
557
+ const qs = har.queryString.map((p) => `${encodeURIComponent(p.name)}=${encodeURIComponent(p.value)}`).join("&");
558
+ const sep = har.url.includes("?") ? "&" : "?";
559
+ return `${har.url}${sep}${qs}`;
560
+ }
561
+ __name(fullUrl, "fullUrl");
562
+ function shellEscape(value) {
563
+ return `'${value.replace(/'/g, `'\\''`)}'`;
564
+ }
565
+ __name(shellEscape, "shellEscape");
566
+ function renderCurl(har) {
567
+ const lines = [`curl -X ${har.method} ${shellEscape(fullUrl(har))}`];
568
+ for (const h of har.headers) {
569
+ lines.push(` -H ${shellEscape(`${h.name}: ${h.value}`)}`);
570
+ }
571
+ if (har.postData?.text) {
572
+ lines.push(` -d ${shellEscape(har.postData.text)}`);
573
+ }
574
+ return lines.join(" \\\n");
575
+ }
576
+ __name(renderCurl, "renderCurl");
577
+ function jsHeadersLiteral(har, indent) {
578
+ if (!har.headers.length) return "{}";
579
+ const entries = har.headers.map((h) => `${indent} ${JSON.stringify(h.name)}: ${JSON.stringify(h.value)}`).join(",\n");
580
+ return `{
581
+ ${entries},
582
+ ${indent}}`;
583
+ }
584
+ __name(jsHeadersLiteral, "jsHeadersLiteral");
585
+ function jsTemplateLiteral(s) {
586
+ if (/[`$]/.test(s)) return JSON.stringify(s);
587
+ return `\`${s}\``;
588
+ }
589
+ __name(jsTemplateLiteral, "jsTemplateLiteral");
590
+ function renderFetch(har) {
591
+ const url = fullUrl(har);
592
+ const options = [` method: ${JSON.stringify(har.method)}`];
593
+ if (har.headers.length) {
594
+ options.push(` headers: ${jsHeadersLiteral(har, " ")}`);
595
+ }
596
+ if (har.postData?.text) {
597
+ options.push(` body: ${jsTemplateLiteral(har.postData.text)}`);
598
+ }
599
+ return `const response = await fetch(${JSON.stringify(url)}, {
600
+ ${options.join(",\n")},
601
+ });
602
+ const data = await response.json();`;
603
+ }
604
+ __name(renderFetch, "renderFetch");
605
+ function renderAxios(har) {
606
+ const url = fullUrl(har);
607
+ const config = [
608
+ ` method: ${JSON.stringify(har.method.toLowerCase())}`,
609
+ ` url: ${JSON.stringify(url)}`
610
+ ];
611
+ if (har.headers.length) {
612
+ config.push(` headers: ${jsHeadersLiteral(har, " ")}`);
613
+ }
614
+ if (har.postData?.text) {
615
+ config.push(` data: ${har.postData.text}`);
616
+ }
617
+ return `import axios from 'axios';
618
+
619
+ const { data } = await axios({
620
+ ${config.join(",\n")},
621
+ });`;
622
+ }
623
+ __name(renderAxios, "renderAxios");
624
+ function renderPython(har) {
625
+ const lines = [`import requests`, ``];
626
+ lines.push(`url = ${JSON.stringify(fullUrl(har))}`);
627
+ if (har.headers.length) {
628
+ const headerEntries = har.headers.map((h) => ` ${JSON.stringify(h.name)}: ${JSON.stringify(h.value)}`).join(",\n");
629
+ lines.push(`headers = {
630
+ ${headerEntries},
631
+ }`);
632
+ }
633
+ if (har.postData?.text) {
634
+ lines.push(`payload = ${har.postData.text}`);
635
+ }
636
+ const args = [`url`];
637
+ if (har.headers.length) args.push(`headers=headers`);
638
+ if (har.postData?.text) args.push(`json=payload`);
639
+ lines.push(``, `response = requests.${har.method.toLowerCase()}(${args.join(", ")})`);
640
+ lines.push(`data = response.json()`);
641
+ return lines.join("\n");
642
+ }
643
+ __name(renderPython, "renderPython");
644
+ function renderGo(har) {
645
+ const url = fullUrl(har);
646
+ const lines = [
647
+ `package main`,
648
+ ``,
649
+ `import (`,
650
+ ` "fmt"`,
651
+ ` "io"`
652
+ ];
653
+ if (har.postData?.text) lines.push(` "strings"`);
654
+ lines.push(` "net/http"`);
655
+ lines.push(`)`, ``, `func main() {`);
656
+ if (har.postData?.text) {
657
+ lines.push(` payload := strings.NewReader(${goRawString(har.postData.text)})`);
658
+ lines.push(` req, _ := http.NewRequest(${JSON.stringify(har.method)}, ${JSON.stringify(url)}, payload)`);
659
+ } else {
660
+ lines.push(` req, _ := http.NewRequest(${JSON.stringify(har.method)}, ${JSON.stringify(url)}, nil)`);
661
+ }
662
+ for (const h of har.headers) {
663
+ lines.push(` req.Header.Add(${JSON.stringify(h.name)}, ${JSON.stringify(h.value)})`);
664
+ }
665
+ lines.push(
666
+ ``,
667
+ ` res, _ := http.DefaultClient.Do(req)`,
668
+ ` defer res.Body.Close()`,
669
+ ` body, _ := io.ReadAll(res.Body)`,
670
+ ` fmt.Println(string(body))`,
671
+ `}`
672
+ );
673
+ return lines.join("\n");
674
+ }
675
+ __name(renderGo, "renderGo");
676
+ function renderPhp(har) {
677
+ const lines = [`<?php`, ``, `$curl = curl_init();`, ``, `curl_setopt_array($curl, [`];
678
+ lines.push(` CURLOPT_URL => ${JSON.stringify(fullUrl(har))},`);
679
+ lines.push(` CURLOPT_RETURNTRANSFER => true,`);
680
+ lines.push(` CURLOPT_CUSTOMREQUEST => ${JSON.stringify(har.method)},`);
681
+ if (har.postData?.text) {
682
+ lines.push(` CURLOPT_POSTFIELDS => ${phpHeredoc(har.postData.text)},`);
683
+ }
684
+ if (har.headers.length) {
685
+ const headerList = har.headers.map((h) => ` ${JSON.stringify(`${h.name}: ${h.value}`)}`).join(",\n");
686
+ lines.push(` CURLOPT_HTTPHEADER => [
687
+ ${headerList},
688
+ ],`);
689
+ }
690
+ lines.push(`]);`, ``, `$response = curl_exec($curl);`, `curl_close($curl);`, `echo $response;`);
691
+ return lines.join("\n");
692
+ }
693
+ __name(renderPhp, "renderPhp");
694
+ function renderRuby(har) {
695
+ const lines = [
696
+ `require 'net/http'`,
697
+ `require 'uri'`,
698
+ `require 'json'`,
699
+ ``,
700
+ `uri = URI(${JSON.stringify(fullUrl(har))})`,
701
+ `http = Net::HTTP.new(uri.host, uri.port)`,
702
+ `http.use_ssl = uri.scheme == 'https'`,
703
+ ``
704
+ ];
705
+ const methodClass = har.method.charAt(0) + har.method.slice(1).toLowerCase();
706
+ lines.push(`request = Net::HTTP::${methodClass}.new(uri)`);
707
+ for (const h of har.headers) {
708
+ lines.push(`request[${JSON.stringify(h.name)}] = ${JSON.stringify(h.value)}`);
709
+ }
710
+ if (har.postData?.text) {
711
+ lines.push(`request.body = ${rubyHeredoc(har.postData.text)}`);
712
+ }
713
+ lines.push(``, `response = http.request(request)`, `puts response.body`);
714
+ return lines.join("\n");
715
+ }
716
+ __name(renderRuby, "renderRuby");
717
+ function renderJava(har) {
718
+ const lines = [
719
+ `OkHttpClient client = new OkHttpClient();`,
720
+ ``
721
+ ];
722
+ if (har.postData?.text) {
723
+ lines.push(
724
+ `MediaType mediaType = MediaType.parse("application/json");`,
725
+ `RequestBody body = RequestBody.create(mediaType, ${javaTextBlock(har.postData.text)});`,
726
+ ``
727
+ );
728
+ }
729
+ lines.push(`Request request = new Request.Builder()`);
730
+ lines.push(` .url(${JSON.stringify(fullUrl(har))})`);
731
+ if (har.postData?.text) {
732
+ lines.push(` .method(${JSON.stringify(har.method)}, body)`);
733
+ } else {
734
+ lines.push(` .method(${JSON.stringify(har.method)}, null)`);
735
+ }
736
+ for (const h of har.headers) {
737
+ lines.push(` .addHeader(${JSON.stringify(h.name)}, ${JSON.stringify(h.value)})`);
738
+ }
739
+ lines.push(` .build();`, ``, `Response response = client.newCall(request).execute();`);
740
+ return lines.join("\n");
741
+ }
742
+ __name(renderJava, "renderJava");
743
+ var RENDERERS = {
744
+ curl: renderCurl,
745
+ fetch: renderFetch,
746
+ axios: renderAxios,
747
+ python: renderPython,
748
+ go: renderGo,
749
+ php: renderPhp,
750
+ ruby: renderRuby,
751
+ java: renderJava
752
+ };
753
+ function renderSnippet(har, targetId) {
754
+ const renderer = RENDERERS[targetId];
755
+ if (!renderer) return null;
756
+ try {
757
+ return renderer(har);
758
+ } catch {
759
+ return null;
760
+ }
761
+ }
762
+ __name(renderSnippet, "renderSnippet");
763
+
764
+ // src/tools/OpenapiViewer/utils/operationToHar.ts
765
+ function buildUrl(endpoint, parameters, baseUrl) {
766
+ const pathParamNames = new Set(
767
+ (endpoint.parameters ?? []).filter((p) => endpoint.path.includes(`{${p.name}}`)).map((p) => p.name)
768
+ );
769
+ let path = endpoint.path;
770
+ for (const name of pathParamNames) {
771
+ const value = parameters[name] ?? `{${name}}`;
772
+ path = path.replaceAll(`{${name}}`, encodeURIComponent(value));
773
+ }
774
+ const queryString = [];
775
+ for (const param of endpoint.parameters ?? []) {
776
+ if (pathParamNames.has(param.name)) continue;
777
+ const value = parameters[param.name];
778
+ if (value === void 0 || value === "") continue;
779
+ queryString.push({ name: param.name, value });
780
+ }
781
+ const url = baseUrl ? `${baseUrl.replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}` : path;
782
+ return { url, queryString };
783
+ }
784
+ __name(buildUrl, "buildUrl");
785
+ function buildHarRequest(input) {
786
+ const { endpoint, body, parameters = {}, headers = {}, baseUrl } = input;
787
+ const { url, queryString } = buildUrl(endpoint, parameters, baseUrl);
788
+ const hasBody = Boolean(body && body.trim().length > 0);
789
+ const bodyMime = hasBody ? "application/json" : void 0;
790
+ const mergedHeaders = {};
791
+ if (hasBody && bodyMime) mergedHeaders["Content-Type"] = bodyMime;
792
+ mergedHeaders["Accept"] = "application/json";
793
+ for (const [k, v] of Object.entries(headers)) {
794
+ if (v === void 0 || v === "") continue;
795
+ mergedHeaders[k] = v;
796
+ }
797
+ const har = {
798
+ method: endpoint.method.toUpperCase(),
799
+ url,
800
+ httpVersion: "HTTP/1.1",
801
+ headers: Object.entries(mergedHeaders).map(([name, value]) => ({ name, value })),
802
+ queryString,
803
+ cookies: [],
804
+ headersSize: -1,
805
+ bodySize: hasBody ? new TextEncoder().encode(body).length : 0
806
+ };
807
+ if (hasBody && bodyMime) {
808
+ har.postData = { mimeType: bodyMime, text: body };
809
+ }
810
+ return har;
811
+ }
812
+ __name(buildHarRequest, "buildHarRequest");
813
+
494
814
  // src/tools/OpenapiViewer/utils/versionManager.ts
495
815
  var API_VERSIONS = [
496
816
  {
@@ -570,6 +890,26 @@ var parseRequestHeaders = /* @__PURE__ */ __name((headersString) => {
570
890
  return { "Content-Type": "application/json" };
571
891
  }
572
892
  }, "parseRequestHeaders");
893
+ function sampleSchema(schema, options = {}, spec) {
894
+ if (!schema) return null;
895
+ try {
896
+ return sample(schema, options, spec);
897
+ } catch (err) {
898
+ consola2.warn("[OpenapiViewer] sampleSchema failed:", err, { schema });
899
+ return null;
900
+ }
901
+ }
902
+ __name(sampleSchema, "sampleSchema");
903
+ function sampleSchemaJson(schema, options = {}, spec) {
904
+ const value = sampleSchema(schema, options, spec);
905
+ if (value === null || value === void 0) return void 0;
906
+ try {
907
+ return JSON.stringify(value, null, 2);
908
+ } catch {
909
+ return void 0;
910
+ }
911
+ }
912
+ __name(sampleSchemaJson, "sampleSchemaJson");
573
913
 
574
914
  // src/tools/OpenapiViewer/utils/url.ts
575
915
  var PATH_PARAM_RE = /\{([^{}]+)\}/g;
@@ -978,7 +1318,7 @@ var PlaygroundProvider = /* @__PURE__ */ __name(({ children, config }) => {
978
1318
  dispatch({ type: "SYNC_API_KEY_HEADER", headers: JSON.stringify(headers, null, 2) });
979
1319
  }
980
1320
  } catch (error) {
981
- consola.error("Error updating headers:", error);
1321
+ consola2.error("Error updating headers:", error);
982
1322
  }
983
1323
  }, [state.selectedApiKey, apiKeys]);
984
1324
  useEffect(() => {
@@ -1009,7 +1349,7 @@ var PlaygroundProvider = /* @__PURE__ */ __name(({ children, config }) => {
1009
1349
  const clearAll = useCallback(() => dispatch({ type: "RESET" }), []);
1010
1350
  const sendRequest = useCallback(async () => {
1011
1351
  if (!state.requestUrl) {
1012
- consola.error("No URL provided");
1352
+ consola2.error("No URL provided");
1013
1353
  return;
1014
1354
  }
1015
1355
  abortControllerRef.current?.abort();
@@ -1053,10 +1393,10 @@ var PlaygroundProvider = /* @__PURE__ */ __name(({ children, config }) => {
1053
1393
  duration
1054
1394
  }
1055
1395
  });
1056
- consola.success(`${state.requestMethod} ${state.requestUrl} \u2192 ${response.status} (${duration}ms)`);
1396
+ consola2.success(`${state.requestMethod} ${state.requestUrl} \u2192 ${response.status} (${duration}ms)`);
1057
1397
  } catch (error) {
1058
1398
  if (error instanceof DOMException && error.name === "AbortError") return;
1059
- consola.error("Request failed:", error);
1399
+ consola2.error("Request failed:", error);
1060
1400
  dispatch({
1061
1401
  type: "REQUEST_ERROR",
1062
1402
  response: {
@@ -1095,6 +1435,6 @@ var PlaygroundProvider = /* @__PURE__ */ __name(({ children, config }) => {
1095
1435
  return /* @__PURE__ */ jsx(PlaygroundContext.Provider, { value: contextValue, children });
1096
1436
  }, "PlaygroundProvider");
1097
1437
 
1098
- export { MarkdownMessage, Mermaid_default, PlaygroundProvider, PrettyCode_default, UrlBuilder, deduplicateEndpoints, dereferenceSchema, endpointToMarkdown, findApiKeyById, formatBytes, isValidJson, joinUrl, parseRequestHeaders, relativePath, resolveAbsolute, resolveBaseUrl, toCompactJson, toMarkdown, toRawJson, useCollapsibleContent, usePlaygroundContext };
1099
- //# sourceMappingURL=chunk-VZGQC3NG.mjs.map
1100
- //# sourceMappingURL=chunk-VZGQC3NG.mjs.map
1438
+ export { CODE_SAMPLE_TARGETS, MarkdownMessage, Mermaid_default, PlaygroundProvider, PrettyCode_default, UrlBuilder, buildHarRequest, deduplicateEndpoints, dereferenceSchema, endpointToMarkdown, findApiKeyById, formatBytes, isValidJson, joinUrl, parseRequestHeaders, relativePath, renderSnippet, resolveAbsolute, resolveBaseUrl, sampleSchemaJson, toCompactJson, toMarkdown, toRawJson, useCollapsibleContent, usePlaygroundContext };
1439
+ //# sourceMappingURL=chunk-EFWOJPA6.mjs.map
1440
+ //# sourceMappingURL=chunk-EFWOJPA6.mjs.map