@mintlify/msft-sdk 1.1.24 → 1.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-playground/ApiPlayground/ApiPlaygroundContext.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/BodySection.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/ParameterSection.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/PlaygroundModal.js +46 -45
- package/dist/api-playground/ApiPlayground/Request/PlaygroundModal.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/SecuritySection.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/ServerSection.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/index.js +18 -18
- package/dist/api-playground/ApiPlayground/Request/index.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/ArrayInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/FileInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/NullInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/NumberInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/ObjectInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/RecursiveInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/SelectInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/StringInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Request/inputs/TextInput.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/CopyFileToClipboardButton.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/DownloadFileButton.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponseBody/CodeResponseContent.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponseBody/index.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponseError.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponseHeaders.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponsePlaceholder.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponseTable.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/ResponseTopbar.js.map +1 -1
- package/dist/api-playground/ApiPlayground/Response/index.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/AdditionalPropertyButton.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/ArrayCount.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/EndpointsMenu.js +20 -21
- package/dist/api-playground/ApiPlayground/components/EndpointsMenu.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/EndpointsMenuLink.js +10 -11
- package/dist/api-playground/ApiPlayground/components/EndpointsMenuLink.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/InputContainer.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/InputSectionContainer.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/ObjectExpandButton.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/PathHeader.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/PlaygroundModalWrapper.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/TrashButton.js.map +1 -1
- package/dist/api-playground/ApiPlayground/components/TypeDropdown.js.map +1 -1
- package/dist/api-playground/ApiPlayground/index.js +30 -30
- package/dist/api-playground/ApiPlayground/index.js.map +1 -1
- package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/NumberMetadata.js.map +1 -1
- package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/StringMetadata.js.map +1 -1
- package/dist/api-playground/EndpointFields/ParamFields/PrimitiveParamField/index.js.map +1 -1
- package/dist/api-playground/EndpointFields/ParamFields/RecursiveParamField.js.map +1 -1
- package/dist/api-playground/EndpointFields/components/Description.js.map +1 -1
- package/dist/api-playground/EndpointFields/components/OneOfDropdown.js.map +1 -1
- package/dist/api-playground/EndpointFields/components/OptionDropdown.js.map +1 -1
- package/dist/api-playground/EndpointFields/components/SectionHeading.js.map +1 -1
- package/dist/api-playground/EndpointFields/index.js.map +1 -1
- package/dist/api-playground-2/Api.js.map +1 -1
- package/dist/api-playground-2/ApiExamples.js.map +1 -1
- package/dist/api-playground-2/ApiFields.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/EndpointSecurity.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/fields/NumberMetadata.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/fields/PrimitiveParamField.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/fields/SimpleArrayParamField.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/fields/SimpleObjectParamField.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/fields/SimplePrimitiveParamField.js.map +1 -1
- package/dist/api-playground-2/components/EndpointFields/fields/StringMetadata.js.map +1 -1
- package/dist/api-playground-2/components/Example/RequestExample.js +17 -15
- package/dist/api-playground-2/components/Example/RequestExample.js.map +1 -1
- package/dist/api-playground-2/components/Example/ResponseExample.js.map +1 -1
- package/dist/api-playground-2/components/Request/InputSectionContainer.js.map +1 -1
- package/dist/api-playground-2/components/TypeDropdown.js.map +1 -1
- package/dist/api-playground-2/constants/index.js +12 -3
- package/dist/api-playground-2/constants/index.js.map +1 -1
- package/dist/api-playground-2/contexts/ApiPlaygroundContext.js.map +1 -1
- package/dist/api-playground-2/generators/generateInteractiveCodeSample.js +10 -10
- package/dist/api-playground-2/generators/generateInteractiveCodeSample.js.map +1 -1
- package/dist/api-playground-2/generators/generateSnippetMap.js +24 -24
- package/dist/api-playground-2/generators/generateSnippetMap.js.map +1 -1
- package/dist/api-playground-2/hooks/useSendPlaygroundRequest.js.map +1 -1
- package/dist/api-playground-2/schemaGraph/addUniqueKeysToSchema.js +41 -0
- package/dist/api-playground-2/schemaGraph/addUniqueKeysToSchema.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/errors.js +19 -0
- package/dist/api-playground-2/schemaGraph/errors.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getApiReferenceDataFromGraph.js +26 -0
- package/dist/api-playground-2/schemaGraph/getApiReferenceDataFromGraph.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getDocumentProperties.js +58 -0
- package/dist/api-playground-2/schemaGraph/getDocumentProperties.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphOperationData.js +77 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphOperationData.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphSchemaData.js +16 -0
- package/dist/api-playground-2/schemaGraph/getSchemaGraphSchemaData.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/processExamples.js +111 -34
- package/dist/api-playground-2/schemaGraph/processExamples.js.map +1 -1
- package/dist/api-playground-2/schemaGraph/reduceCompositions.js +283 -0
- package/dist/api-playground-2/schemaGraph/reduceCompositions.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/resolveGraphNode.js +61 -0
- package/dist/api-playground-2/schemaGraph/resolveGraphNode.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/resolveOperationWithDependencies.js +149 -0
- package/dist/api-playground-2/schemaGraph/resolveOperationWithDependencies.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/resolveSchemaWithDependencies.js +33 -0
- package/dist/api-playground-2/schemaGraph/resolveSchemaWithDependencies.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/sortSchemaByRequired.js +35 -0
- package/dist/api-playground-2/schemaGraph/sortSchemaByRequired.js.map +1 -0
- package/dist/api-playground-2/schemaGraph/utils.js +144 -98
- package/dist/api-playground-2/schemaGraph/utils.js.map +1 -1
- package/dist/common/parseApiTargetFromMetadata.js +24 -0
- package/dist/common/parseApiTargetFromMetadata.js.map +1 -0
- package/dist/common/parseOpenApiString.js +42 -0
- package/dist/common/parseOpenApiString.js.map +1 -0
- package/dist/components/Api/ApiReferenceProvider.js +6 -15
- package/dist/components/Api/ApiReferenceProvider.js.map +1 -1
- package/dist/components/Api/ErrorBoundary.js.map +1 -1
- package/dist/components/Api/Expandable.js.map +1 -1
- package/dist/components/Api/Markdown.js.map +1 -1
- package/dist/components/Api/MethodPill.js.map +1 -1
- package/dist/components/Api/Param.js.map +1 -1
- package/dist/components/Api/colors.js.map +1 -1
- package/dist/components/content-components/CodeGroupSelect/CodeGroupCopyButton.js.map +1 -1
- package/dist/components/content-components/CodeGroupSelect/CodeSelectDropdown.js.map +1 -1
- package/dist/components/content-components/CodeGroupSelect/index.js.map +1 -1
- package/dist/components/content-components/code-block.js.map +1 -1
- package/dist/components/content-components/code-group.js.map +1 -1
- package/dist/components/content-components/code-snippet.js.map +1 -1
- package/dist/components/content-components/code-snippets.js.map +1 -1
- package/dist/components/content-components/getNodeText.js.map +1 -1
- package/dist/components/docsLayout.js +29 -27
- package/dist/components/docsLayout.js.map +1 -1
- package/dist/components/nav-tree/index.js +165 -156
- package/dist/components/nav-tree/index.js.map +1 -1
- package/dist/contexts/CodeExampleLabelContext.js.map +1 -1
- package/dist/contexts/ConfigContext.js +61 -12
- package/dist/contexts/ConfigContext.js.map +1 -1
- package/dist/contexts/EndpointLocationContext.js.map +1 -1
- package/dist/contexts/MDXContentContext.js +0 -1
- package/dist/contexts/MDXContentContext.js.map +1 -1
- package/dist/hooks/useApiPlaygroundDisplay.js.map +1 -1
- package/dist/hooks/useApiPlaygroundInputs.js.map +1 -1
- package/dist/hooks/useBaseUrlOptions.js.map +1 -1
- package/dist/hooks/useEndpoint.js.map +1 -1
- package/dist/hooks/useKeyboardShortcut.js.map +1 -1
- package/dist/hooks/useMDXContent.js.map +1 -1
- package/dist/hooks/useMDXContentController/useApiPlaygroundInputs.js.map +1 -1
- package/dist/hooks/useMDXContentController/useMDXContentCallbacks/useSetApiBaseIndexCallback.js.map +1 -1
- package/dist/hooks/useMDXContentController/useMDXContentCallbacks/useSetApiPlaygroundInputsCallback.js.map +1 -1
- package/dist/hooks/usePlaygroundSchemaOptions.js.map +1 -1
- package/dist/hooks/usePrefilledInputs/index.js.map +1 -1
- package/dist/hooks/usePrefilledInputs/storedServerVariables.js.map +1 -1
- package/dist/hooks/useSecurityOption.js.map +1 -1
- package/dist/hooks/useSendPlaygroundRequest.js.map +1 -1
- package/dist/index.d.ts +129 -11
- package/dist/index.js +156 -144
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/hooks/useCurrentPath.js +0 -17
- package/dist/hooks/useCurrentPath.js.map +0 -1
- package/dist/utils/decodeSlug.js +0 -8
- package/dist/utils/decodeSlug.js.map +0 -1
- package/dist/utils/optionallyAddLeadingSlash.js +0 -7
- package/dist/utils/optionallyAddLeadingSlash.js.map +0 -1
|
@@ -2,20 +2,20 @@ import { getFirstExampleValue as f } from "../schemaGraph/processExamples.js";
|
|
|
2
2
|
import { langToPresetMap as q } from "../../constants/snippetPresets.js";
|
|
3
3
|
import { generateRequest as x } from "./generateRequest.js";
|
|
4
4
|
import { generateSnippet as B } from "./generateSnippet.js";
|
|
5
|
-
const I =
|
|
5
|
+
const I = ({
|
|
6
6
|
apiReferenceData: e,
|
|
7
7
|
baseUrl: n,
|
|
8
8
|
inputs: o,
|
|
9
|
-
apiPlaygroundMode:
|
|
9
|
+
apiPlaygroundMode: a,
|
|
10
10
|
selectedSecurityOptionIndex: d,
|
|
11
11
|
lang: l,
|
|
12
12
|
requiredOnly: u
|
|
13
13
|
}) => {
|
|
14
14
|
var r, s, p, c;
|
|
15
|
-
if (n &&
|
|
16
|
-
const
|
|
15
|
+
if (n && a !== "none") {
|
|
16
|
+
const g = Object.keys(
|
|
17
17
|
((s = (r = e.dependencies) == null ? void 0 : r.requestBody) == null ? void 0 : s.content) ?? {}
|
|
18
|
-
)[0],
|
|
18
|
+
)[0], y = f(
|
|
19
19
|
((c = (p = e.dependencies) == null ? void 0 : p.requestBody) == null ? void 0 : c.content) ?? {}
|
|
20
20
|
);
|
|
21
21
|
try {
|
|
@@ -23,17 +23,17 @@ const I = async ({
|
|
|
23
23
|
baseUrl: n,
|
|
24
24
|
apiReferenceData: e,
|
|
25
25
|
inputs: o,
|
|
26
|
-
exampleData:
|
|
27
|
-
selectedBodyContentType:
|
|
26
|
+
exampleData: y,
|
|
27
|
+
selectedBodyContentType: g,
|
|
28
28
|
requiredOnly: u,
|
|
29
29
|
selectedSecurityOptionIndex: d
|
|
30
|
-
}),
|
|
31
|
-
if (
|
|
30
|
+
}), m = q[l];
|
|
31
|
+
if (m == null)
|
|
32
32
|
return;
|
|
33
33
|
const [t] = B({
|
|
34
34
|
request: i,
|
|
35
35
|
pathInputs: o.path,
|
|
36
|
-
snippetPresets: [
|
|
36
|
+
snippetPresets: [m],
|
|
37
37
|
apiReferenceData: e
|
|
38
38
|
});
|
|
39
39
|
if (t)
|
|
@@ -1 +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 =
|
|
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 = ({\n apiReferenceData,\n baseUrl,\n inputs,\n apiPlaygroundMode,\n selectedSecurityOptionIndex,\n lang,\n requiredOnly,\n}: {\n lang: string;\n baseUrl?: string;\n apiReferenceData: ApiReferenceDataV2;\n inputs: ApiPlaygroundInputs;\n apiPlaygroundMode: ApiPlaygroundDisplayType;\n selectedSecurityOptionIndex: number;\n requiredOnly?: boolean;\n}): 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 selectedSecurityOptionIndex,\n });\n const preset = langToPresetMap[lang];\n if (preset == undefined) {\n return;\n }\n const [snippet] = 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","selectedSecurityOptionIndex","lang","requiredOnly","firstRequestBodyContentType","_b","_a","firstExample","getFirstExampleValue","_d","_c","request","generateRequest","preset","langToPresetMap","snippet","generateSnippet"],"mappings":";;;;AAUO,MAAMA,IAAgC,CAAC;AAAA,EAC5C,kBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,6BAAAC;AAAA,EACA,MAAAC;AAAA,EACA,cAAAC;AACF,MAQ8B;;AAC5B,MAAIL,KAAWE,MAAsB,QAAQ;AAC3C,UAAMI,IAA8B,OAAO;AAAA,QACzCC,KAAAC,IAAAT,EAAiB,iBAAjB,gBAAAS,EAA+B,gBAA/B,gBAAAD,EAA4C,YAAW,CAAA;AAAA,IAAC,EACxD,CAAC,GACGE,IAAeC;AAAA,QACnBC,KAAAC,IAAAb,EAAiB,iBAAjB,gBAAAa,EAA+B,gBAA/B,gBAAAD,EAA4C,YAAW,CAAA;AAAA,IAAC;AAE1D,QAAI;AACF,YAAME,IAAUC,EAAgB;AAAA,QAC9B,SAAAd;AAAA,QACA,kBAAAD;AAAA,QACA,QAAAE;AAAA,QACA,aAAaQ;AAAA,QACb,yBAAyBH;AAAA,QACzB,cAAAD;AAAA,QACA,6BAAAF;AAAA,MAAA,CACD,GACKY,IAASC,EAAgBZ,CAAI;AACnC,UAAIW,KAAU;AACZ;AAEF,YAAM,CAACE,CAAO,IAAIC,EAAgB;AAAA,QAChC,SAAAL;AAAA,QACA,YAAYZ,EAAO;AAAA,QACnB,gBAAgB,CAACc,CAAM;AAAA,QACvB,kBAAAhB;AAAA,MAAA,CACD;AACD,UAAIkB;AACF,eAAO;AAAA,UACL,OAAO;AAAA,UACP,MAAMA,EAAQ;AAAA,UACd,QAAQA,EAAQ;AAAA,QAAA;AAAA,IAEtB,QAAc;AAAA,IAAC;AAAA,EACjB;AACF;"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { requestExampleLanguages as k } from "@mintlify/models";
|
|
2
2
|
import { toShikiLang as x, shikiLangToDisplayLang as m } from "../../constants/snippetPresets.js";
|
|
3
3
|
import { generateInteractiveCodeSample as v } from "./generateInteractiveCodeSample.js";
|
|
4
|
-
const
|
|
4
|
+
const p = ({
|
|
5
5
|
codeSamples: t,
|
|
6
6
|
apiReferenceData: c,
|
|
7
|
-
baseUrl:
|
|
7
|
+
baseUrl: r,
|
|
8
8
|
inputs: e,
|
|
9
9
|
apiPlaygroundMode: f,
|
|
10
|
-
requestExampleLanguages:
|
|
10
|
+
requestExampleLanguages: a,
|
|
11
11
|
requiredOnly: g,
|
|
12
12
|
selectedSecurityOptionIndex: L
|
|
13
13
|
}) => {
|
|
14
|
-
const d =
|
|
14
|
+
const d = r && f !== "none" || r && a, o = a ?? [];
|
|
15
15
|
t = t.map((n) => ({
|
|
16
16
|
...n,
|
|
17
17
|
lang: x(n.lang)
|
|
18
|
-
})),
|
|
19
|
-
|
|
18
|
+
})), a === void 0 && (t.forEach((n) => {
|
|
19
|
+
o.includes(n.lang) || o.push(n.lang);
|
|
20
20
|
}), d && k.forEach((n) => {
|
|
21
|
-
|
|
21
|
+
o.includes(n) || o.push(n);
|
|
22
22
|
}));
|
|
23
23
|
const h = {};
|
|
24
|
-
for (const n of
|
|
25
|
-
let
|
|
26
|
-
const u = t.filter((
|
|
24
|
+
for (const n of o) {
|
|
25
|
+
let s = m[n] ?? n;
|
|
26
|
+
const u = t.filter((i) => i.lang === n), l = h[s] ?? {};
|
|
27
27
|
if (u.length === 0) {
|
|
28
|
-
const
|
|
29
|
-
baseUrl:
|
|
28
|
+
const i = v({
|
|
29
|
+
baseUrl: r,
|
|
30
30
|
apiReferenceData: c,
|
|
31
31
|
inputs: e,
|
|
32
32
|
apiPlaygroundMode: f,
|
|
@@ -34,37 +34,37 @@ const j = async ({
|
|
|
34
34
|
requiredOnly: g,
|
|
35
35
|
selectedSecurityOptionIndex: L
|
|
36
36
|
});
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
i && E(
|
|
38
|
+
i,
|
|
39
39
|
n,
|
|
40
|
-
|
|
40
|
+
s,
|
|
41
41
|
l,
|
|
42
42
|
!0
|
|
43
43
|
);
|
|
44
44
|
} else
|
|
45
|
-
u.forEach((
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
u.forEach((i) => {
|
|
46
|
+
s = m[n] ?? i.label ?? n, E(
|
|
47
|
+
i,
|
|
48
48
|
n,
|
|
49
|
-
|
|
49
|
+
s,
|
|
50
50
|
l,
|
|
51
51
|
!1
|
|
52
52
|
);
|
|
53
53
|
});
|
|
54
|
-
Object.keys(l).length > 0 && (h[
|
|
54
|
+
Object.keys(l).length > 0 && (h[s] = l);
|
|
55
55
|
}
|
|
56
56
|
return h;
|
|
57
|
-
}, E = (t, c,
|
|
57
|
+
}, E = (t, c, r, e, f) => {
|
|
58
58
|
"" in e && (e["Example 1"] = e[""], delete e[""]);
|
|
59
|
-
const
|
|
59
|
+
const a = Object.keys(e).length, g = t.label ?? (a > 0 ? `Example ${a + 1}` : "");
|
|
60
60
|
e[g] = {
|
|
61
|
-
filename: f ?
|
|
61
|
+
filename: f ? r : g || r,
|
|
62
62
|
// (used in CodeSnippets)
|
|
63
63
|
language: c,
|
|
64
64
|
code: t.source
|
|
65
65
|
};
|
|
66
66
|
};
|
|
67
67
|
export {
|
|
68
|
-
|
|
68
|
+
p as generateSnippetMap
|
|
69
69
|
};
|
|
70
70
|
//# sourceMappingURL=generateSnippetMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateSnippetMap.js","sources":["../../../src/api-playground-2/generators/generateSnippetMap.ts"],"sourcesContent":["import {\n ApiPlaygroundDisplayType,\n requestExampleLanguages as defaultRequestExampleLanguages,\n} from '@mintlify/models';\nimport { ApiPlaygroundInputs, CodeSample } from '@mintlify/validation';\n\nimport type { ApiReferenceDataV2 } from '@/api-playground-2/types';\nimport { shikiLangToDisplayLang, toShikiLang } from '@/constants/snippetPresets';\nimport { ExampleCodeSnippet } from '@/types/exampleCodeSnippet';\n\nimport { generateInteractiveCodeSample } from './generateInteractiveCodeSample';\n\n// more or less identical but in all places where we use Endpoint, we use ApiReferenceDataV2 instead\nexport const generateSnippetMap =
|
|
1
|
+
{"version":3,"file":"generateSnippetMap.js","sources":["../../../src/api-playground-2/generators/generateSnippetMap.ts"],"sourcesContent":["import {\n ApiPlaygroundDisplayType,\n requestExampleLanguages as defaultRequestExampleLanguages,\n} from '@mintlify/models';\nimport { ApiPlaygroundInputs, CodeSample } from '@mintlify/validation';\n\nimport type { ApiReferenceDataV2 } from '@/api-playground-2/types';\nimport { shikiLangToDisplayLang, toShikiLang } from '@/constants/snippetPresets';\nimport { ExampleCodeSnippet } from '@/types/exampleCodeSnippet';\n\nimport { generateInteractiveCodeSample } from './generateInteractiveCodeSample';\n\n// more or less identical but in all places where we use Endpoint, we use ApiReferenceDataV2 instead\nexport const generateSnippetMap = ({\n codeSamples,\n apiReferenceData,\n baseUrl,\n inputs,\n apiPlaygroundMode,\n requestExampleLanguages,\n requiredOnly,\n selectedSecurityOptionIndex,\n}: {\n codeSamples: CodeSample[];\n apiReferenceData: ApiReferenceDataV2;\n baseUrl?: string;\n inputs: ApiPlaygroundInputs;\n apiPlaygroundMode: ApiPlaygroundDisplayType;\n requestExampleLanguages?: string[];\n requiredOnly?: boolean;\n selectedSecurityOptionIndex: number;\n}): Record<string, Record<string, ExampleCodeSnippet>> => {\n const shouldHaveGeneratedExamples =\n (baseUrl && apiPlaygroundMode !== 'none') || (baseUrl && requestExampleLanguages);\n const langOrder = requestExampleLanguages ?? [];\n codeSamples = codeSamples.map((codeSample) => ({\n ...codeSample,\n lang: toShikiLang(codeSample.lang),\n }));\n if (requestExampleLanguages === undefined) {\n codeSamples.forEach((codeSample) => {\n if (langOrder.includes(codeSample.lang)) return;\n langOrder.push(codeSample.lang);\n });\n if (shouldHaveGeneratedExamples) {\n defaultRequestExampleLanguages.forEach((lang) => {\n if (langOrder.includes(lang)) return;\n langOrder.push(lang);\n });\n }\n }\n\n const map: Record<string, Record<string, ExampleCodeSnippet>> = {};\n\n for (const shikiLang of langOrder) {\n let displayLang = shikiLangToDisplayLang[shikiLang] ?? shikiLang;\n\n const codeSamplesInLang = codeSamples.filter((codeSample) => codeSample.lang === shikiLang);\n\n const labelToSnippetMap = map[displayLang] ?? {};\n if (codeSamplesInLang.length === 0) {\n const generatedCodeSample = generateInteractiveCodeSample({\n baseUrl,\n apiReferenceData,\n inputs,\n apiPlaygroundMode,\n lang: shikiLang,\n requiredOnly,\n selectedSecurityOptionIndex,\n });\n if (generatedCodeSample) {\n addCodeSampleToLabelToSnippetMap(\n generatedCodeSample,\n shikiLang,\n displayLang,\n labelToSnippetMap,\n true\n );\n }\n } else {\n codeSamplesInLang.forEach((codeSample) => {\n displayLang = shikiLangToDisplayLang[shikiLang] ?? codeSample.label ?? shikiLang;\n addCodeSampleToLabelToSnippetMap(\n codeSample,\n shikiLang,\n displayLang,\n labelToSnippetMap,\n false\n );\n });\n }\n if (Object.keys(labelToSnippetMap).length > 0) {\n map[displayLang] = labelToSnippetMap;\n }\n }\n\n return map;\n};\n\nconst addCodeSampleToLabelToSnippetMap = (\n codeSample: CodeSample,\n shikiLang: string,\n displayLang: string,\n labelToSnippetMap: Record<string, ExampleCodeSnippet>,\n isGenerated: boolean\n) => {\n // if we have entered an empty label, retroactively update it to 'Example 1'\n if ('' in labelToSnippetMap) {\n labelToSnippetMap['Example 1'] = labelToSnippetMap[''];\n delete labelToSnippetMap[''];\n }\n\n const numExistingLabels = Object.keys(labelToSnippetMap).length;\n const label =\n codeSample.label ?? (numExistingLabels > 0 ? `Example ${numExistingLabels + 1}` : '');\n\n labelToSnippetMap[label] = {\n filename: isGenerated ? displayLang : label || displayLang, // (used in CodeSnippets)\n language: shikiLang,\n code: codeSample.source,\n };\n};\n"],"names":["generateSnippetMap","codeSamples","apiReferenceData","baseUrl","inputs","apiPlaygroundMode","requestExampleLanguages","requiredOnly","selectedSecurityOptionIndex","shouldHaveGeneratedExamples","langOrder","codeSample","toShikiLang","defaultRequestExampleLanguages","lang","map","shikiLang","displayLang","shikiLangToDisplayLang","codeSamplesInLang","labelToSnippetMap","generatedCodeSample","generateInteractiveCodeSample","addCodeSampleToLabelToSnippetMap","isGenerated","numExistingLabels","label"],"mappings":";;;AAaO,MAAMA,IAAqB,CAAC;AAAA,EACjC,aAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,mBAAAC;AAAA,EAAA,yBACAC;AAAAA,EACA,cAAAC;AAAA,EACA,6BAAAC;AACF,MAS0D;AACxD,QAAMC,IACHN,KAAWE,MAAsB,UAAYF,KAAWG,GACrDI,IAAYJ,KAA2B,CAAA;AAC7C,EA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AAEH,EAAI,MAAMJ,MACRA,EAAkB,WAAW,IAAIA,EAAkB,EAAE,GACrD,OAAOA,EAAkB,EAAE;AAG7B,QAAMK,IAAoB,OAAO,KAAKL,CAAiB,EAAE,QACnDM,IACJf,EAAW,UAAUc,IAAoB,IAAI,WAAWA,IAAoB,CAAC,KAAK;AAEpF,EAAAL,EAAkBM,CAAK,IAAI;AAAA,IACzB,UAAUF,IAAcP,IAAcS,KAAST;AAAA;AAAA,IAC/C,UAAUD;AAAA,IACV,MAAML,EAAW;AAAA,EAAA;AAErB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSendPlaygroundRequest.js","sources":["../../../src/api-playground-2/hooks/useSendPlaygroundRequest.ts"],"sourcesContent":["'use client';\n\nimport { ApiPlaygroundResultType } from '@mintlify/models';\nimport { HttpMethod } from '@mintlify/validation';\nimport { AxiosResponse } from 'axios';\nimport { useCallback } from 'react';\nimport { NEXT_PUBLIC } from '@/env';\n\n\nimport { ApiReferenceDataV2 } from '../types';\nimport { usePlaygroundInputsStore } from './usePlaygroundInputsStore';\n\nexport type UseSendPlaygroundRequestProps = {\n apiReferenceData: ApiReferenceDataV2;\n baseUrl: string | undefined;\n contentType: string | undefined;\n setResult: (result: ApiPlaygroundResultType) => void;\n setIsSending: (isSending: boolean) => void;\n};\n\nexport type RequestInfo = {\n method: HttpMethod;\n url: string;\n header: Record<string, unknown>;\n query: Record<string, unknown>;\n cookie: Record<string, unknown>;\n body: unknown;\n};\n\nexport const useSendPlaygroundRequest = ({\n apiReferenceData,\n baseUrl,\n contentType = 'application/json',\n setResult,\n setIsSending,\n}: UseSendPlaygroundRequestProps) => {\n // replace with msft analytics \n const { getApiPlaygroundInputs } = usePlaygroundInputsStore();\n const inputs = getApiPlaygroundInputs();\n\n const disableProxy = apiReferenceData.operation?.disableProxy;\n const path = apiReferenceData.operation?.path;\n const method = apiReferenceData.operation?.method;\n\n return useCallback(async () => {\n setIsSending(true);\n if (!path || !baseUrl || !method || !contentType || !baseUrl) {\n setIsSending(false);\n setResult({\n error: true,\n errorMessage: 'Missing required fields to send a playground request',\n });\n console.error(\n `Missing some required field to send a playground request:\\n\\npath=${path}\\nmethod=${method}\\ncontentType=${contentType}\\nbaseUrl=${baseUrl}`\n );\n return;\n }\n const axios = await import('axios').then((x) => x.default);\n\n const pathWithInputs = addPathParams(path, inputs.path);\n\n const url = joinWithSingleSlash(addServerVariables(baseUrl, inputs.server), pathWithInputs);\n\n const headers = addContentType(inputs.header, contentType);\n\n const request: RequestInfo = {\n method,\n url,\n header: headers,\n body: inputs.body,\n cookie: inputs.cookie,\n query: inputs.query,\n };\n\n try {\n if (disableProxy) {\n const response = await performDirectRequest(request);\n setResult({\n error: false,\n response: {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n data: response.data,\n },\n });\n } else {\n if (contentType && contentType.includes('multipart/form-data')) {\n const data = await performFileRequest(request);\n\n setResult(data);\n } else {\n const { data } = await axios.post<unknown, AxiosResponse<ApiPlaygroundResultType>>(\n `${NEXT_PUBLIC.BASE_PATH}/_mintlify/api/request`,\n request\n );\n setResult(data);\n }\n }\n } catch (err) {\n setResult({\n error: true,\n errorMessage: 'unable to complete request',\n });\n console.error(err);\n }\n setIsSending(false);\n }, [\n method,\n path,\n setIsSending,\n inputs,\n baseUrl,\n contentType,\n disableProxy,\n setResult,\n ]);\n};\n\nexport const addPathParams = (path: string, pathInputs: Record<string, unknown>) => {\n return Object.entries(pathInputs).reduce((path, [inputName, inputValue]) => {\n if (inputValue == undefined) return path;\n return path.replace(`{${inputName}}`, encodeURIComponent(inputValue.toString()));\n }, path);\n};\n\nexport const addServerVariables = (baseUrl: string, variables: Record<string, string>): string => {\n let url = baseUrl;\n Object.entries(variables).forEach(([key, input]) => {\n if (input) url = url.replace(`{${key}}`, input);\n });\n return url;\n};\n\nexport const joinWithSingleSlash = (baseUrl: string, path: string): string => {\n // remove the last slash of the baseUrl and the first slash of the path, and join with slash\n return baseUrl.replace(/\\/$/, '') + '/' + path.replace(/^\\//, '');\n};\n\nconst addContentType = (headers: Record<string, unknown>, contentType: string) => {\n if (Object.keys(headers).some((name) => name.toLowerCase() === 'content-type')) {\n return headers;\n }\n\n return {\n ...headers,\n ['content-type']: contentType,\n };\n};\n\nconst performDirectRequest = async (request: RequestInfo) => {\n const axios = await import('axios').then((it) => it.default);\n\n const contentType = Object.keys(request.header).find(\n (key) => key.toLowerCase() === 'content-type'\n );\n let data = request.body;\n \n let headers = request.header as Record<string, string>;\n if (contentType?.includes('multipart/form-data')) {\n const { data: formData, headers: formHeaders } = handleFormData(request);\n data = formData;\n headers = formHeaders;\n }\n\n return axios({\n url: request.url,\n method: request.method,\n params: request.query,\n data,\n headers,\n // prevent axios from adding [] after array query params\n paramsSerializer: {\n indexes: null,\n },\n responseType: 'arraybuffer',\n // prevent axios from erroring on bad status codes\n validateStatus: () => true,\n // prevent axios from parsing json, losing whitespace information, and using default utf-8 encoding\n // we can't use `responseEncoding` as it's ignored client-side\n transformResponse: (data) => {\n return Buffer.from(data).toString('base64');\n },\n });\n};\n\nconst performFileRequest = async (request: RequestInfo) => {\n const axios = await import('axios').then((it) => it.default);\n const formData = new FormData();\n formData.append(\n 'requestInfo',\n JSON.stringify({\n method: request.method,\n url: request.url,\n header: request.header,\n query: request.query,\n cookie: request.cookie,\n })\n );\n if (typeof request.body === 'object' && request.body !== null) {\n Object.entries(request.body).forEach(([key, value]) => {\n if (value instanceof File) {\n formData.append(key, value);\n } else if (Array.isArray(value)) {\n value.forEach((item) => {\n if (item instanceof File) {\n formData.append(key, item);\n } else if (item !== undefined && item !== null) {\n formData.append(key, typeof item === 'object' ? JSON.stringify(item) : item.toString());\n }\n });\n } else if (value !== undefined && value !== null) {\n formData.append(key, typeof value === 'object' ? JSON.stringify(value) : value.toString());\n }\n });\n }\n\n const { data } = await axios.post<unknown, AxiosResponse<ApiPlaygroundResultType>>(\n `${NEXT_PUBLIC.BASE_PATH}/_mintlify/api/file-request`,\n formData\n );\n return data;\n};\n\nconst handleFormData = (request: RequestInfo) => {\n let data = request.body;\n \n const headers = request.header as Record<string, string>;\n\n if (headers['content-type']?.includes('multipart/form-data')) {\n const formData = new FormData();\n if (typeof data === 'object' && data !== null) {\n Object.entries(data).forEach(([key, value]) => {\n if (value instanceof File) {\n formData.append(key, value);\n } else if (Array.isArray(value)) {\n value.forEach((item) => {\n if (item instanceof File) {\n formData.append(key, item);\n } else if (item !== undefined && item !== null) {\n formData.append(\n key,\n typeof item === 'object' ? JSON.stringify(item) : item.toString()\n );\n }\n });\n } else if (value !== undefined && value !== null) {\n formData.append(\n key,\n typeof value === 'object' ? JSON.stringify(value) : value.toString()\n );\n }\n });\n data = formData;\n delete headers['content-type'];\n }\n }\n return { data, headers };\n};\n"],"names":["useSendPlaygroundRequest","apiReferenceData","baseUrl","contentType","setResult","setIsSending","getApiPlaygroundInputs","usePlaygroundInputsStore","inputs","disableProxy","_a","path","_b","method","_c","useCallback","axios","x","pathWithInputs","addPathParams","url","joinWithSingleSlash","addServerVariables","headers","addContentType","request","response","performDirectRequest","data","performFileRequest","NEXT_PUBLIC","err","pathInputs","inputName","inputValue","variables","key","input","name","it","formData","formHeaders","handleFormData","value","item"],"mappings":";;;AA6BO,MAAMA,IAA2B,CAAC;AAAA,EACvC,kBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,WAAAC;AAAA,EACA,cAAAC;AACF,MAAqC;;AAEnC,QAAM,EAAE,wBAAAC,EAAA,IAA2BC,EAAA,GAC7BC,IAASF,EAAA,GAETG,KAAeC,IAAAT,EAAiB,cAAjB,gBAAAS,EAA4B,cAC3CC,KAAOC,IAAAX,EAAiB,cAAjB,gBAAAW,EAA4B,MACnCC,KAASC,IAAAb,EAAiB,cAAjB,gBAAAa,EAA4B;AAE3C,SAAOC,EAAY,YAAY;AAE7B,QADAV,EAAa,EAAI,GACb,CAACM,KAAQ,CAACT,KAAW,CAACW,KAAU,CAACV,KAAe,CAACD,GAAS;AA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roundResultType } from '@mintlify/models';\nimport { HttpMethod } from '@mintlify/validation';\nimport { AxiosResponse } from 'axios';\nimport { useCallback } from 'react';\nimport { NEXT_PUBLIC } from '@/env';\n\n\nimport { ApiReferenceDataV2 } from '../types';\nimport { usePlaygroundInputsStore } from './usePlaygroundInputsStore';\n\nexport type UseSendPlaygroundRequestProps = {\n apiReferenceData: ApiReferenceDataV2;\n baseUrl: string | undefined;\n contentType: string | undefined;\n setResult: (result: ApiPlaygroundResultType) => void;\n setIsSending: (isSending: boolean) => void;\n};\n\nexport type RequestInfo = {\n method: HttpMethod;\n url: string;\n header: Record<string, unknown>;\n query: Record<string, unknown>;\n cookie: Record<string, unknown>;\n body: unknown;\n};\n\nexport const useSendPlaygroundRequest = ({\n apiReferenceData,\n baseUrl,\n contentType = 'application/json',\n setResult,\n setIsSending,\n}: UseSendPlaygroundRequestProps) => {\n // replace with msft analytics \n const { getApiPlaygroundInputs } = usePlaygroundInputsStore();\n const inputs = getApiPlaygroundInputs();\n\n const disableProxy = apiReferenceData.operation?.disableProxy;\n const path = apiReferenceData.operation?.path;\n const method = apiReferenceData.operation?.method;\n\n return useCallback(async () => {\n setIsSending(true);\n if (!path || !baseUrl || !method || !contentType || !baseUrl) {\n setIsSending(false);\n setResult({\n error: true,\n errorMessage: 'Missing required fields to send a playground request',\n });\n console.error(\n `Missing some required field to send a playground request:\\n\\npath=${path}\\nmethod=${method}\\ncontentType=${contentType}\\nbaseUrl=${baseUrl}`\n );\n return;\n }\n const axios = await import('axios').then((x) => x.default);\n\n const pathWithInputs = addPathParams(path, inputs.path);\n\n const url = joinWithSingleSlash(addServerVariables(baseUrl, inputs.server), pathWithInputs);\n\n const headers = addContentType(inputs.header, contentType);\n\n const request: RequestInfo = {\n method,\n url,\n header: headers,\n body: inputs.body,\n cookie: inputs.cookie,\n query: inputs.query,\n };\n\n try {\n if (disableProxy) {\n const response = await performDirectRequest(request);\n setResult({\n error: false,\n response: {\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n data: response.data,\n },\n });\n } else {\n if (contentType && contentType.includes('multipart/form-data')) {\n const data = await performFileRequest(request);\n\n setResult(data);\n } else {\n const { data } = await axios.post<unknown, AxiosResponse<ApiPlaygroundResultType>>(\n `${NEXT_PUBLIC.BASE_PATH}/_mintlify/api/request`,\n request\n );\n setResult(data);\n }\n }\n } catch (err) {\n setResult({\n error: true,\n errorMessage: 'unable to complete request',\n });\n console.error(err);\n }\n setIsSending(false);\n }, [\n method,\n path,\n setIsSending,\n inputs,\n baseUrl,\n contentType,\n disableProxy,\n setResult,\n ]);\n};\n\nexport const addPathParams = (path: string, pathInputs: Record<string, unknown>) => {\n return Object.entries(pathInputs).reduce((path, [inputName, inputValue]) => {\n if (inputValue == undefined) return path;\n return path.replace(`{${inputName}}`, encodeURIComponent(inputValue.toString()));\n }, path);\n};\n\nexport const addServerVariables = (baseUrl: string, variables: Record<string, string>): string => {\n let url = baseUrl;\n Object.entries(variables).forEach(([key, input]) => {\n if (input) url = url.replace(`{${key}}`, input);\n });\n return url;\n};\n\nexport const joinWithSingleSlash = (baseUrl: string, path: string): string => {\n // remove the last slash of the baseUrl and the first slash of the path, and join with slash\n return baseUrl.replace(/\\/$/, '') + '/' + path.replace(/^\\//, '');\n};\n\nconst addContentType = (headers: Record<string, unknown>, contentType: string) => {\n if (Object.keys(headers).some((name) => name.toLowerCase() === 'content-type')) {\n return headers;\n }\n\n return {\n ...headers,\n ['content-type']: contentType,\n };\n};\n\nconst performDirectRequest = async (request: RequestInfo) => {\n const axios = await import('axios').then((it) => it.default);\n\n const contentType = Object.keys(request.header).find(\n (key) => key.toLowerCase() === 'content-type'\n );\n let data = request.body;\n \n let headers = request.header as Record<string, string>;\n if (contentType?.includes('multipart/form-data')) {\n const { data: formData, headers: formHeaders } = handleFormData(request);\n data = formData;\n headers = formHeaders;\n }\n\n return axios({\n url: request.url,\n method: request.method,\n params: request.query,\n data,\n headers,\n // prevent axios from adding [] after array query params\n paramsSerializer: {\n indexes: null,\n },\n responseType: 'arraybuffer',\n // prevent axios from erroring on bad status codes\n validateStatus: () => true,\n // prevent axios from parsing json, losing whitespace information, and using default utf-8 encoding\n // we can't use `responseEncoding` as it's ignored client-side\n transformResponse: (data) => {\n return Buffer.from(data).toString('base64');\n },\n });\n};\n\nconst performFileRequest = async (request: RequestInfo) => {\n const axios = await import('axios').then((it) => it.default);\n const formData = new FormData();\n formData.append(\n 'requestInfo',\n JSON.stringify({\n method: request.method,\n url: request.url,\n header: request.header,\n query: request.query,\n cookie: request.cookie,\n })\n );\n if (typeof request.body === 'object' && request.body !== null) {\n Object.entries(request.body).forEach(([key, value]) => {\n if (value instanceof File) {\n formData.append(key, value);\n } else if (Array.isArray(value)) {\n value.forEach((item) => {\n if (item instanceof File) {\n formData.append(key, item);\n } else if (item !== undefined && item !== null) {\n formData.append(key, typeof item === 'object' ? JSON.stringify(item) : item.toString());\n }\n });\n } else if (value !== undefined && value !== null) {\n formData.append(key, typeof value === 'object' ? JSON.stringify(value) : value.toString());\n }\n });\n }\n\n const { data } = await axios.post<unknown, AxiosResponse<ApiPlaygroundResultType>>(\n `${NEXT_PUBLIC.BASE_PATH}/_mintlify/api/file-request`,\n formData\n );\n return data;\n};\n\nconst handleFormData = (request: RequestInfo) => {\n let data = request.body;\n \n const headers = request.header as Record<string, string>;\n\n if (headers['content-type']?.includes('multipart/form-data')) {\n const formData = new FormData();\n if (typeof data === 'object' && data !== null) {\n Object.entries(data).forEach(([key, value]) => {\n if (value instanceof File) {\n formData.append(key, value);\n } else if (Array.isArray(value)) {\n value.forEach((item) => {\n if (item instanceof File) {\n formData.append(key, item);\n } else if (item !== undefined && item !== null) {\n formData.append(\n key,\n typeof item === 'object' ? JSON.stringify(item) : item.toString()\n );\n }\n });\n } else if (value !== undefined && value !== null) {\n formData.append(\n key,\n typeof value === 'object' ? JSON.stringify(value) : value.toString()\n );\n }\n });\n data = formData;\n delete headers['content-type'];\n }\n }\n return { data, headers };\n};\n"],"names":["useSendPlaygroundRequest","apiReferenceData","baseUrl","contentType","setResult","setIsSending","getApiPlaygroundInputs","usePlaygroundInputsStore","inputs","disableProxy","_a","path","_b","method","_c","useCallback","axios","x","pathWithInputs","addPathParams","url","joinWithSingleSlash","addServerVariables","headers","addContentType","request","response","performDirectRequest","data","performFileRequest","NEXT_PUBLIC","err","pathInputs","inputName","inputValue","variables","key","input","name","it","formData","formHeaders","handleFormData","value","item"],"mappings":";;;AA4BO,MAAMA,IAA2B,CAAC;AAAA,EACvC,kBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,WAAAC;AAAA,EACA,cAAAC;AACF,MAAqC;;AAEnC,QAAM,EAAE,wBAAAC,EAAA,IAA2BC,EAAA,GAC7BC,IAASF,EAAA,GAETG,KAAeC,IAAAT,EAAiB,cAAjB,gBAAAS,EAA4B,cAC3CC,KAAOC,IAAAX,EAAiB,cAAjB,gBAAAW,EAA4B,MACnCC,KAASC,IAAAb,EAAiB,cAAjB,gBAAAa,EAA4B;AAE3C,SAAOC,EAAY,YAAY;AAE7B,QADAV,EAAa,EAAI,GACb,CAACM,KAAQ,CAACT,KAAW,CAACW,KAAU,CAACV,KAAe,CAACD,GAAS;AAC5D,MAAAG,EAAa,EAAK,GAClBD,EAAU;AAAA,QACR,OAAO;AAAA,QACP,cAAc;AAAA,MAAA,CACf,GACD,QAAQ;AAAA,QACN;AAAA;AAAA,OAAqEO,CAAI;AAAA,SAAYE,CAAM;AAAA,cAAiBV,CAAW;AAAA,UAAaD,CAAO;AAAA,MAAA;AAE7I;AAAA,IACF;AACA,UAAMc,IAAQ,MAAM,OAAO,OAAO,EAAE,KAAK,CAACC,MAAMA,EAAE,OAAO,GAEnDC,IAAiBC,EAAcR,GAAMH,EAAO,IAAI,GAEhDY,IAAMC,EAAoBC,EAAmBpB,GAASM,EAAO,MAAM,GAAGU,CAAc,GAEpFK,IAAUC,EAAehB,EAAO,QAAQL,CAAW,GAEnDsB,IAAuB;AAAA,MAC3B,QAAAZ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SACvC,OAAO,QAAQA,CAAI,EAAE,QAAQ,CAAC,CAACQ,GAAKO,CAAK,MAAM;AAC7C,MAAIA,aAAiB,OACnBH,EAAS,OAAOJ,GAAKO,CAAK,IACjB,MAAM,QAAQA,CAAK,IAC5BA,EAAM,QAAQ,CAACC,MAAS;AACtB,QAAIA,aAAgB,OAClBJ,EAAS,OAAOJ,GAAKQ,CAAI,IACMA,KAAS,QACxCJ,EAAS;AAAA,UACPJ;AAAA,UACA,OAAOQ,KAAS,WAAW,KAAK,UAAUA,CAAI,IAAIA,EAAK,SAAA;AAAA,QAAS;AAAA,MAGtE,CAAC,IAC+BD,KAAU,QAC1CH,EAAS;AAAA,QACPJ;AAAA,QACA,OAAOO,KAAU,WAAW,KAAK,UAAUA,CAAK,IAAIA,EAAM,SAAA;AAAA,MAAS;AAAA,IAGzE,CAAC,GACDf,IAAOY,GACP,OAAOjB,EAAQ,cAAc;AAAA,EAEjC;AACA,SAAO,EAAE,MAAAK,GAAM,SAAAL,EAAA;AACjB;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isSchemaObject as s, escapeDots as p } from "./utils.js";
|
|
2
|
+
const n = (d, o = "") => {
|
|
3
|
+
if (!s(d))
|
|
4
|
+
return d;
|
|
5
|
+
const e = {
|
|
6
|
+
...d,
|
|
7
|
+
uniqueKey: o
|
|
8
|
+
};
|
|
9
|
+
if (e.oneOf && Array.isArray(e.oneOf) && (e.oneOf = e.oneOf.map((t, i) => {
|
|
10
|
+
if (s(t)) {
|
|
11
|
+
const r = o ? `${o}.oneOf.${i}` : `${i}`;
|
|
12
|
+
return n(t, r);
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
})), e.type === "object" && e.properties) {
|
|
16
|
+
const t = {};
|
|
17
|
+
Object.entries(e.properties).forEach(([i, r]) => {
|
|
18
|
+
if (s(r)) {
|
|
19
|
+
const a = o ? `${o}.${p(i)}` : p(i);
|
|
20
|
+
t[i] = n(r, a);
|
|
21
|
+
} else
|
|
22
|
+
t[i] = r;
|
|
23
|
+
}), e.properties = t;
|
|
24
|
+
}
|
|
25
|
+
if (e.additionalProperties && typeof e.additionalProperties == "object" && s(e.additionalProperties)) {
|
|
26
|
+
const t = o ? `${o}.additionalProperties` : "additionalProperties";
|
|
27
|
+
e.additionalProperties = n(
|
|
28
|
+
e.additionalProperties,
|
|
29
|
+
t
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (e.type === "array" && "items" in e && s(e.items)) {
|
|
33
|
+
const t = o ? `${o}.items` : "items";
|
|
34
|
+
e.items = n(e.items, t);
|
|
35
|
+
}
|
|
36
|
+
return e;
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
n as addUniqueKeysToSchema
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=addUniqueKeysToSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addUniqueKeysToSchema.js","sources":["../../../src/api-playground-2/schemaGraph/addUniqueKeysToSchema.ts"],"sourcesContent":["import { SchemaObject } from '@mintlify/validation';\n\nimport { escapeDots, isSchemaObject } from '@/api-playground-2/schemaGraph/utils';\nimport type { ResolvedSchemaObject } from '@/api-playground-2/types';\n\n/**\n * Add unique keys to each schema node, representing the path from the root.\n * This is used to generate unique input keys for the playground data store.\n *\n * @param schema - The schema to process\n * @param pathPrefix - The current path prefix (e.g., \"body.application/json\")\n * @returns The schema with uniqueKey properties added\n */\nexport const addUniqueKeysToSchema = (\n schema: SchemaObject,\n pathPrefix: string = ''\n): ResolvedSchemaObject => {\n if (!isSchemaObject(schema)) {\n return schema;\n }\n\n const processedSchema: ResolvedSchemaObject = {\n ...schema,\n uniqueKey: pathPrefix,\n };\n\n if (processedSchema.oneOf && Array.isArray(processedSchema.oneOf)) {\n processedSchema.oneOf = processedSchema.oneOf.map((subSchema, index) => {\n if (isSchemaObject(subSchema)) {\n const subPath = pathPrefix ? `${pathPrefix}.oneOf.${index}` : `${index}`;\n return addUniqueKeysToSchema(subSchema, subPath);\n }\n return subSchema;\n });\n }\n\n if (processedSchema.type === 'object' && processedSchema.properties) {\n const processedProperties: Record<string, SchemaObject> = {};\n Object.entries(processedSchema.properties).forEach(([name, propSchema]) => {\n if (isSchemaObject(propSchema)) {\n const propPath = pathPrefix ? `${pathPrefix}.${escapeDots(name)}` : escapeDots(name);\n processedProperties[name] = addUniqueKeysToSchema(propSchema, propPath);\n } else {\n processedProperties[name] = propSchema;\n }\n });\n processedSchema.properties = processedProperties;\n }\n\n if (\n processedSchema.additionalProperties &&\n typeof processedSchema.additionalProperties === 'object' &&\n isSchemaObject(processedSchema.additionalProperties)\n ) {\n const addPropsPath = pathPrefix ? `${pathPrefix}.additionalProperties` : 'additionalProperties';\n processedSchema.additionalProperties = addUniqueKeysToSchema(\n processedSchema.additionalProperties,\n addPropsPath\n );\n }\n\n if (\n processedSchema.type === 'array' &&\n 'items' in processedSchema &&\n isSchemaObject(processedSchema.items)\n ) {\n const itemsPath = pathPrefix ? `${pathPrefix}.items` : 'items';\n processedSchema.items = addUniqueKeysToSchema(processedSchema.items, itemsPath);\n }\n\n return processedSchema;\n};\n"],"names":["addUniqueKeysToSchema","schema","pathPrefix","isSchemaObject","processedSchema","subSchema","index","subPath","processedProperties","name","propSchema","propPath","escapeDots","addPropsPath","itemsPath"],"mappings":";AAaO,MAAMA,IAAwB,CACnCC,GACAC,IAAqB,OACI;AACzB,MAAI,CAACC,EAAeF,CAAM;AACxB,WAAOA;AAGT,QAAMG,IAAwC;AAAA,IAC5C,GAAGH;AAAA,IACH,WAAWC;AAAA,EAAA;AAab,MAVIE,EAAgB,SAAS,MAAM,QAAQA,EAAgB,KAAK,MAC9DA,EAAgB,QAAQA,EAAgB,MAAM,IAAI,CAACC,GAAWC,MAAU;AACtE,QAAIH,EAAeE,CAAS,GAAG;AAC7B,YAAME,IAAUL,IAAa,GAAGA,CAAU,UAAUI,CAAK,KAAK,GAAGA,CAAK;AACtE,aAAON,EAAsBK,GAAWE,CAAO;AAAA,IACjD;AACA,WAAOF;AAAA,EACT,CAAC,IAGCD,EAAgB,SAAS,YAAYA,EAAgB,YAAY;AACnE,UAAMI,IAAoD,CAAA;AAC1D,WAAO,QAAQJ,EAAgB,UAAU,EAAE,QAAQ,CAAC,CAACK,GAAMC,CAAU,MAAM;AACzE,UAAIP,EAAeO,CAAU,GAAG;AAC9B,cAAMC,IAAWT,IAAa,GAAGA,CAAU,IAAIU,EAAWH,CAAI,CAAC,KAAKG,EAAWH,CAAI;AACnF,QAAAD,EAAoBC,CAAI,IAAIT,EAAsBU,GAAYC,CAAQ;AAAA,MACxE;AACE,QAAAH,EAAoBC,CAAI,IAAIC;AAAA,IAEhC,CAAC,GACDN,EAAgB,aAAaI;AAAA,EAC/B;AAEA,MACEJ,EAAgB,wBAChB,OAAOA,EAAgB,wBAAyB,YAChDD,EAAeC,EAAgB,oBAAoB,GACnD;AACA,UAAMS,IAAeX,IAAa,GAAGA,CAAU,0BAA0B;AACzE,IAAAE,EAAgB,uBAAuBJ;AAAA,MACrCI,EAAgB;AAAA,MAChBS;AAAA,IAAA;AAAA,EAEJ;AAEA,MACET,EAAgB,SAAS,WACzB,WAAWA,KACXD,EAAeC,EAAgB,KAAK,GACpC;AACA,UAAMU,IAAYZ,IAAa,GAAGA,CAAU,WAAW;AACvD,IAAAE,EAAgB,QAAQJ,EAAsBI,EAAgB,OAAOU,CAAS;AAAA,EAChF;AAEA,SAAOV;AACT;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const s = (r, ...e) => [r.map((o) => o.replace("\\", "\\\\").replace("/", "\\/")).join("/"), ...e].join(`
|
|
2
|
+
`);
|
|
3
|
+
class n extends Error {
|
|
4
|
+
constructor(e, ...t) {
|
|
5
|
+
super(s(e, ...t)), this.name = "ImpossibleSchemaError", Object.setPrototypeOf(this, n.prototype);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
function a(r, e, t = !1, ...o) {
|
|
9
|
+
if (t)
|
|
10
|
+
console.error(s(e, ...o), r);
|
|
11
|
+
else
|
|
12
|
+
throw r;
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
n as ImpossibleSchemaError,
|
|
16
|
+
s as generateMessage,
|
|
17
|
+
a as handleExistingError
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sources":["../../../src/api-playground-2/schemaGraph/errors.ts"],"sourcesContent":["// ERRORS\nexport const generateMessage = (path: string[], ...messages: string[]): string => {\n const pathString = path\n .map((component) => component.replace('\\\\', '\\\\\\\\').replace('/', '\\\\/'))\n .join('/');\n return [pathString, ...messages].join('\\n');\n};\n\n/**\n * Thrown when a value is incorrect or missing, according to the OpenAPI spec.\n */\nexport class InvalidSchemaError extends Error {\n constructor(path: string[], ...messages: string[]) {\n super(generateMessage(path, ...messages));\n this.name = 'InvalidSchemaError';\n Object.setPrototypeOf(this, InvalidSchemaError.prototype);\n }\n}\n\n/**\n * Thrown when a schema is valid according to OpenAPI, but is unsatisfiable\n * (e.g. a value that must be both a number and a string).\n */\nexport class ImpossibleSchemaError extends Error {\n constructor(path: string[], ...messages: string[]) {\n super(generateMessage(path, ...messages));\n this.name = 'ImpossibleSchemaError';\n Object.setPrototypeOf(this, ImpossibleSchemaError.prototype);\n }\n}\n\n/**\n * Thrown when there is an issue that was caused in another part of the conversion\n * (e.g. a schema in reduced form that is missing `oneOf`).\n */\nexport class ConversionError extends Error {\n constructor(path: string[], ...messages: string[]) {\n super(generateMessage(path, ...messages));\n this.name = 'ConversionError';\n Object.setPrototypeOf(this, ConversionError.prototype);\n }\n}\n\nexport function handleExistingError(\n error: unknown,\n path: string[],\n safeParse: boolean = false,\n ...messages: string[]\n) {\n if (safeParse) {\n console.error(generateMessage(path, ...messages), error);\n } else {\n throw error;\n }\n}\n"],"names":["generateMessage","path","messages","component","ImpossibleSchemaError","handleExistingError","error","safeParse"],"mappings":"AACO,MAAMA,IAAkB,CAACC,MAAmBC,MAI1C,CAHYD,EAChB,IAAI,CAACE,MAAcA,EAAU,QAAQ,MAAM,MAAM,EAAE,QAAQ,KAAK,KAAK,CAAC,EACtE,KAAK,GAAG,GACS,GAAGD,CAAQ,EAAE,KAAK;AAAA,CAAI;AAkBrC,MAAME,UAA8B,MAAM;AAAA,EAC/C,YAAYH,MAAmBC,GAAoB;AACjD,UAAMF,EAAgBC,GAAM,GAAGC,CAAQ,CAAC,GACxC,KAAK,OAAO,yBACZ,OAAO,eAAe,MAAME,EAAsB,SAAS;AAAA,EAC7D;AACF;AAcO,SAASC,EACdC,GACAL,GACAM,IAAqB,OAClBL,GACH;AACA,MAAIK;AACF,YAAQ,MAAMP,EAAgBC,GAAM,GAAGC,CAAQ,GAAGI,CAAK;AAAA;AAEvD,UAAMA;AAEV;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseApiTargetFromMetadata as o } from "../../common/parseApiTargetFromMetadata.js";
|
|
2
|
+
import { getSchemaGraphOperationData as p } from "./getSchemaGraphOperationData.js";
|
|
3
|
+
import { getSchemaGraphSchemaData as m } from "./getSchemaGraphSchemaData.js";
|
|
4
|
+
const f = ({
|
|
5
|
+
metadata: e,
|
|
6
|
+
schemaGraphData: t
|
|
7
|
+
}) => {
|
|
8
|
+
const r = o(e);
|
|
9
|
+
if (!r)
|
|
10
|
+
return {};
|
|
11
|
+
try {
|
|
12
|
+
return r.type === "operation" ? p({
|
|
13
|
+
target: r,
|
|
14
|
+
schemaGraphData: t
|
|
15
|
+
}) : m({
|
|
16
|
+
target: r,
|
|
17
|
+
schemaGraphData: t
|
|
18
|
+
});
|
|
19
|
+
} catch (a) {
|
|
20
|
+
throw a;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export {
|
|
24
|
+
f as getApiReferenceDataFromGraph
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=getApiReferenceDataFromGraph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getApiReferenceDataFromGraph.js","sources":["../../../src/api-playground-2/schemaGraph/getApiReferenceDataFromGraph.ts"],"sourcesContent":["import { parseApiTargetFromMetadata } from '../../common/parseApiTargetFromMetadata';\nimport type { PageMetaTags } from '@mintlify/models';\nimport type { SchemaGraphData } from '@mintlify/validation';\n\nimport type { ApiReferenceDataV2 } from '@/api-playground-2/types';\n\nimport { getSchemaGraphOperationData } from './getSchemaGraphOperationData';\nimport { getSchemaGraphSchemaData } from './getSchemaGraphSchemaData';\n\nexport const getApiReferenceDataFromGraph = ({\n metadata,\n schemaGraphData,\n}: {\n metadata: PageMetaTags;\n schemaGraphData: SchemaGraphData;\n}): ApiReferenceDataV2 => {\n const target = parseApiTargetFromMetadata(metadata);\n\n if (!target) {\n return {};\n }\n\n try {\n if (target.type === 'operation') {\n return getSchemaGraphOperationData({\n target,\n schemaGraphData,\n });\n } else {\n return getSchemaGraphSchemaData({\n target,\n schemaGraphData,\n });\n }\n } catch (error) {\n throw error;\n }\n};\n"],"names":["getApiReferenceDataFromGraph","metadata","schemaGraphData","target","parseApiTargetFromMetadata","getSchemaGraphOperationData","getSchemaGraphSchemaData","error"],"mappings":";;;AASO,MAAMA,IAA+B,CAAC;AAAA,EAC3C,UAAAC;AAAA,EACA,iBAAAC;AACF,MAG0B;AACxB,QAAMC,IAASC,EAA2BH,CAAQ;AAElD,MAAI,CAACE;AACH,WAAO,CAAA;AAGT,MAAI;AACF,WAAIA,EAAO,SAAS,cACXE,EAA4B;AAAA,MACjC,QAAAF;AAAA,MACA,iBAAAD;AAAA,IAAA,CACD,IAEMI,EAAyB;AAAA,MAC9B,QAAAH;AAAA,MACA,iBAAAD;AAAA,IAAA,CACD;AAAA,EAEL,SAASK,GAAO;AACd,UAAMA;AAAA,EACR;AACF;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import u from "lodash/zip";
|
|
2
|
+
import { deeplyResolveGraphNode as p, resolveGraphNode as n } from "./resolveGraphNode.js";
|
|
3
|
+
import { flattenSingleOneOf as c } from "./utils.js";
|
|
4
|
+
const d = (e) => n({
|
|
5
|
+
uuidObjectHashMap: e.spec.uuidObjectHashMap,
|
|
6
|
+
hashedNodeMap: e.spec.hashedNodeMap,
|
|
7
|
+
id: e.documentId
|
|
8
|
+
});
|
|
9
|
+
function O({
|
|
10
|
+
operation: e,
|
|
11
|
+
schemaGraphData: r
|
|
12
|
+
}) {
|
|
13
|
+
var o, i;
|
|
14
|
+
const t = (o = d(r)) == null ? void 0 : o.servers, s = (i = d(r)) == null ? void 0 : i.security;
|
|
15
|
+
return {
|
|
16
|
+
...e,
|
|
17
|
+
servers: t,
|
|
18
|
+
security: s
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const l = (e) => {
|
|
22
|
+
var t;
|
|
23
|
+
const r = (t = d(e)) == null ? void 0 : t.servers;
|
|
24
|
+
return r ? Object.fromEntries(
|
|
25
|
+
u(
|
|
26
|
+
r,
|
|
27
|
+
r.map(
|
|
28
|
+
(s) => p({
|
|
29
|
+
uuidObjectHashMap: e.spec.uuidObjectHashMap,
|
|
30
|
+
hashedNodeMap: e.spec.hashedNodeMap,
|
|
31
|
+
id: s
|
|
32
|
+
})
|
|
33
|
+
)
|
|
34
|
+
).filter((s) => s[1] !== void 0).map(([s, o]) => [s, c(o)])
|
|
35
|
+
) : {};
|
|
36
|
+
}, b = (e) => {
|
|
37
|
+
var t;
|
|
38
|
+
const r = (t = d(e)) == null ? void 0 : t.security;
|
|
39
|
+
return r ? Object.fromEntries(
|
|
40
|
+
u(
|
|
41
|
+
r,
|
|
42
|
+
r.map(
|
|
43
|
+
(s) => p({
|
|
44
|
+
uuidObjectHashMap: e.spec.uuidObjectHashMap,
|
|
45
|
+
hashedNodeMap: e.spec.hashedNodeMap,
|
|
46
|
+
id: s
|
|
47
|
+
})
|
|
48
|
+
)
|
|
49
|
+
).filter((s) => s[1] !== void 0).map(([s, o]) => [s, c(o)])
|
|
50
|
+
) : {};
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
d as getDocument,
|
|
54
|
+
b as getResolvedSecuritys,
|
|
55
|
+
l as getResolvedServers,
|
|
56
|
+
O as withDocumentProperties
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=getDocumentProperties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDocumentProperties.js","sources":["../../../src/api-playground-2/schemaGraph/getDocumentProperties.ts"],"sourcesContent":["import {\n Operation,\n SchemaGraphData,\n Document,\n ServerObject,\n SecurityRequirement,\n UUID,\n} from '@mintlify/validation';\nimport zip from 'lodash/zip';\n\nimport {\n deeplyResolveGraphNode,\n resolveGraphNode,\n} from '@/api-playground-2/schemaGraph/resolveGraphNode';\nimport { flattenSingleOneOf } from '@/api-playground-2/schemaGraph/utils';\nimport type { ResolvedSecurityObject } from '@/api-playground-2/types';\n\nexport const getDocument = (schemaGraphData: SchemaGraphData) => {\n return resolveGraphNode<Document>({\n uuidObjectHashMap: schemaGraphData.spec.uuidObjectHashMap,\n hashedNodeMap: schemaGraphData.spec.hashedNodeMap,\n id: schemaGraphData.documentId,\n });\n};\n\n// Decorate an Operation object that has been parsed from a path with some additional properties which\n// are stored at the top level of the schema document.\nexport function withDocumentProperties({\n operation,\n schemaGraphData,\n}: {\n operation: Operation;\n schemaGraphData: SchemaGraphData;\n}): Operation {\n // get servers\n const servers = getDocument(schemaGraphData)?.servers;\n\n // get security\n const security = getDocument(schemaGraphData)?.security;\n\n return {\n ...operation,\n servers,\n security,\n };\n}\n\nexport const getResolvedServers = (\n schemaGraphData: SchemaGraphData\n): Record<string, ServerObject> => {\n const serverUUIDs = getDocument(schemaGraphData)?.servers;\n if (!serverUUIDs) return {};\n\n return Object.fromEntries(\n zip(\n serverUUIDs,\n serverUUIDs.map((serverUUID) =>\n deeplyResolveGraphNode<ServerObject>({\n uuidObjectHashMap: schemaGraphData.spec.uuidObjectHashMap,\n hashedNodeMap: schemaGraphData.spec.hashedNodeMap,\n id: serverUUID,\n })\n )\n )\n .filter((entry): entry is [UUID, ServerObject] => entry[1] !== undefined)\n .map(([uuid, server]) => [uuid, flattenSingleOneOf(server)])\n );\n};\n\nexport const getResolvedSecuritys = (\n schemaGraphData: SchemaGraphData\n): Record<string, ResolvedSecurityObject> => {\n const securityUUIDs = getDocument(schemaGraphData)?.security;\n if (!securityUUIDs) return {};\n\n return Object.fromEntries(\n zip(\n securityUUIDs,\n securityUUIDs.map((securityUUID) =>\n deeplyResolveGraphNode<SecurityRequirement>({\n uuidObjectHashMap: schemaGraphData.spec.uuidObjectHashMap,\n hashedNodeMap: schemaGraphData.spec.hashedNodeMap,\n id: securityUUID,\n })\n )\n )\n .filter((entry): entry is [UUID, ResolvedSecurityObject] => entry[1] !== undefined)\n .map(([uuid, security]) => [uuid, flattenSingleOneOf(security)])\n );\n};\n"],"names":["getDocument","schemaGraphData","resolveGraphNode","withDocumentProperties","operation","servers","_a","security","_b","getResolvedServers","serverUUIDs","zip","serverUUID","deeplyResolveGraphNode","entry","uuid","server","flattenSingleOneOf","getResolvedSecuritys","securityUUIDs","securityUUID"],"mappings":";;;AAiBO,MAAMA,IAAc,CAACC,MACnBC,EAA2B;AAAA,EAChC,mBAAmBD,EAAgB,KAAK;AAAA,EACxC,eAAeA,EAAgB,KAAK;AAAA,EACpC,IAAIA,EAAgB;AAAA,CACrB;AAKI,SAASE,EAAuB;AAAA,EACrC,WAAAC;AAAA,EACA,iBAAAH;AACF,GAGc;;AAEZ,QAAMI,KAAUC,IAAAN,EAAYC,CAAe,MAA3B,gBAAAK,EAA8B,SAGxCC,KAAWC,IAAAR,EAAYC,CAAe,MAA3B,gBAAAO,EAA8B;AAE/C,SAAO;AAAA,IACL,GAAGJ;AAAA,IACH,SAAAC;AAAA,IACA,UAAAE;AAAA,EAAA;AAEJ;AAEO,MAAME,IAAqB,CAChCR,MACiC;;AACjC,QAAMS,KAAcJ,IAAAN,EAAYC,CAAe,MAA3B,gBAAAK,EAA8B;AAClD,SAAKI,IAEE,OAAO;AAAA,IACZC;AAAA,MACED;AAAA,MACAA,EAAY;AAAA,QAAI,CAACE,MACfC,EAAqC;AAAA,UACnC,mBAAmBZ,EAAgB,KAAK;AAAA,UACxC,eAAeA,EAAgB,KAAK;AAAA,UACpC,IAAIW;AAAA,QAAA,CACL;AAAA,MAAA;AAAA,IACH,EAEC,OAAO,CAACE,MAAyCA,EAAM,CAAC,MAAM,MAAS,EACvE,IAAI,CAAC,CAACC,GAAMC,CAAM,MAAM,CAACD,GAAME,EAAmBD,CAAM,CAAC,CAAC;AAAA,EAAA,IAdtC,CAAA;AAgB3B,GAEaE,IAAuB,CAClCjB,MAC2C;;AAC3C,QAAMkB,KAAgBb,IAAAN,EAAYC,CAAe,MAA3B,gBAAAK,EAA8B;AACpD,SAAKa,IAEE,OAAO;AAAA,IACZR;AAAA,MACEQ;AAAA,MACAA,EAAc;AAAA,QAAI,CAACC,MACjBP,EAA4C;AAAA,UAC1C,mBAAmBZ,EAAgB,KAAK;AAAA,UACxC,eAAeA,EAAgB,KAAK;AAAA,UACpC,IAAImB;AAAA,QAAA,CACL;AAAA,MAAA;AAAA,IACH,EAEC,OAAO,CAACN,MAAmDA,EAAM,CAAC,MAAM,MAAS,EACjF,IAAI,CAAC,CAACC,GAAMR,CAAQ,MAAM,CAACQ,GAAME,EAAmBV,CAAQ,CAAC,CAAC;AAAA,EAAA,IAdxC,CAAA;AAgB7B;"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { withDocumentProperties as h, getResolvedServers as f, getResolvedSecuritys as b } from "./getDocumentProperties.js";
|
|
2
|
+
import { resolveGraphNode as O } from "./resolveGraphNode.js";
|
|
3
|
+
import { resolveOperationWithDependencies as v } from "./resolveOperationWithDependencies.js";
|
|
4
|
+
const y = ({
|
|
5
|
+
operation: e,
|
|
6
|
+
target: n,
|
|
7
|
+
baseUrlOptions: o
|
|
8
|
+
}) => {
|
|
9
|
+
let r, t = [];
|
|
10
|
+
o.length > 1 ? t = o : r = o[0];
|
|
11
|
+
const i = [];
|
|
12
|
+
return Array.isArray(e["x-code-samples"]) && e["x-code-samples"].length > 0 && e["x-code-samples"].forEach((s) => {
|
|
13
|
+
s && typeof s == "object" && "source" in s && typeof s.source == "string" && "lang" in s && typeof s.lang == "string" && i.push({
|
|
14
|
+
label: "label" in s && typeof s.label == "string" ? s.label : void 0,
|
|
15
|
+
lang: s.lang,
|
|
16
|
+
source: s.source
|
|
17
|
+
});
|
|
18
|
+
}), {
|
|
19
|
+
...e,
|
|
20
|
+
path: n.endpoint || "",
|
|
21
|
+
baseUrl: r,
|
|
22
|
+
baseUrlOptions: t,
|
|
23
|
+
title: e.summary ?? "",
|
|
24
|
+
description: e.description ?? "",
|
|
25
|
+
codeSamples: i
|
|
26
|
+
};
|
|
27
|
+
}, g = (e, n, o) => {
|
|
28
|
+
const r = e.spec.refUuidMap[`${n}/${o}`];
|
|
29
|
+
if (!r) return;
|
|
30
|
+
const t = O({
|
|
31
|
+
uuidObjectHashMap: e.spec.uuidObjectHashMap,
|
|
32
|
+
hashedNodeMap: e.spec.hashedNodeMap,
|
|
33
|
+
id: r
|
|
34
|
+
});
|
|
35
|
+
return o === "webhook" ? t == null ? void 0 : t.post : t == null ? void 0 : t[o];
|
|
36
|
+
}, w = ({
|
|
37
|
+
target: e,
|
|
38
|
+
schemaGraphData: n
|
|
39
|
+
}) => {
|
|
40
|
+
const { uuidObjectHashMap: o, hashedNodeMap: r } = n.spec, t = g(n, e.endpoint, e.method);
|
|
41
|
+
if (!t)
|
|
42
|
+
throw new Error(
|
|
43
|
+
`no matching OpenAPI operation found with path "${e.endpoint}" and method "${e.method}"`
|
|
44
|
+
);
|
|
45
|
+
const i = v({
|
|
46
|
+
operationId: t,
|
|
47
|
+
uuidObjectHashMap: o,
|
|
48
|
+
hashedNodeMap: r
|
|
49
|
+
});
|
|
50
|
+
if (!i)
|
|
51
|
+
return {};
|
|
52
|
+
let s = i.operation;
|
|
53
|
+
s = h({
|
|
54
|
+
operation: s,
|
|
55
|
+
schemaGraphData: n
|
|
56
|
+
});
|
|
57
|
+
const c = f(n), p = b(n), d = Object.values(c).map((l) => l.url), u = y({
|
|
58
|
+
operation: s,
|
|
59
|
+
target: e,
|
|
60
|
+
baseUrlOptions: d
|
|
61
|
+
}), a = {
|
|
62
|
+
...i.dependencies,
|
|
63
|
+
servers: c,
|
|
64
|
+
security: p,
|
|
65
|
+
...i.schemas && { schemas: i.schemas }
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
operation: u,
|
|
69
|
+
dependencies: a
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
y as createOperationV2,
|
|
74
|
+
g as getOperationId,
|
|
75
|
+
w as getSchemaGraphOperationData
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=getSchemaGraphOperationData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSchemaGraphOperationData.js","sources":["../../../src/api-playground-2/schemaGraph/getSchemaGraphOperationData.ts"],"sourcesContent":["import type { OperationTargetType } from '@mintlify/common';\nimport type {\n CodeSample,\n HttpMethod,\n PathOrRef,\n SchemaGraphData,\n Operation,\n} from '@mintlify/validation';\n\nimport {\n getResolvedSecuritys,\n getResolvedServers,\n withDocumentProperties,\n} from '@/api-playground-2/schemaGraph/getDocumentProperties';\nimport { resolveGraphNode } from '@/api-playground-2/schemaGraph/resolveGraphNode';\nimport type { ApiReferenceDataV2, OperationV2 } from '@/api-playground-2/types';\n\nimport { resolveOperationWithDependencies } from './resolveOperationWithDependencies';\n\nexport const createOperationV2 = ({\n operation,\n target,\n baseUrlOptions,\n}: {\n operation: Operation;\n target: OperationTargetType;\n baseUrlOptions: string[];\n}): OperationV2 => {\n let baseUrl: string | undefined = undefined;\n let baseUrls: string[] = [];\n if (baseUrlOptions.length > 1) {\n baseUrls = baseUrlOptions;\n } else {\n baseUrl = baseUrlOptions[0];\n }\n\n const codeSamples: CodeSample[] = [];\n if (Array.isArray(operation['x-code-samples']) && operation['x-code-samples'].length > 0) {\n operation['x-code-samples'].forEach((codeSample) => {\n if (\n codeSample &&\n typeof codeSample === 'object' &&\n 'source' in codeSample &&\n typeof codeSample['source'] === 'string' &&\n 'lang' in codeSample &&\n typeof codeSample['lang'] === 'string'\n ) {\n codeSamples.push({\n label:\n 'label' in codeSample && typeof codeSample['label'] === 'string'\n ? codeSample['label']\n : undefined,\n lang: codeSample['lang'],\n source: codeSample['source'],\n });\n }\n });\n }\n\n return {\n ...operation,\n path: target.endpoint || '',\n baseUrl,\n baseUrlOptions: baseUrls,\n title: operation.summary ?? '',\n description: operation.description ?? '',\n codeSamples,\n };\n};\n\n// An OpenAPI doc comes to us with a `paths` array. We turn that array into a series of path objects\n// which have a set of `method` keys that map to operation objects.\nexport const getOperationId = (\n graph: SchemaGraphData,\n endpoint: string,\n method: HttpMethod | 'webhook'\n) => {\n const pathUuid = graph.spec.refUuidMap[`${endpoint}/${method}`];\n if (!pathUuid) return undefined;\n\n // pathNode has a shape like:\n // {\n // path: string;\n // [method: HttpMethod]: UUID;\n // }\n const pathNode = resolveGraphNode<PathOrRef>({\n uuidObjectHashMap: graph.spec.uuidObjectHashMap,\n hashedNodeMap: graph.spec.hashedNodeMap,\n id: pathUuid,\n });\n\n // TODO - Api Playground Refactor: I think we assume in the converter that webhooks always have \"post\" as a method\n // technically I they can have multiple/other methods specified?\n const pathNodeOperationObject = method === 'webhook' ? pathNode?.['post'] : pathNode?.[method];\n\n return pathNodeOperationObject;\n};\n\nexport const getSchemaGraphOperationData = ({\n target,\n schemaGraphData,\n}: {\n target: OperationTargetType;\n schemaGraphData: SchemaGraphData;\n}): ApiReferenceDataV2 => {\n const { uuidObjectHashMap, hashedNodeMap } = schemaGraphData.spec;\n\n const operationId = getOperationId(schemaGraphData, target.endpoint, target.method);\n\n if (!operationId) {\n throw new Error(\n `no matching OpenAPI operation found with path \"${target.endpoint}\" and method \"${target.method}\"`\n );\n }\n\n const resolvedData = resolveOperationWithDependencies({\n operationId,\n uuidObjectHashMap,\n hashedNodeMap,\n });\n\n if (!resolvedData) {\n // better error handling?\n return {};\n }\n\n let operation = resolvedData.operation;\n\n // The Operation object doesn't directly contain all the properties we want, so we add a few elsewhere\n // in the spec.\n operation = withDocumentProperties({\n operation,\n schemaGraphData,\n });\n\n const servers = getResolvedServers(schemaGraphData);\n const security = getResolvedSecuritys(schemaGraphData);\n const baseUrlOptions = Object.values(servers).map((server) => server.url);\n\n const operationV2 = createOperationV2({\n operation,\n target,\n baseUrlOptions,\n });\n\n // Then we need to make sure we have dependencies for those new properties.\n const dependenciesWithDocumentDependencies = {\n ...resolvedData.dependencies,\n servers,\n security,\n ...(resolvedData.schemas && { schemas: resolvedData.schemas }),\n };\n\n return {\n operation: operationV2,\n dependencies: dependenciesWithDocumentDependencies,\n };\n};\n"],"names":["createOperationV2","operation","target","baseUrlOptions","baseUrl","baseUrls","codeSamples","codeSample","getOperationId","graph","endpoint","method","pathUuid","pathNode","resolveGraphNode","getSchemaGraphOperationData","schemaGraphData","uuidObjectHashMap","hashedNodeMap","operationId","resolvedData","resolveOperationWithDependencies","withDocumentProperties","servers","getResolvedServers","security","getResolvedSecuritys","server","operationV2","dependenciesWithDocumentDependencies"],"mappings":";;;AAmBO,MAAMA,IAAoB,CAAC;AAAA,EAChC,WAAAC;AAAA,EACA,QAAAC;AAAA,EACA,gBAAAC;AACF,MAImB;AACjB,MAAIC,GACAC,IAAqB,CAAA;AACzB,EAAIF,EAAe,SAAS,IAC1BE,IAAWF,IAEXC,IAAUD,EAAe,CAAC;AAG5B,QAAMG,IAA4B,CAAA;AAClC,SAAI,MAAM,QAAQL,EAAU,gBAAgB,CAAC,KAAKA,EAAU,gBAAgB,EAAE,SAAS,KACrFA,EAAU,gBAAgB,EAAE,QAAQ,CAACM,MAAe;AAClD,IACEA,KACA,OAAOA,KAAe,YACtB,YAAYA,KACZ,OAAOA,EAAW,UAAc,YAChC,UAAUA,KACV,OAAOA,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AA,IACjC,WAAArB;AAAA,IACA,iBAAAe;AAAA,EAAA,CACD;AAED,QAAMO,IAAUC,EAAmBR,CAAe,GAC5CS,IAAWC,EAAqBV,CAAe,GAC/Cb,IAAiB,OAAO,OAAOoB,CAAO,EAAE,IAAI,CAACI,MAAWA,EAAO,GAAG,GAElEC,IAAc5B,EAAkB;AAAA,IACpC,WAAAC;AAAA,IACA,QAAAC;AAAA,IACA,gBAAAC;AAAA,EAAA,CACD,GAGK0B,IAAuC;AAAA,IAC3C,GAAGT,EAAa;AAAA,IAChB,SAAAG;AAAA,IACA,UAAAE;AAAA,IACA,GAAIL,EAAa,WAAW,EAAE,SAASA,EAAa,QAAA;AAAA,EAAQ;AAG9D,SAAO;AAAA,IACL,WAAWQ;AAAA,IACX,cAAcC;AAAA,EAAA;AAElB;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { resolveSchemaWithDependencies as t } from "./resolveSchemaWithDependencies.js";
|
|
2
|
+
function o({
|
|
3
|
+
target: e,
|
|
4
|
+
schemaGraphData: a
|
|
5
|
+
}) {
|
|
6
|
+
return {
|
|
7
|
+
schemaData: t({
|
|
8
|
+
schemaPath: `#/components/schemas/${e.name}`,
|
|
9
|
+
schemaGraphData: a
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
o as getSchemaGraphSchemaData
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=getSchemaGraphSchemaData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSchemaGraphSchemaData.js","sources":["../../../src/api-playground-2/schemaGraph/getSchemaGraphSchemaData.ts"],"sourcesContent":["import type { SchemaTargetType } from '@mintlify/common';\nimport { SchemaGraphData } from '@mintlify/validation';\n\nimport { resolveSchemaWithDependencies } from '@/api-playground-2/schemaGraph/resolveSchemaWithDependencies';\nimport { ApiReferenceDataV2 } from '@/api-playground-2/types';\n\nexport function getSchemaGraphSchemaData({\n target,\n schemaGraphData,\n}: {\n target: SchemaTargetType;\n schemaGraphData: SchemaGraphData;\n}): ApiReferenceDataV2 {\n const resolvedData = resolveSchemaWithDependencies({\n schemaPath: `#/components/schemas/${target.name}`,\n schemaGraphData,\n });\n\n return {\n schemaData: resolvedData,\n };\n}\n"],"names":["getSchemaGraphSchemaData","target","schemaGraphData","resolveSchemaWithDependencies"],"mappings":";AAMO,SAASA,EAAyB;AAAA,EACvC,QAAAC;AAAA,EACA,iBAAAC;AACF,GAGuB;AAMrB,SAAO;AAAA,IACL,YANmBC,EAA8B;AAAA,MACjD,YAAY,wBAAwBF,EAAO,IAAI;AAAA,MAC/C,iBAAAC;AAAA,IAAA,CACD;AAAA,EAGa;AAEhB;"}
|