@mintlify/msft-sdk 1.1.18 → 1.1.21

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 (55) hide show
  1. package/dist/api-playground/ApiPlayground/ApiPlaygroundContext.js +11 -0
  2. package/dist/api-playground/ApiPlayground/ApiPlaygroundContext.js.map +1 -0
  3. package/dist/api-playground-2/ApiExamples.js +3 -3
  4. package/dist/api-playground-2/components/Example/GeneratedRequestExample.js +3 -3
  5. package/dist/api-playground-2/components/Example/GeneratedResponseExample.js +2 -2
  6. package/dist/api-playground-2/components/Example/RequestExample.js +35 -35
  7. package/dist/api-playground-2/components/Example/RequestExample.js.map +1 -1
  8. package/dist/api-playground-2/constants/index.js +20 -0
  9. package/dist/api-playground-2/constants/index.js.map +1 -0
  10. package/dist/api-playground-2/generators/createBodyData.js +67 -0
  11. package/dist/api-playground-2/generators/createBodyData.js.map +1 -0
  12. package/dist/api-playground-2/generators/createHeaders.js +45 -0
  13. package/dist/api-playground-2/generators/createHeaders.js.map +1 -0
  14. package/dist/api-playground-2/generators/generateInteractiveCodeSample.js +50 -0
  15. package/dist/api-playground-2/generators/generateInteractiveCodeSample.js.map +1 -0
  16. package/dist/api-playground-2/generators/generateRequest.js +65 -0
  17. package/dist/api-playground-2/generators/generateRequest.js.map +1 -0
  18. package/dist/api-playground-2/generators/generateResponseExampleMap.js +36 -0
  19. package/dist/api-playground-2/generators/generateResponseExampleMap.js.map +1 -0
  20. package/dist/api-playground-2/generators/generateSnippet.js +42 -0
  21. package/dist/api-playground-2/generators/generateSnippet.js.map +1 -0
  22. package/dist/api-playground-2/generators/generateSnippetMap.js +68 -0
  23. package/dist/api-playground-2/generators/generateSnippetMap.js.map +1 -0
  24. package/dist/api-playground-2/generators/getFileProperties.js +24 -0
  25. package/dist/api-playground-2/generators/getFileProperties.js.map +1 -0
  26. package/dist/api-playground-2/hooks/usePlaygroundInputsStore.js +22 -0
  27. package/dist/api-playground-2/hooks/usePlaygroundInputsStore.js.map +1 -0
  28. package/dist/api-playground-2/schemaGraph/getAllRequiredProperties.js +10 -0
  29. package/dist/api-playground-2/schemaGraph/getAllRequiredProperties.js.map +1 -0
  30. package/dist/api-playground-2/schemaGraph/processExamples.js +13 -0
  31. package/dist/api-playground-2/schemaGraph/processExamples.js.map +1 -0
  32. package/dist/api-playground-2/schemaGraph/utils.js +76 -0
  33. package/dist/api-playground-2/schemaGraph/utils.js.map +1 -0
  34. package/dist/components/Api/dropdown-menu.js +4 -3
  35. package/dist/components/Api/dropdown-menu.js.map +1 -1
  36. package/dist/components/content-components/CodeGroupSelect/index.js +3 -3
  37. package/dist/constants/initialRequest.js +14 -0
  38. package/dist/constants/initialRequest.js.map +1 -0
  39. package/dist/constants/snippetPresets.js +47 -13
  40. package/dist/constants/snippetPresets.js.map +1 -1
  41. package/dist/contexts/CodeExampleLabelContext.js +14 -0
  42. package/dist/contexts/CodeExampleLabelContext.js.map +1 -0
  43. package/dist/contexts/ConfigContext.js +1 -2
  44. package/dist/contexts/ConfigContext.js.map +1 -1
  45. package/dist/env.js +3 -0
  46. package/dist/env.js.map +1 -0
  47. package/dist/hooks/useSendPlaygroundRequest.js +18 -0
  48. package/dist/hooks/useSendPlaygroundRequest.js.map +1 -0
  49. package/dist/utils/locales/en.js +111 -0
  50. package/dist/utils/locales/en.js.map +1 -0
  51. package/dist/utils/locales/index.js +6 -0
  52. package/dist/utils/locales/index.js.map +1 -0
  53. package/dist/utils/uuid.js +7 -0
  54. package/dist/utils/uuid.js.map +1 -0
  55. package/package.json +6 -2
@@ -0,0 +1,11 @@
1
+ import { createContext as e } from "react";
2
+ const t = e({
3
+ isSending: !1,
4
+ selectedBaseUrlIndex: 0,
5
+ isPlaygroundExpanded: !1,
6
+ selectedExampleIndex: 0
7
+ });
8
+ export {
9
+ t as ApiPlaygroundContext
10
+ };
11
+ //# sourceMappingURL=ApiPlaygroundContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiPlaygroundContext.js","sources":["../../../src/api-playground/ApiPlayground/ApiPlaygroundContext.tsx"],"sourcesContent":["'use client';\n\nimport { ApiPlaygroundResultType } from '@mintlify/models';\nimport { createContext } from 'react';\n\nexport type ApiPlaygroundContextType = {\n isSending?: boolean;\n sendRequest?: () => void;\n isPlaygroundExpanded: boolean;\n result?: ApiPlaygroundResultType;\n selectedBaseUrlIndex: number;\n setSelectedBaseUrlIndex?: (index: number) => void;\n setIsPlaygroundExpanded?: (expanded: boolean) => void;\n baseUrlOptions?: string[];\n selectedExampleIndex?: number;\n setSelectedExampleIndex?: (index: number) => void;\n};\n\nexport const ApiPlaygroundContext = createContext<ApiPlaygroundContextType>({\n isSending: false,\n selectedBaseUrlIndex: 0,\n isPlaygroundExpanded: false,\n selectedExampleIndex: 0,\n});\n"],"names":["ApiPlaygroundContext","createContext"],"mappings":";AAkBO,MAAMA,IAAuBC,EAAwC;AAAA,EAC1E,WAAW;AAAA,EACX,sBAAsB;AAAA,EACtB,sBAAsB;AAAA,EACtB,sBAAsB;AACxB,CAAC;"}
@@ -1,8 +1,8 @@
1
1
  import { jsx as e, jsxs as c } from "react/jsx-runtime";
2
2
  import { useContext as x, useState as f, useMemo as u } from "react";
3
- import { usePlaygroundInputsStore as d } from "@/api-playground-2/hooks/usePlaygroundInputsStore";
4
- import { CodeExampleLabelContext as h } from "@/contexts/CodeExampleLabelContext";
5
- import { ApiReferenceContext2 as g } from "@/contexts/ConfigContext";
3
+ import { usePlaygroundInputsStore as d } from "./hooks/usePlaygroundInputsStore.js";
4
+ import { CodeExampleLabelContext as h } from "../contexts/CodeExampleLabelContext.js";
5
+ import { ApiReferenceContext2 as g } from "../contexts/ConfigContext.js";
6
6
  import R from "../components/Api/ErrorBoundary.js";
7
7
  import { clsx as v } from "clsx";
8
8
  import { RequestExample as C } from "./components/Example/RequestExample.js";
@@ -1,8 +1,8 @@
1
1
  import { jsx as y } from "react/jsx-runtime";
2
2
  import { useState as M, useEffect as B } from "react";
3
- import { generateRequest as E } from "@/api-playground-2/generators/generateRequest";
4
- import { generateSnippet as I } from "@/api-playground-2/generators/generateSnippet";
5
- import { getFirstExampleValue as a } from "@/api-playground-2/schemaGraph/processExamples";
3
+ import { generateRequest as E } from "../../generators/generateRequest.js";
4
+ import { generateSnippet as I } from "../../generators/generateSnippet.js";
5
+ import { getFirstExampleValue as a } from "../../schemaGraph/processExamples.js";
6
6
  import { CodeGroupSelect as w } from "../../../components/content-components/CodeGroupSelect/index.js";
7
7
  import { CodeSnippets as A } from "../../../components/content-components/code-snippets.js";
8
8
  import { langToPresetMap as G } from "../../../constants/snippetPresets.js";
@@ -1,6 +1,6 @@
1
1
  import { jsx as r } from "react/jsx-runtime";
2
- import { generateResponseExampleMap as m } from "@/api-playground-2/generators/generateResponseExampleMap";
3
- import { mapResponseExamples as i } from "@/api-playground-2/schemaGraph/utils";
2
+ import { generateResponseExampleMap as m } from "../../generators/generateResponseExampleMap.js";
3
+ import { mapResponseExamples as i } from "../../schemaGraph/utils.js";
4
4
  import { CodeGroupSelect as u } from "../../../components/content-components/CodeGroupSelect/index.js";
5
5
  import { CodeSnippets as d } from "../../../components/content-components/code-snippets.js";
6
6
  const C = ({
@@ -1,55 +1,55 @@
1
1
  import { jsx as l } from "react/jsx-runtime";
2
- import { useState as q, useEffect as y } from "react";
3
- import { initialApiPlaygroundInputs as E } from "@/api-playground-2/constants";
4
- import { generateSnippetMap as x } from "@/api-playground-2/generators/generateSnippetMap";
2
+ import { useState as b, useEffect as q } from "react";
3
+ import { initialApiPlaygroundInputs as y } from "../../constants/index.js";
4
+ import { generateSnippetMap as E } from "../../generators/generateSnippetMap.js";
5
5
  import { CodeGroupSelect as M } from "../../../components/content-components/CodeGroupSelect/index.js";
6
6
  import { CodeSnippets as O } from "../../../components/content-components/code-snippets.js";
7
- import { CodeBlock as T } from "../../../components/content-components/code-block.js";
7
+ import { CodeBlock as x } from "../../../components/content-components/code-block.js";
8
8
  import { CodeGroup as U } from "../../../components/content-components/code-group.js";
9
9
  import { prismLangToDisplayLang as j } from "../../../constants/prism-languages.js";
10
10
  import { useApiPlaygroundDisplay as w } from "../../../hooks/useApiPlaygroundDisplay.js";
11
11
  import { GeneratedRequestExample as C } from "./GeneratedRequestExample.js";
12
- const F = ({
12
+ const I = ({
13
13
  apiReferenceData: o,
14
- inputs: m = E,
14
+ inputs: i = y,
15
15
  maxHeight: p
16
16
  }) => {
17
- var r, s, c, e, g;
18
- const u = (r = o.operation) == null ? void 0 : r.requestExamples, a = w(), i = (s = o.operation) == null ? void 0 : s.requestExampleLanguages, t = (c = o.operation) == null ? void 0 : c.requiredOnlyExamples, d = (e = o.operation) == null ? void 0 : e.requestExampleType;
19
- switch (console.log("requestExampleType", d), (g = o.operation) == null ? void 0 : g.requestExampleType) {
17
+ var d, r, n, c, e;
18
+ const u = (d = o.operation) == null ? void 0 : d.requestExamples, a = w(), m = (r = o.operation) == null ? void 0 : r.requestExampleLanguages, t = (n = o.operation) == null ? void 0 : n.requiredOnlyExamples;
19
+ switch ((c = o.operation) == null || c.requestExampleType, (e = o.operation) == null ? void 0 : e.requestExampleType) {
20
20
  case "mdx":
21
21
  if (!u) return null;
22
- const f = u.some((n) => n.dropdown ?? !1);
23
- return /* @__PURE__ */ l(U, { isSmallText: !0, dropdown: f, noMargins: !0, className: p, children: u.map((n, b) => /* @__PURE__ */ l(
24
- T,
22
+ const S = u.some((s) => s.dropdown ?? !1);
23
+ return /* @__PURE__ */ l(U, { isSmallText: !0, dropdown: S, noMargins: !0, className: p, children: u.map((s, f) => /* @__PURE__ */ l(
24
+ x,
25
25
  {
26
- language: n.language,
27
- fileName: n.filename,
28
- children: /* @__PURE__ */ l("span", { children: n.code })
26
+ language: s.language,
27
+ fileName: s.filename,
28
+ children: /* @__PURE__ */ l("span", { children: s.code })
29
29
  },
30
- `${n.filename}-${n.language}-${b}`
30
+ `${s.filename}-${s.language}-${f}`
31
31
  )) });
32
32
  case "codeSamples":
33
33
  return o.operation.codeSamples ? /* @__PURE__ */ l(
34
34
  L,
35
35
  {
36
36
  apiReferenceData: o,
37
- inputs: m,
37
+ inputs: i,
38
38
  apiPlaygroundDisplay: a,
39
- requestExampleLanguages: i,
39
+ requestExampleLanguages: m,
40
40
  requiredOnly: t,
41
41
  maxHeight: p
42
42
  }
43
43
  ) : null;
44
44
  case "generated":
45
- const S = o.operation.baseUrl ?? o.operation.baseUrlOptions[0];
46
- return S ? /* @__PURE__ */ l(
45
+ const g = o.operation.baseUrl ?? o.operation.baseUrlOptions[0];
46
+ return g ? /* @__PURE__ */ l(
47
47
  C,
48
48
  {
49
49
  apiReferenceData: o,
50
- baseUrl: S,
51
- inputs: m,
52
- requestExampleLanguages: i,
50
+ baseUrl: g,
51
+ inputs: i,
52
+ requestExampleLanguages: m,
53
53
  requiredOnly: t,
54
54
  maxHeight: p
55
55
  }
@@ -57,35 +57,35 @@ const F = ({
57
57
  }
58
58
  }, L = ({
59
59
  apiReferenceData: o,
60
- inputs: m,
60
+ inputs: i,
61
61
  apiPlaygroundDisplay: p,
62
62
  requestExampleLanguages: u,
63
63
  requiredOnly: a,
64
- maxHeight: i
64
+ maxHeight: m
65
65
  }) => {
66
- const [t, d] = q(null);
67
- if (y(() => {
66
+ const [t, d] = b(null);
67
+ if (q(() => {
68
68
  var r;
69
- (r = o.operation) != null && r.codeSamples && x({
69
+ (r = o.operation) != null && r.codeSamples && E({
70
70
  apiReferenceData: o,
71
71
  codeSamples: o.operation.codeSamples,
72
72
  baseUrl: o.operation.baseUrl ?? o.operation.baseUrlOptions[0],
73
73
  apiPlaygroundMode: p,
74
74
  requestExampleLanguages: u,
75
75
  requiredOnly: a,
76
- inputs: m
76
+ inputs: i
77
77
  }).then(d);
78
- }, [o, m, p, u, a]), !t) return null;
78
+ }, [o, i, p, u, a]), !t) return null;
79
79
  if (Object.values(t).every((r) => Object.keys(r).length <= 1)) {
80
- let s = Object.values(t).flatMap((e) => Object.values(e));
81
- return new Set(s.map((e) => e.filename)).size !== s.length && (s = s.map((e) => ({
80
+ let n = Object.values(t).flatMap((e) => Object.values(e));
81
+ return new Set(n.map((e) => e.filename)).size !== n.length && (n = n.map((e) => ({
82
82
  ...e,
83
83
  filename: j[e.language] ?? e.language
84
- }))), /* @__PURE__ */ l(O, { snippets: s, dropdown: !0, maxHeight: i });
84
+ }))), /* @__PURE__ */ l(O, { snippets: n, dropdown: !0, maxHeight: m });
85
85
  }
86
- return /* @__PURE__ */ l(M, { snippets: t, maxHeight: i });
86
+ return /* @__PURE__ */ l(M, { snippets: t, maxHeight: m });
87
87
  };
88
88
  export {
89
- F as RequestExample
89
+ I as RequestExample
90
90
  };
91
91
  //# sourceMappingURL=RequestExample.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RequestExample.js","sources":["../../../../src/api-playground-2/components/Example/RequestExample.tsx"],"sourcesContent":["import { ApiPlaygroundInputs } from '@mintlify/validation';\nimport { useState, useEffect } from 'react';\n\nimport { initialApiPlaygroundInputs } from '@/api-playground-2/constants';\nimport { generateSnippetMap } from '@/api-playground-2/generators/generateSnippetMap';\nimport type { ApiReferenceDataV2, CodeExample } from '@/api-playground-2/types';\nimport { CodeGroupSelect } from '../../../components/content-components/CodeGroupSelect';\nimport { CodeSnippet } from '../../../components/content-components/code-snippet';\nimport { CodeSnippets } from '../../../components/content-components/code-snippets';\nimport { CodeBlock } from '../../../components/content-components/code-block';\nimport { CodeGroup } from '../../../components/content-components/code-group';\nimport { prismLangToDisplayLang } from '../../../constants/prism-languages';\nimport { useApiPlaygroundDisplay } from '../../../hooks/useApiPlaygroundDisplay';\nimport type { ExampleCodeSnippet } from '../../../types/exampleCodeSnippet';\n\nimport { GeneratedRequestExample } from './GeneratedRequestExample';\n\nexport const RequestExample = ({\n apiReferenceData,\n inputs = initialApiPlaygroundInputs,\n maxHeight,\n}: {\n apiReferenceData: ApiReferenceDataV2;\n inputs: ApiPlaygroundInputs;\n maxHeight?: string;\n}) => {\n const requestExamples = apiReferenceData.operation?.requestExamples;\n const apiPlaygroundDisplay = useApiPlaygroundDisplay();\n const requestExampleLanguages = apiReferenceData.operation?.requestExampleLanguages;\n const requiredOnly = apiReferenceData.operation?.requiredOnlyExamples;\n\n const requestExampleType = apiReferenceData.operation?.requestExampleType;\n\n console.log('requestExampleType', requestExampleType);\n\n switch (apiReferenceData.operation?.requestExampleType) {\n case 'mdx':\n if (!requestExamples) return null;\n const dropdown = requestExamples.some((example: CodeExample) => example.dropdown ?? false);\n return (\n <CodeGroup isSmallText dropdown={dropdown} noMargins className={maxHeight}>\n {requestExamples.map((example: CodeExample, index) => (\n <CodeBlock\n language={example.language}\n fileName={example.filename}\n key={`${example.filename}-${example.language}-${index}`}\n >\n <span>{example.code}</span>\n </CodeBlock>\n ))}\n </CodeGroup>\n );\n case 'codeSamples':\n if (!apiReferenceData.operation.codeSamples) return null;\n return (\n <CodeSamplesExample\n apiReferenceData={apiReferenceData}\n inputs={inputs}\n apiPlaygroundDisplay={apiPlaygroundDisplay}\n requestExampleLanguages={requestExampleLanguages}\n requiredOnly={requiredOnly}\n maxHeight={maxHeight}\n />\n );\n case 'generated':\n const baseUrl =\n apiReferenceData.operation.baseUrl ?? apiReferenceData.operation.baseUrlOptions[0];\n if (!baseUrl) return null;\n return (\n <GeneratedRequestExample\n apiReferenceData={apiReferenceData}\n baseUrl={baseUrl}\n inputs={inputs}\n requestExampleLanguages={requestExampleLanguages}\n requiredOnly={requiredOnly}\n maxHeight={maxHeight}\n />\n );\n }\n};\n\nconst CodeSamplesExample = ({\n apiReferenceData,\n inputs,\n apiPlaygroundDisplay,\n requestExampleLanguages,\n requiredOnly,\n maxHeight,\n}: {\n apiReferenceData: ApiReferenceDataV2;\n inputs: ApiPlaygroundInputs;\n apiPlaygroundDisplay: 'none' | 'simple' | 'interactive';\n requestExampleLanguages?: string[];\n requiredOnly?: boolean;\n maxHeight?: string;\n}) => {\n const [snippetMap, setSnippetMap] = useState<Record<string, Record<string, ExampleCodeSnippet>> | null>(null);\n\n useEffect(() => {\n if (!apiReferenceData.operation?.codeSamples) return;\n\n generateSnippetMap({\n apiReferenceData,\n codeSamples: apiReferenceData.operation.codeSamples,\n baseUrl: apiReferenceData.operation.baseUrl ?? apiReferenceData.operation.baseUrlOptions[0],\n apiPlaygroundMode: apiPlaygroundDisplay,\n requestExampleLanguages,\n requiredOnly,\n inputs,\n }).then(setSnippetMap);\n }, [apiReferenceData, inputs, apiPlaygroundDisplay, requestExampleLanguages, requiredOnly]);\n\n if (!snippetMap) return null;\n\n if (Object.values(snippetMap).every((value) => Object.keys(value).length <= 1)) {\n const codeSnippetMap = Object.values(snippetMap);\n let snippets = codeSnippetMap.flatMap((record) => Object.values(record));\n const uniqueLabels = new Set(snippets.map((snippet) => snippet.filename));\n if (uniqueLabels.size !== snippets.length) {\n snippets = snippets.map((snippet) => ({\n ...snippet,\n filename: prismLangToDisplayLang[snippet.language] ?? snippet.language,\n }));\n }\n return <CodeSnippets snippets={snippets} dropdown maxHeight={maxHeight} />;\n }\n\n return <CodeGroupSelect snippets={snippetMap} maxHeight={maxHeight} />;\n};\n"],"names":["RequestExample","apiReferenceData","inputs","initialApiPlaygroundInputs","maxHeight","requestExamples","_a","apiPlaygroundDisplay","useApiPlaygroundDisplay","requestExampleLanguages","_b","requiredOnly","_c","requestExampleType","_d","_e","dropdown","example","jsx","CodeGroup","index","CodeBlock","CodeSamplesExample","baseUrl","GeneratedRequestExample","snippetMap","setSnippetMap","useState","useEffect","generateSnippetMap","value","snippets","record","snippet","prismLangToDisplayLang","CodeSnippets","CodeGroupSelect"],"mappings":";;;;;;;;;;;AAiBO,MAAMA,IAAiB,CAAC;AAAA,EAC7B,kBAAAC;AAAA,EACA,QAAAC,IAASC;AAAA,EACT,WAAAC;AACF,MAIM;;AACJ,QAAMC,KAAkBC,IAAAL,EAAiB,cAAjB,gBAAAK,EAA4B,iBAC9CC,IAAuBC,EAAA,GACvBC,KAA0BC,IAAAT,EAAiB,cAAjB,gBAAAS,EAA4B,yBACtDC,KAAeC,IAAAX,EAAiB,cAAjB,gBAAA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Example.tsx"],"sourcesContent":["import { ApiPlaygroundInputs } from '@mintlify/validation';\nimport { useState, useEffect } from 'react';\n\nimport { initialApiPlaygroundInputs } from '@/api-playground-2/constants';\nimport { generateSnippetMap } from '@/api-playground-2/generators/generateSnippetMap';\nimport type { ApiReferenceDataV2, CodeExample } from '@/api-playground-2/types';\nimport { CodeGroupSelect } from '../../../components/content-components/CodeGroupSelect';\nimport { CodeSnippet } from '../../../components/content-components/code-snippet';\nimport { CodeSnippets } from '../../../components/content-components/code-snippets';\nimport { CodeBlock } from '../../../components/content-components/code-block';\nimport { CodeGroup } from '../../../components/content-components/code-group';\nimport { prismLangToDisplayLang } from '../../../constants/prism-languages';\nimport { useApiPlaygroundDisplay } from '../../../hooks/useApiPlaygroundDisplay';\nimport type { ExampleCodeSnippet } from '../../../types/exampleCodeSnippet';\n\nimport { GeneratedRequestExample } from './GeneratedRequestExample';\n\nexport const RequestExample = ({\n apiReferenceData,\n inputs = initialApiPlaygroundInputs,\n maxHeight,\n}: {\n apiReferenceData: ApiReferenceDataV2;\n inputs: ApiPlaygroundInputs;\n maxHeight?: string;\n}) => {\n const requestExamples = apiReferenceData.operation?.requestExamples;\n const apiPlaygroundDisplay = useApiPlaygroundDisplay();\n const requestExampleLanguages = apiReferenceData.operation?.requestExampleLanguages;\n const requiredOnly = apiReferenceData.operation?.requiredOnlyExamples;\n\n const requestExampleType = apiReferenceData.operation?.requestExampleType;\n\n switch (apiReferenceData.operation?.requestExampleType) {\n case 'mdx':\n if (!requestExamples) return null;\n const dropdown = requestExamples.some((example: CodeExample) => example.dropdown ?? false);\n return (\n <CodeGroup isSmallText dropdown={dropdown} noMargins className={maxHeight}>\n {requestExamples.map((example: CodeExample, index) => (\n <CodeBlock\n language={example.language}\n fileName={example.filename}\n key={`${example.filename}-${example.language}-${index}`}\n >\n <span>{example.code}</span>\n </CodeBlock>\n ))}\n </CodeGroup>\n );\n case 'codeSamples':\n if (!apiReferenceData.operation.codeSamples) return null;\n return (\n <CodeSamplesExample\n apiReferenceData={apiReferenceData}\n inputs={inputs}\n apiPlaygroundDisplay={apiPlaygroundDisplay}\n requestExampleLanguages={requestExampleLanguages}\n requiredOnly={requiredOnly}\n maxHeight={maxHeight}\n />\n );\n case 'generated':\n const baseUrl =\n apiReferenceData.operation.baseUrl ?? apiReferenceData.operation.baseUrlOptions[0];\n if (!baseUrl) return null;\n return (\n <GeneratedRequestExample\n apiReferenceData={apiReferenceData}\n baseUrl={baseUrl}\n inputs={inputs}\n requestExampleLanguages={requestExampleLanguages}\n requiredOnly={requiredOnly}\n maxHeight={maxHeight}\n />\n );\n }\n};\n\nconst CodeSamplesExample = ({\n apiReferenceData,\n inputs,\n apiPlaygroundDisplay,\n requestExampleLanguages,\n requiredOnly,\n maxHeight,\n}: {\n apiReferenceData: ApiReferenceDataV2;\n inputs: ApiPlaygroundInputs;\n apiPlaygroundDisplay: 'none' | 'simple' | 'interactive';\n requestExampleLanguages?: string[];\n requiredOnly?: boolean;\n maxHeight?: string;\n}) => {\n const [snippetMap, setSnippetMap] = useState<Record<string, Record<string, ExampleCodeSnippet>> | null>(null);\n\n useEffect(() => {\n if (!apiReferenceData.operation?.codeSamples) return;\n\n generateSnippetMap({\n apiReferenceData,\n codeSamples: apiReferenceData.operation.codeSamples,\n baseUrl: apiReferenceData.operation.baseUrl ?? apiReferenceData.operation.baseUrlOptions[0],\n apiPlaygroundMode: apiPlaygroundDisplay,\n requestExampleLanguages,\n requiredOnly,\n inputs,\n }).then(setSnippetMap);\n }, [apiReferenceData, inputs, apiPlaygroundDisplay, requestExampleLanguages, requiredOnly]);\n\n if (!snippetMap) return null;\n\n if (Object.values(snippetMap).every((value) => Object.keys(value).length <= 1)) {\n const codeSnippetMap = Object.values(snippetMap);\n let snippets = codeSnippetMap.flatMap((record) => Object.values(record));\n const uniqueLabels = new Set(snippets.map((snippet) => snippet.filename));\n if (uniqueLabels.size !== snippets.length) {\n snippets = snippets.map((snippet) => ({\n ...snippet,\n filename: prismLangToDisplayLang[snippet.language] ?? snippet.language,\n }));\n }\n return <CodeSnippets snippets={snippets} dropdown maxHeight={maxHeight} />;\n }\n\n return <CodeGroupSelect snippets={snippetMap} maxHeight={maxHeight} />;\n};\n"],"names":["RequestExample","apiReferenceData","inputs","initialApiPlaygroundInputs","maxHeight","requestExamples","_a","apiPlaygroundDisplay","useApiPlaygroundDisplay","requestExampleLanguages","_b","requiredOnly","_c","_d","_e","dropdown","example","jsx","CodeGroup","index","CodeBlock","CodeSamplesExample","baseUrl","GeneratedRequestExample","snippetMap","setSnippetMap","useState","useEffect","generateSnippetMap","value","snippets","record","snippet","prismLangToDisplayLang","CodeSnippets","CodeGroupSelect"],"mappings":";;;;;;;;;;;AAiBO,MAAMA,IAAiB,CAAC;AAAA,EAC7B,kBAAAC;AAAA,EACA,QAAAC,IAASC;AAAA,EACT,WAAAC;AACF,MAIM;;AACJ,QAAMC,KAAkBC,IAAAL,EAAiB,cAAjB,gBAAAK,EAA4B,iBAC9CC,IAAuBC,EAAA,GACvBC,KAA0BC,IAAAT,EAAiB,cAAjB,gBAAAS,EAA4B,yBACtDC,KAAeC,IAAAX,EAAiB,cAAjB,gBAAAW,EAA4B;AAIjD,WAF2BC,IAAAZ,EAAiB,cAAjB,QAAAY,EAA4B,qBAE/CC,IAAAb,EAAiB,cAAjB,gBAAAa,EAA4B,oBAAA;AAAA,IAClC,KAAK;AACH,UAAI,CAACT,EAAiB,QAAO;AAC7B,YAAMU,IAAWV,EAAgB,KAAK,CAACW,MAAyBA,EAAQ,YAAY,EAAK;AACzF,aACE,gBAAAC,EAACC,GAAA,EAAU,aAAW,IAAC,UAAAH,GAAoB,WAAS,IAAC,WAAWX,GAC7D,UAAAC,EAAgB,IAAI,CAACW,GAAsBG,MAC1C,gBAAAF;AAAA,QAACG;AAAA,QAAA;AAAA,UACC,UAAUJ,EAAQ;AAAA,UAClB,UAAUA,EAAQ;AAAA,UAGlB,UAAA,gBAAAC,EAAC,QAAA,EAAM,UAAAD,EAAQ,KAA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AAC,GAEtF,CAACa,EAAY,QAAO;AAExB,MAAI,OAAO,OAAOA,CAAU,EAAE,MAAM,CAACK,MAAU,OAAO,KAAKA,CAAK,EAAE,UAAU,CAAC,GAAG;AAE9E,QAAIC,IADmB,OAAO,OAAON,CAAU,EACjB,QAAQ,CAACO,MAAW,OAAO,OAAOA,CAAM,CAAC;AAEvE,WADqB,IAAI,IAAID,EAAS,IAAI,CAACE,MAAYA,EAAQ,QAAQ,CAAC,EACvD,SAASF,EAAS,WACjCA,IAAWA,EAAS,IAAI,CAACE,OAAa;AAAA,MACpC,GAAGA;AAAA,MACH,UAAUC,EAAuBD,EAAQ,QAAQ,KAAKA,EAAQ;AAAA,IAAA,EAC9D,IAEG,gBAAAf,EAACiB,GAAA,EAAa,UAAAJ,GAAoB,UAAQ,IAAC,WAAA1B,GAAsB;AAAA,EAC1E;AAEA,SAAO,gBAAAa,EAACkB,GAAA,EAAgB,UAAUX,GAAY,WAAApB,EAAA,CAAsB;AACtE;"}
@@ -0,0 +1,20 @@
1
+ const e = {
2
+ server: {},
3
+ path: {},
4
+ query: {},
5
+ header: {},
6
+ cookie: {},
7
+ body: void 0
8
+ }, o = {
9
+ server: "server",
10
+ path: "path",
11
+ query: "query",
12
+ header: "header",
13
+ cookie: "cookie",
14
+ body: "body"
15
+ };
16
+ export {
17
+ o as apiPlaygroundInputKeys,
18
+ e as initialApiPlaygroundInputs
19
+ };
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/api-playground-2/constants/index.ts"],"sourcesContent":["import { ApiPlaygroundInputs } from '@mintlify/validation';\n\nexport const MAX_RECURSION_DEPTH = 10;\nexport const MAX_SCHEMA_COMBINATION_SIZE = 1000;\nexport const CIRCULAR_REF_KEY = '$circularRef';\nexport const stringFileFormats = ['binary', 'base64'];\n\nexport const combinationKeys = [\n 'properties',\n 'additionalProperties',\n 'items',\n 'oneOf',\n 'anyOf',\n 'allOf',\n];\n\n// duplicated from ApiPlaygroundInputsContext.tsx\nexport const initialApiPlaygroundInputs: ApiPlaygroundInputs = {\n server: {},\n path: {},\n query: {},\n header: {},\n cookie: {},\n body: undefined,\n};\n\nexport const apiPlaygroundInputKeys = {\n server: 'server',\n path: 'path',\n query: 'query',\n header: 'header',\n cookie: 'cookie',\n body: 'body',\n};\n"],"names":["initialApiPlaygroundInputs","apiPlaygroundInputKeys"],"mappings":"AAiBO,MAAMA,IAAkD;AAAA,EAC7D,QAAQ,CAAA;AAAA,EACR,MAAM,CAAA;AAAA,EACN,OAAO,CAAA;AAAA,EACP,QAAQ,CAAA;AAAA,EACR,QAAQ,CAAA;AAAA,EACR,MAAM;AACR,GAEaC,IAAyB;AAAA,EACpC,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,MAAM;AACR;"}
@@ -0,0 +1,67 @@
1
+ import { isObject as x, isFile as s } from "@mintlify/common";
2
+ const j = (n, r, c, m) => {
3
+ if (n !== void 0) {
4
+ if (typeof n == "object" && n !== null && c && c.length > 0 && (n = Object.fromEntries(
5
+ Object.entries(n).filter(([e]) => c.includes(e))
6
+ )), r === "multipart/form-data" || r === "application/x-www-form-urlencoded") {
7
+ if (!n || typeof n != "object")
8
+ return;
9
+ typeof n == "object" && m && m.length > 0 && x(n) && m.forEach((i) => {
10
+ i in n || (n[i] = {
11
+ fileName: "example-file"
12
+ });
13
+ });
14
+ const e = (i) => s(i) ? i.name || "file" : typeof i == "object" ? JSON.stringify(i, void 0, 2) : i == null ? void 0 : i.toString();
15
+ return {
16
+ mimeType: r,
17
+ params: Object.entries(n).flatMap(([i, f]) => Array.isArray(f) ? f.filter((t) => t != null).map((t, u) => {
18
+ const l = f.length > 1 ? `${i}[${u}]` : i;
19
+ return s(t) && "name" in t ? {
20
+ name: l,
21
+ value: e(t),
22
+ fileName: t.name
23
+ } : m && m.includes(i) ? {
24
+ name: l,
25
+ value: e(t),
26
+ fileName: "example-file"
27
+ } : {
28
+ name: l,
29
+ value: e(t)
30
+ };
31
+ }) : s(f) && "name" in f ? [
32
+ {
33
+ name: i,
34
+ value: e(f),
35
+ fileName: f.name
36
+ }
37
+ ] : m && m.includes(i) ? [
38
+ {
39
+ name: i,
40
+ value: e(f),
41
+ fileName: "example-file"
42
+ }
43
+ ] : [
44
+ {
45
+ name: i,
46
+ value: e(f)
47
+ }
48
+ ])
49
+ };
50
+ }
51
+ return typeof n == "string" && r && p(r) ? {
52
+ mimeType: r,
53
+ text: n
54
+ } : {
55
+ mimeType: "application/json",
56
+ text: JSON.stringify(n, null, 2)
57
+ };
58
+ }
59
+ };
60
+ function p(n) {
61
+ const r = n.toLowerCase();
62
+ return r.startsWith("text/") || r.endsWith("+xml") || r.endsWith("/xml");
63
+ }
64
+ export {
65
+ j as getPostData
66
+ };
67
+ //# sourceMappingURL=createBodyData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBodyData.js","sources":["../../../src/api-playground-2/generators/createBodyData.ts"],"sourcesContent":["import { isFile, isObject } from '@mintlify/common';\nimport type { PostData } from 'har-format';\n\nexport const getPostData = (\n bodyData: unknown,\n selectedBodyContentType?: string,\n requiredProperties?: string[],\n fileProperties?: string[]\n): PostData | undefined => {\n if (bodyData === undefined) {\n return undefined;\n }\n\n if (\n typeof bodyData === 'object' &&\n bodyData !== null &&\n requiredProperties &&\n requiredProperties.length > 0\n ) {\n bodyData = Object.fromEntries(\n Object.entries(bodyData).filter(([key]) => requiredProperties.includes(key))\n );\n }\n\n // if body type is form data, convert to a list of form params\n if (\n selectedBodyContentType === 'multipart/form-data' ||\n selectedBodyContentType === 'application/x-www-form-urlencoded'\n ) {\n if (!bodyData || typeof bodyData !== 'object') {\n return undefined;\n }\n\n if (typeof bodyData === 'object' && fileProperties && fileProperties.length > 0) {\n if (isObject(bodyData)) {\n fileProperties.forEach((fieldName: string) => {\n if (!(fieldName in bodyData)) {\n bodyData[fieldName] = {\n fileName: 'example-file',\n };\n }\n });\n }\n }\n\n const getParamValue = (value: unknown) => {\n if (isFile(value)) {\n return value.name || 'file';\n }\n if (typeof value === 'object') {\n return JSON.stringify(value, undefined, 2);\n }\n return value?.toString();\n };\n\n return {\n mimeType: selectedBodyContentType,\n params: Object.entries(bodyData).flatMap(([name, value]) => {\n if (Array.isArray(value)) {\n return value\n .filter((item) => item !== undefined && item !== null)\n .map((item, index) => {\n const paramName = value.length > 1 ? `${name}[${index}]` : name;\n if (isFile(item) && 'name' in item) {\n return {\n name: paramName,\n value: getParamValue(item),\n fileName: item.name,\n };\n } else if (fileProperties && fileProperties.includes(name)) {\n return {\n name: paramName,\n value: getParamValue(item),\n fileName: 'example-file',\n };\n }\n return {\n name: paramName,\n value: getParamValue(item),\n };\n });\n }\n\n if (isFile(value) && 'name' in value) {\n return [\n {\n name,\n value: getParamValue(value),\n fileName: value.name,\n },\n ];\n } else if (fileProperties && fileProperties.includes(name)) {\n return [\n {\n name,\n value: getParamValue(value),\n fileName: 'example-file',\n },\n ];\n }\n return [\n {\n name,\n value: getParamValue(value),\n },\n ];\n }),\n };\n }\n\n if (\n typeof bodyData === 'string' &&\n selectedBodyContentType &&\n isPlainText(selectedBodyContentType)\n ) {\n return {\n mimeType: selectedBodyContentType,\n text: bodyData,\n };\n }\n\n return {\n mimeType: 'application/json',\n text: JSON.stringify(bodyData, null, 2),\n };\n};\n\nfunction isPlainText(rawContentType: string) {\n const contentType = rawContentType.toLowerCase();\n return (\n contentType.startsWith('text/') || contentType.endsWith('+xml') || contentType.endsWith('/xml')\n );\n}\n"],"names":["getPostData","bodyData","selectedBodyContentType","requiredProperties","fileProperties","key","isObject","fieldName","getParamValue","value","isFile","name","item","index","paramName","isPlainText","rawContentType","contentType"],"mappings":";AAGO,MAAMA,IAAc,CACzBC,GACAC,GACAC,GACAC,MACyB;AACzB,MAAIH,MAAa,QAgBjB;AAAA,QAXE,OAAOA,KAAa,YACpBA,MAAa,QACbE,KACAA,EAAmB,SAAS,MAE5BF,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E,MAAAE;AAAA,YACA,OAAOH,EAAcC,CAAK;AAAA,YAC1B,UAAUA,EAAM;AAAA,UAAA;AAAA,QAClB,IAEOL,KAAkBA,EAAe,SAASO,CAAI,IAChD;AAAA,UACL;AAAA,YACE,MAAAA;AAAA,YACA,OAAOH,EAAcC,CAAK;AAAA,YAC1B,UAAU;AAAA,UAAA;AAAA,QACZ,IAGG;AAAA,UACL;AAAA,YACE,MAAAE;AAAA,YACA,OAAOH,EAAcC,CAAK;AAAA,UAAA;AAAA,QAC5B,CAEH;AAAA,MAAA;AAAA,IAEL;AAEA,WACE,OAAOR,KAAa,YACpBC,KACAa,EAAYb,CAAuB,IAE5B;AAAA,MACL,UAAUA;AAAA,MACV,MAAMD;AAAA,IAAA,IAIH;AAAA,MACL,UAAU;AAAA,MACV,MAAM,KAAK,UAAUA,GAAU,MAAM,CAAC;AAAA,IAAA;AAAA;AAE1C;AAEA,SAASc,EAAYC,GAAwB;AAC3C,QAAMC,IAAcD,EAAe,YAAA;AACnC,SACEC,EAAY,WAAW,OAAO,KAAKA,EAAY,SAAS,MAAM,KAAKA,EAAY,SAAS,MAAM;AAElG;"}
@@ -0,0 +1,45 @@
1
+ const v = (t, s, n) => {
2
+ var o, c, u;
3
+ const a = [], i = /* @__PURE__ */ new Set(), h = Object.values(
4
+ ((c = (o = t.dependencies) == null ? void 0 : o.parameters) == null ? void 0 : c.header) ?? {}
5
+ ).filter((e) => !e.in || e.in === "header").filter((e) => e.schema.isRequired), l = Object.values(
6
+ ((u = t.dependencies) == null ? void 0 : u.processedSecurityOptions) ?? {}
7
+ ).filter(({ scheme: e }) => !("in" in e) || e.in === "header");
8
+ return Object.entries(s).filter((e) => e[1] != null).forEach(([e, r]) => {
9
+ i.add(e), a.push({
10
+ name: e,
11
+ value: r.toString()
12
+ });
13
+ }), h.forEach((e) => {
14
+ const r = e.name;
15
+ i.has(r) || a.push({
16
+ name: r,
17
+ value: `<${r.toLowerCase()}>`
18
+ });
19
+ }), l.forEach(({ scheme: e, schema: r }) => {
20
+ const d = r.title ?? "Authorization";
21
+ i.has(d) || a.push({
22
+ name: d,
23
+ value: p(e)
24
+ });
25
+ }), n && f(a, n), a;
26
+ }, p = (t) => {
27
+ switch (t.type) {
28
+ case "http":
29
+ return t.scheme === "basic" ? "Basic <encoded-value>" : "Bearer <token>";
30
+ case "oauth2":
31
+ return "Bearer <token>";
32
+ case "apiKey":
33
+ default:
34
+ return "<api-key>";
35
+ }
36
+ }, f = (t, s) => {
37
+ t.some(({ name: n }) => n.toLowerCase() === "content-type") || t.push({
38
+ name: "Content-Type",
39
+ value: s
40
+ });
41
+ };
42
+ export {
43
+ v as createHeaders
44
+ };
45
+ //# sourceMappingURL=createHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHeaders.js","sources":["../../../src/api-playground-2/generators/createHeaders.ts"],"sourcesContent":["import type { Header } from 'har-format';\n\nimport type { ApiReferenceDataV2, SecuritySchemeAndScope } from '@/api-playground-2/types';\n\nexport const createHeaders = (\n apiReferenceData: ApiReferenceDataV2,\n headerInputs: Record<string, unknown>,\n selectedBodyContentType?: string\n): Header[] => {\n const headers: Header[] = [];\n const addedHeaders = new Set<string>();\n const requiredHeaderParameters = Object.values(\n apiReferenceData.dependencies?.parameters?.header ?? {}\n )\n .filter((param) => !param.in || param.in === 'header')\n .filter((param) => param.schema.isRequired);\n const securityHeaderParameters = Object.values(\n apiReferenceData.dependencies?.processedSecurityOptions ?? {}\n ).filter(({ scheme }) => !('in' in scheme) || scheme.in === 'header');\n\n Object.entries(headerInputs)\n .filter((entry): entry is [string, NonNullable<unknown>] => entry[1] != null)\n .forEach(([name, value]) => {\n addedHeaders.add(name);\n headers.push({\n name,\n value: value.toString(),\n });\n });\n\n requiredHeaderParameters.forEach((param) => {\n const name = param.name;\n if (!addedHeaders.has(name)) {\n headers.push({\n name,\n value: `<${name.toLowerCase()}>`,\n });\n }\n });\n\n securityHeaderParameters.forEach(({ scheme, schema }) => {\n const name = schema.title ?? 'Authorization';\n if (!addedHeaders.has(name)) {\n headers.push({\n name,\n value: generateAuthPlaceholder(scheme),\n });\n }\n });\n\n if (selectedBodyContentType) {\n addContentTypeHeader(headers, selectedBodyContentType);\n }\n\n return headers;\n};\n\nconst generateAuthPlaceholder = (scheme: SecuritySchemeAndScope): string => {\n switch (scheme.type) {\n case 'http':\n return scheme.scheme === 'basic' ? 'Basic <encoded-value>' : 'Bearer <token>';\n case 'oauth2':\n return 'Bearer <token>';\n case 'apiKey':\n default:\n return '<api-key>';\n }\n};\n\nconst addContentTypeHeader = (headers: Header[], contentType: string) => {\n if (headers.some(({ name }) => name.toLowerCase() === 'content-type')) {\n return;\n }\n\n headers.push({\n name: 'Content-Type',\n value: contentType,\n });\n};\n"],"names":["createHeaders","apiReferenceData","headerInputs","selectedBodyContentType","_a","_b","_c","headers","addedHeaders","requiredHeaderParameters","param","securityHeaderParameters","scheme","entry","name","value","schema","generateAuthPlaceholder","addContentTypeHeader","contentType"],"mappings":"AAIO,MAAMA,IAAgB,CAC3BC,GACAC,GACAC,MACa;AAJR,MAAAC,GAAAC,GAAAC;AAKL,QAAMC,IAAoB,CAAA,GACpBC,wBAAmB,IAAA,GACnBC,IAA2B,OAAO;AAAA,MACtCJ,KAAAD,IAAAH,EAAiB,iBAAjB,gBAAAG,EAA+B,eAA/B,gBAAAC,EAA2C,WAAU,CAAA;AAAA,EAAC,EAErD,OAAO,CAACK,MAAU,CAACA,EAAM,MAAMA,EAAM,OAAO,QAAQ,EACpD,OAAO,CAACA,MAAUA,EAAM,OAAO,UAAU,GACtCC,IAA2B,OAAO;AAAA,MACtCL,IAAAL,EAAiB,iBAAjB,gBAAAK,EAA+B,6BAA4B,CAAA;AAAA,EAAC,EAC5D,OAAO,CAAC,EAAE,QAAAM,QAAa,EAAE,QAAQA,MAAWA,EAAO,OAAO,QAAQ;AAEpE,gBAAO,QAAQV,CAAY,EACxB,OAAO,CAACW,MAAmDA,EAAM,CAAC,KAAK,IAAI,EAC3E,QAAQ,CAAC,CAACC,GAAMC,CAAK,MAAM;AAC1B,IAAAP,EAAa,IAAIM,CAAI,GACrBP,EAAQ,KAAK;AAAA,MACX,MAAAO;AAAA,MACA,OAAOC,EAAM,SAAA;AAAA,IAAS,CACvB;AAAA,EACH,CAAC,GAEHN,EAAyB,QAAQ,CAACC,MAAU;AAC1C,UAAMI,IAAOJ,EAAM;AACnB,IAAKF,EAAa,IAAIM,CAAI,KACxBP,EAAQ,KAAK;AAAA,MACX,MAAAO;AAAA,MACA,OAAO,IAAIA,EAAK,YAAA,CAAa;AAAA,IAAA,CAC9B;AAAA,EAEL,CAAC,GAEDH,EAAyB,QAAQ,CAAC,EAAE,QAAAC,GAAQ,QAAAI,QAAa;AACvD,UAAMF,IAAOE,EAAO,SAAS;AAC7B,IAAKR,EAAa,IAAIM,CAAI,KACxBP,EAAQ,KAAK;AAAA,MACX,MAAAO;AAAA,MACA,OAAOG,EAAwBL,CAAM;AAAA,IAAA,CACtC;AAAA,EAEL,CAAC,GAEGT,KACFe,EAAqBX,GAASJ,CAAuB,GAGhDI;AACT,GAEMU,IAA0B,CAACL,MAA2C;AAC1E,UAAQA,EAAO,MAAA;AAAA,IACb,KAAK;AACH,aAAOA,EAAO,WAAW,UAAU,0BAA0B;AAAA,IAC/D,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EAAA;AAEb,GAEMM,IAAuB,CAACX,GAAmBY,MAAwB;AACvE,EAAIZ,EAAQ,KAAK,CAAC,EAAE,MAAAO,EAAA,MAAWA,EAAK,kBAAkB,cAAc,KAIpEP,EAAQ,KAAK;AAAA,IACX,MAAM;AAAA,IACN,OAAOY;AAAA,EAAA,CACR;AACH;"}
@@ -0,0 +1,50 @@
1
+ import { getFirstExampleValue as g } from "../schemaGraph/processExamples.js";
2
+ import { langToPresetMap as f } from "../../constants/snippetPresets.js";
3
+ import { generateRequest as q } from "./generateRequest.js";
4
+ import { generateSnippet as x } from "./generateSnippet.js";
5
+ const E = async ({
6
+ apiReferenceData: e,
7
+ baseUrl: n,
8
+ inputs: o,
9
+ apiPlaygroundMode: m,
10
+ lang: d,
11
+ requiredOnly: l
12
+ }) => {
13
+ var r, s, p, c;
14
+ if (n && m !== "none") {
15
+ const u = Object.keys(
16
+ ((s = (r = e.dependencies) == null ? void 0 : r.requestBody) == null ? void 0 : s.content) ?? {}
17
+ )[0], y = g(
18
+ ((c = (p = e.dependencies) == null ? void 0 : p.requestBody) == null ? void 0 : c.content) ?? {}
19
+ );
20
+ try {
21
+ const a = q({
22
+ baseUrl: n,
23
+ apiReferenceData: e,
24
+ inputs: o,
25
+ exampleData: y,
26
+ selectedBodyContentType: u,
27
+ requiredOnly: l
28
+ }), i = f[d];
29
+ if (i == null)
30
+ return;
31
+ const [t] = await x({
32
+ request: a,
33
+ pathInputs: o.path,
34
+ snippetPresets: [i],
35
+ apiReferenceData: e
36
+ });
37
+ if (t)
38
+ return {
39
+ label: "Interactive Example",
40
+ lang: t.language,
41
+ source: t.code
42
+ };
43
+ } catch {
44
+ }
45
+ }
46
+ };
47
+ export {
48
+ E as generateInteractiveCodeSample
49
+ };
50
+ //# sourceMappingURL=generateInteractiveCodeSample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateInteractiveCodeSample.js","sources":["../../../src/api-playground-2/generators/generateInteractiveCodeSample.ts"],"sourcesContent":["import { ApiPlaygroundDisplayType } from '@mintlify/models';\nimport { ApiPlaygroundInputs, CodeSample } from '@mintlify/validation';\n\nimport { getFirstExampleValue } from '@/api-playground-2/schemaGraph/processExamples';\nimport type { ApiReferenceDataV2 } from '@/api-playground-2/types';\nimport { langToPresetMap } from '@/constants/snippetPresets';\n\nimport { generateRequest } from './generateRequest';\nimport { generateSnippet } from './generateSnippet';\n\nexport const generateInteractiveCodeSample = async ({\n apiReferenceData,\n baseUrl,\n inputs,\n apiPlaygroundMode,\n lang,\n requiredOnly,\n}: {\n lang: string;\n baseUrl?: string;\n apiReferenceData: ApiReferenceDataV2;\n inputs: ApiPlaygroundInputs;\n apiPlaygroundMode: ApiPlaygroundDisplayType;\n requiredOnly?: boolean;\n}): Promise<CodeSample | undefined> => {\n if (baseUrl && apiPlaygroundMode !== 'none') {\n const firstRequestBodyContentType = Object.keys(\n apiReferenceData.dependencies?.requestBody?.content ?? {}\n )[0];\n const firstExample = getFirstExampleValue(\n apiReferenceData.dependencies?.requestBody?.content ?? {}\n );\n try {\n const request = generateRequest({\n baseUrl,\n apiReferenceData,\n inputs,\n exampleData: firstExample,\n selectedBodyContentType: firstRequestBodyContentType,\n requiredOnly,\n });\n const preset = langToPresetMap[lang];\n if (preset == undefined) {\n return;\n }\n const [snippet] = await generateSnippet({\n request,\n pathInputs: inputs.path,\n snippetPresets: [preset],\n apiReferenceData,\n });\n if (snippet)\n return {\n label: 'Interactive Example',\n lang: snippet.language,\n source: snippet.code,\n };\n } catch (err) {}\n }\n};\n"],"names":["generateInteractiveCodeSample","apiReferenceData","baseUrl","inputs","apiPlaygroundMode","lang","requiredOnly","firstRequestBodyContentType","_b","_a","firstExample","getFirstExampleValue","_d","_c","request","generateRequest","preset","langToPresetMap","snippet","generateSnippet"],"mappings":";;;;AAUO,MAAMA,IAAgC,OAAO;AAAA,EAClD,kBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAAC;AACF,MAOuC;;AACrC,MAAIJ,KAAWE,MAAsB,QAAQ;AAC3C,UAAMG,IAA8B,OAAO;AAAA,QACzCC,KAAAC,IAAAR,EAAiB,iBAAjB,gBAAAQ,EAA+B,gBAA/B,gBAAAD,EAA4C,YAAW,CAAA;AAAA,IAAC,EACxD,CAAC,GACGE,IAAeC;AAAA,QACnBC,KAAAC,IAAAZ,EAAiB,iBAAjB,gBAAAY,EAA+B,gBAA/B,gBAAAD,EAA4C,YAAW,CAAA;AAAA,IAAC;AAE1D,QAAI;AACF,YAAME,IAAUC,EAAgB;AAAA,QAC9B,SAAAb;AAAA,QACA,kBAAAD;AAAA,QACA,QAAAE;AAAA,QACA,aAAaO;AAAA,QACb,yBAAyBH;AAAA,QACzB,cAAAD;AAAA,MAAA,CACD,GACKU,IAASC,EAAgBZ,CAAI;AACnC,UAAIW,KAAU;AACZ;AAEF,YAAM,CAACE,CAAO,IAAI,MAAMC,EAAgB;AAAA,QACtC,SAAAL;AAAA,QACA,YAAYX,EAAO;AAAA,QACnB,gBAAgB,CAACa,CAAM;AAAA,QACvB,kBAAAf;AAAA,MAAA,CACD;AACD,UAAIiB;AACF,eAAO;AAAA,UACL,OAAO;AAAA,UACP,MAAMA,EAAQ;AAAA,UACd,QAAQA,EAAQ;AAAA,QAAA;AAAA,IAEtB,QAAc;AAAA,IAAC;AAAA,EACjB;AACF;"}
@@ -0,0 +1,65 @@
1
+ import { isObject as c } from "@mintlify/common";
2
+ import y from "lodash/cloneDeep";
3
+ import U from "lodash/merge";
4
+ import { getAllRequiredProperties as $ } from "../schemaGraph/getAllRequiredProperties.js";
5
+ import { isSchemaObject as k } from "../schemaGraph/utils.js";
6
+ import { initialRequest as F } from "../../constants/initialRequest.js";
7
+ import { addPathParams as H, joinWithSingleSlash as J, addServerVariables as K } from "../../hooks/useSendPlaygroundRequest.js";
8
+ import { getPostData as M } from "./createBodyData.js";
9
+ import { createHeaders as N } from "./createHeaders.js";
10
+ import { getFileProperties as Q } from "./getFileProperties.js";
11
+ const W = ({
12
+ exampleData: o,
13
+ apiReferenceData: r,
14
+ baseUrl: t,
15
+ inputs: e,
16
+ selectedBodyContentType: i,
17
+ requiredOnly: n
18
+ }) => {
19
+ var f, l, p, u, b, g;
20
+ const S = Object.values(((f = r.dependencies) == null ? void 0 : f.parameters) ?? {}).filter((d) => d.style === "deepObject").map((d) => d.name), j = V(e, S), v = H(((l = r.operation) == null ? void 0 : l.path) ?? "", e.path), a = N(r, e.header, i), m = _(e.body), q = c(o), O = c(e.body) ? h(e.body) : {}, A = !m && q ? U(y(o), O) : null, P = m ? o : A;
21
+ let s;
22
+ i && k(
23
+ (b = (u = (p = r.dependencies) == null ? void 0 : p.requestBody) == null ? void 0 : u.content[i]) == null ? void 0 : b.schema
24
+ ) && (s = r.dependencies.requestBody.content[i].schema);
25
+ const E = n && !e.body && s ? $(s) : void 0, B = s ? Q(s) : void 0, I = M(
26
+ P,
27
+ i,
28
+ E,
29
+ B
30
+ );
31
+ return {
32
+ ...F,
33
+ method: (((g = r.operation) == null ? void 0 : g.method) ?? "").toUpperCase(),
34
+ url: J(K(t, e.server), v),
35
+ queryString: j,
36
+ headers: a,
37
+ postData: I
38
+ };
39
+ }, V = (o, r) => Object.entries(o.query).flatMap(([t, e]) => e ? Array.isArray(e) ? e.filter(Boolean).map((i) => ({
40
+ name: t,
41
+ value: i.toString()
42
+ })) : typeof e == "object" ? r != null && r.includes(t) ? Object.entries(e).filter(([i, n]) => n).map(([i, n]) => ({
43
+ name: `${t}[${i}]`,
44
+ value: n.toString()
45
+ })) : [{ name: t, value: JSON.stringify(e) }] : [
46
+ {
47
+ name: t,
48
+ value: e.toString()
49
+ }
50
+ ] : []), _ = (o) => {
51
+ if (o == null)
52
+ return !0;
53
+ if (typeof o == "object")
54
+ return Object.values(o).every((r) => r === void 0);
55
+ };
56
+ function h(o) {
57
+ const r = y(o);
58
+ for (const t in r)
59
+ r[t] === void 0 ? delete r[t] : c(r[t]) && h(r[t]);
60
+ return r;
61
+ }
62
+ export {
63
+ W as generateRequest
64
+ };
65
+ //# sourceMappingURL=generateRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateRequest.js","sources":["../../../src/api-playground-2/generators/generateRequest.ts"],"sourcesContent":["import { isObject } from '@mintlify/common';\nimport { ApiPlaygroundInputs, SchemaObject } from '@mintlify/validation';\nimport type { Request } from 'har-format';\nimport cloneDeep from 'lodash/cloneDeep';\nimport merge from 'lodash/merge';\n\nimport { getAllRequiredProperties } from '@/api-playground-2/schemaGraph/getAllRequiredProperties';\nimport { isSchemaObject } from '@/api-playground-2/schemaGraph/utils';\nimport type { ApiReferenceDataV2 } from '@/api-playground-2/types';\nimport { initialRequest } from '@/constants/initialRequest';\nimport {\n addPathParams,\n addServerVariables,\n joinWithSingleSlash,\n} from '@/hooks/useSendPlaygroundRequest';\n\nimport { getPostData } from './createBodyData';\nimport { createHeaders } from './createHeaders';\nimport { getFileProperties } from './getFileProperties';\n\ntype QueryParam = { name: string; value: string };\n\n/**\n * Constructs the request from the URL, schema, and inputs\n */\nexport const generateRequest = ({\n exampleData,\n apiReferenceData,\n baseUrl,\n inputs,\n selectedBodyContentType,\n requiredOnly,\n}: {\n exampleData?: unknown;\n apiReferenceData: ApiReferenceDataV2;\n baseUrl: string;\n inputs: ApiPlaygroundInputs;\n selectedBodyContentType?: string;\n requiredOnly?: boolean;\n}): Request => {\n const queryParamsWithDeepObjects = Object.values(apiReferenceData.dependencies?.parameters ?? {})\n .filter((param) => param.style === 'deepObject')\n .map((param) => param.name);\n\n const queryString = createQueryString(inputs, queryParamsWithDeepObjects);\n const path = addPathParams(apiReferenceData.operation?.path ?? '', inputs.path);\n const headers = createHeaders(apiReferenceData, inputs.header, selectedBodyContentType);\n\n const bodyIsEmpty = isBodyEmpty(inputs.body);\n const bodyIsObject = isObject(exampleData);\n const input = isObject(inputs.body) ? deleteUndefinedKeys(inputs.body) : {};\n\n const mergedExampleAndBody =\n !bodyIsEmpty && bodyIsObject ? merge(cloneDeep(exampleData), input) : null;\n\n const bodyData = bodyIsEmpty ? exampleData : mergedExampleAndBody;\n let requestBodySchema: SchemaObject | undefined = undefined;\n\n if (selectedBodyContentType) {\n if (\n isSchemaObject(\n apiReferenceData.dependencies?.requestBody?.content[selectedBodyContentType]?.schema\n )\n ) {\n requestBodySchema =\n apiReferenceData.dependencies.requestBody.content[selectedBodyContentType].schema;\n }\n }\n\n const requiredProperties =\n requiredOnly && !inputs.body && requestBodySchema\n ? \n getAllRequiredProperties(requestBodySchema as SchemaObject)\n : undefined;\n\n const fileProperties = requestBodySchema ? getFileProperties(requestBodySchema) : undefined;\n\n const postData = getPostData(\n bodyData,\n selectedBodyContentType,\n requiredProperties,\n fileProperties\n );\n\n return {\n ...initialRequest,\n method: (apiReferenceData.operation?.method ?? '').toUpperCase(),\n url: joinWithSingleSlash(addServerVariables(baseUrl, inputs.server), path),\n queryString,\n headers,\n postData,\n };\n};\n\nconst createQueryString = (\n inputs: ApiPlaygroundInputs,\n queryParamsWithDeepObjects?: string[]\n): QueryParam[] => {\n return Object.entries(inputs.query).flatMap(([name, value]) => {\n if (!value) return [];\n\n if (Array.isArray(value)) {\n return value.filter(Boolean).map((element) => ({\n name,\n value: element.toString(),\n }));\n }\n\n if (typeof value === 'object') {\n if (queryParamsWithDeepObjects?.includes(name)) {\n return Object.entries(value)\n .filter(([_, value]) => value)\n .map(([key, value]) => ({\n name: `${name}[${key}]`,\n value: value.toString(),\n }));\n }\n\n return [{ name, value: JSON.stringify(value) }];\n }\n\n return [\n {\n name,\n value: value.toString(),\n },\n ];\n });\n};\n\nconst isBodyEmpty = (bodyData: unknown) => {\n if (bodyData === null || bodyData === undefined) {\n return true;\n }\n\n if (typeof bodyData === 'object') {\n return Object.values(bodyData).every((value) => value === undefined);\n }\n};\n\nfunction deleteUndefinedKeys(obj: Record<string, unknown>): Record<string, unknown> {\n const objClone = cloneDeep(obj);\n for (const key in objClone) {\n if (objClone[key] === undefined) delete objClone[key];\n else if (isObject(objClone[key])) deleteUndefinedKeys(objClone[key]);\n }\n return objClone;\n}\n"],"names":["generateRequest","exampleData","apiReferenceData","baseUrl","inputs","selectedBodyContentType","requiredOnly","queryParamsWithDeepObjects","_a","param","queryString","createQueryString","path","addPathParams","_b","headers","createHeaders","bodyIsEmpty","isBodyEmpty","bodyIsObject","isObject","input","deleteUndefinedKeys","mergedExampleAndBody","merge","cloneDeep","bodyData","requestBodySchema","isSchemaObject","_e","_d","_c","requiredProperties","getAllRequiredProperties","fileProperties","getFileProperties","postData","getPostData","initialRequest","_f","joinWithSingleSlash","addServerVariables","name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B,EAASF,CAAG,CAAC,KAAGxB,EAAoB0B,EAASF,CAAG,CAAC;AAErE,SAAOE;AACT;"}
@@ -0,0 +1,36 @@
1
+ const y = (a, l) => Object.entries(a).sort().reduce((e, [n, r]) => {
2
+ const t = Object.keys(r), c = t[l] ? r[t[l]] : r[t[0]];
3
+ if (c === void 0)
4
+ return e[n] = {
5
+ "": {
6
+ filename: n,
7
+ code: "This response has no body data.",
8
+ language: ""
9
+ }
10
+ }, e;
11
+ const i = c.examples, s = i == null ? void 0 : i[0];
12
+ if (s && "value" in s && s.value === void 0)
13
+ return e[n] = {
14
+ "": {
15
+ filename: n,
16
+ code: "This response does not have an example.",
17
+ language: ""
18
+ }
19
+ }, e;
20
+ const g = Object.entries(i ?? {}).reduce(
21
+ (u, [h, o]) => {
22
+ const f = "value" in o ? o.value : o, d = "title" in o && typeof o.title == "string" ? o.title : "", v = JSON.stringify(f, null, 2);
23
+ return u[d] = {
24
+ filename: n,
25
+ language: "json",
26
+ code: v
27
+ }, u;
28
+ },
29
+ {}
30
+ );
31
+ return e[n] = g, e;
32
+ }, {});
33
+ export {
34
+ y as generateResponseExampleMap
35
+ };
36
+ //# sourceMappingURL=generateResponseExampleMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateResponseExampleMap.js","sources":["../../../src/api-playground-2/generators/generateResponseExampleMap.ts"],"sourcesContent":["import type { MediaObject } from '@mintlify/validation';\n\nimport type { ExampleCodeSnippet } from '@/types/exampleCodeSnippet';\n\ntype ExampleMap = { [title: string]: ExampleCodeSnippet };\ntype ResponseExampleMap = { [status: string]: ExampleMap };\n\nexport const generateResponseExampleMap = (\n responses: Record<string, MediaObject>,\n selectedContentTypeIndex?: number\n): ResponseExampleMap => {\n return Object.entries(responses)\n .sort()\n .reduce<ResponseExampleMap>((map, [status, mediaObject]) => {\n const contentTypes = Object.keys(mediaObject);\n const content: MediaObject | undefined =\n selectedContentTypeIndex !== undefined && contentTypes[selectedContentTypeIndex]\n ? \n mediaObject[contentTypes[selectedContentTypeIndex] as keyof MediaObject]\n : \n mediaObject[contentTypes[0] as keyof MediaObject];\n if (content === undefined) {\n map[status] = {\n '': {\n filename: status,\n code: 'This response has no body data.',\n language: '',\n },\n };\n return map;\n }\n const contentExamples = content.examples;\n const firstExample = contentExamples?.[0];\n if (firstExample && 'value' in firstExample && firstExample.value === undefined) {\n map[status] = {\n '': {\n filename: status,\n code: 'This response does not have an example.',\n language: '',\n },\n };\n return map;\n }\n const exampleMap = Object.entries(contentExamples ?? {}).reduce<ExampleMap>(\n (exampleMap, [_, example]) => {\n const exampleValue = 'value' in example ? example.value : example;\n const exampleTitle =\n 'title' in example && typeof example.title === 'string' ? example.title : '';\n const stringifiedExample = JSON.stringify(exampleValue, null, 2);\n exampleMap[exampleTitle] = {\n filename: status,\n language: 'json',\n code: stringifiedExample,\n };\n return exampleMap;\n },\n {}\n );\n map[status] = exampleMap;\n return map;\n }, {});\n};\n"],"names":["generateResponseExampleMap","responses","selectedContentTypeIndex","map","status","mediaObject","contentTypes","content","contentExamples","firstExample","exampleMap","_","example","exampleValue","exampleTitle","stringifiedExample"],"mappings":"AAOO,MAAMA,IAA6B,CACxCC,GACAC,MAEO,OAAO,QAAQD,CAAS,EAC5B,KAAA,EACA,OAA2B,CAACE,GAAK,CAACC,GAAQC,CAAW,MAAM;AAC1D,QAAMC,IAAe,OAAO,KAAKD,CAAW,GACtCE,IACsCD,EAAaJ,CAAwB,IAE3EG,EAAYC,EAAaJ,CAAwB,CAAsB,IAEvEG,EAAYC,EAAa,CAAC,CAAsB;AACtD,MAAIC,MAAY;AACd,WAAAJ,EAAIC,CAAM,IAAI;AAAA,MACZ,IAAI;AAAA,QACF,UAAUA;AAAA,QACV,MAAM;AAAA,QACN,UAAU;AAAA,MAAA;AAAA,IACZ,GAEKD;AAET,QAAMK,IAAkBD,EAAQ,UAC1BE,IAAeD,KAAA,gBAAAA,EAAkB;AACvC,MAAIC,KAAgB,WAAWA,KAAgBA,EAAa,UAAU;AACpE,WAAAN,EAAIC,CAAM,IAAI;AAAA,MACZ,IAAI;AAAA,QACF,UAAUA;AAAA,QACV,MAAM;AAAA,QACN,UAAU;AAAA,MAAA;AAAA,IACZ,GAEKD;AAET,QAAMO,IAAa,OAAO,QAAQF,KAAmB,CAAA,CAAE,EAAE;AAAA,IACvD,CAACE,GAAY,CAACC,GAAGC,CAAO,MAAM;AAC5B,YAAMC,IAAe,WAAWD,IAAUA,EAAQ,QAAQA,GACpDE,IACJ,WAAWF,KAAW,OAAOA,EAAQ,SAAU,WAAWA,EAAQ,QAAQ,IACtEG,IAAqB,KAAK,UAAUF,GAAc,MAAM,CAAC;AAC/DH,aAAAA,EAAWI,CAAY,IAAI;AAAA,QACzB,UAAUV;AAAA,QACV,UAAU;AAAA,QACV,MAAMW;AAAA,MAAA,GAEDL;AAAAA,IACT;AAAA,IACA,CAAA;AAAA,EAAC;AAEH,SAAAP,EAAIC,CAAM,IAAIM,GACPP;AACT,GAAG,CAAA,CAAE;"}
@@ -0,0 +1,42 @@
1
+ import { HTTPSnippet as T } from "@readme/httpsnippet";
2
+ import { generateUniqueString as U } from "../../utils/uuid.js";
3
+ import { snippetPresets as x } from "../../constants/snippetPresets.js";
4
+ const N = async ({
5
+ request: r,
6
+ pathInputs: p,
7
+ apiReferenceData: s,
8
+ snippetPresets: a = x,
9
+ isMultipleRequest: c = !1
10
+ }) => {
11
+ const i = {}, g = /:{[^{}]+}/g, m = r.url.replace(g, (t) => {
12
+ const e = ":62437";
13
+ return i[e] = t, e;
14
+ }), f = /{[^{}]+}/g, d = m.replace(f, (t) => {
15
+ const e = t.slice(1, t.length - 1), n = p[e];
16
+ if (t === "{endpoint}")
17
+ return "https://{endpoint}";
18
+ if (n && (typeof n != "string" || n.length > 0))
19
+ return `${encodeURIComponent(n.toString())}`;
20
+ const o = U();
21
+ return i[o] = t, o;
22
+ }), h = new T({
23
+ ...r,
24
+ url: d,
25
+ postData: r.postData || { mimeType: "application/json" }
26
+ });
27
+ return Promise.all(
28
+ a.map(async (t) => {
29
+ var u;
30
+ const { filename: e, snippet: n, language: o } = t, { target: P, client: S } = n, l = h.convert(P, S), y = R(i, (l == null ? void 0 : l.toString()) || "");
31
+ return {
32
+ filename: c ? e : ((u = s.operation) == null ? void 0 : u.title) || e,
33
+ code: y,
34
+ language: o
35
+ };
36
+ })
37
+ );
38
+ }, R = (r, p) => Object.entries(r).reduce((s, [a, c]) => s.replace(a, c), p);
39
+ export {
40
+ N as generateSnippet
41
+ };
42
+ //# sourceMappingURL=generateSnippet.js.map