@scalar/blocks 0.1.16 → 0.1.18
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/CHANGELOG.md +19 -0
- package/dist/code-example/components/CodeExample.vue.d.ts +1 -1
- package/dist/code-example/components/CodeExample.vue.js +1 -1
- package/dist/code-example/components/CodeExample.vue.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue.script.js.map +1 -1
- package/dist/code-example/components/ExamplePicker.vue.d.ts +1 -1
- package/dist/code-example/components/ExamplePicker.vue.js.map +1 -1
- package/dist/code-example/components/ExamplePicker.vue.script.js.map +1 -1
- package/dist/code-example/helpers/generate-client-options.js.map +1 -1
- package/dist/code-example/helpers/generate-code-snippet.d.ts +1 -1
- package/dist/code-example/helpers/generate-code-snippet.js.map +1 -1
- package/dist/code-example/helpers/get-custom-code-samples.d.ts +1 -1
- package/dist/code-example/helpers/get-custom-code-samples.js.map +1 -1
- package/dist/code-example/helpers/get-snippet.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.d.ts +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.js +79 -73
- package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.js +50 -48
- package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-server-url.d.ts +1 -1
- package/dist/code-example/helpers/operation-to-har/process-server-url.js.map +1 -1
- package/dist/code-example/mount.d.ts +1 -1
- package/dist/code-example/mount.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/style.css +19 -3
- package/dist/vue-styles.css +1 -1
- package/package.json +9 -9
|
@@ -1,102 +1,108 @@
|
|
|
1
1
|
import { getResolvedRefDeep as e } from "@scalar/workspace-store/helpers/get-resolved-ref-deep";
|
|
2
|
-
import { getResolvedRef as t } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
3
|
-
import { getExample as
|
|
4
|
-
import { json2xml as
|
|
5
|
-
import {
|
|
6
|
-
import { unpackProxyObject as s } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
2
|
+
import { getResolvedRef as t, mergeSiblingReferences as n } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
3
|
+
import { coerceLeafValueToSchemaType as r, getExample as i, getExampleFromSchema as a, resolveLeafSchema as o, serializeFormPropertyWithEncoding as s, serializeMultipartArray as c } from "@scalar/workspace-store/request-example";
|
|
4
|
+
import { json2xml as l } from "@scalar/helpers/file/json2xml";
|
|
5
|
+
import { unpackProxyObject as u } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
7
6
|
//#region src/code-example/helpers/operation-to-har/process-body.ts
|
|
8
|
-
var
|
|
9
|
-
let
|
|
10
|
-
for (let [
|
|
11
|
-
if (
|
|
12
|
-
let
|
|
13
|
-
if (
|
|
7
|
+
var d = (e, t, n, i = !1, a) => {
|
|
8
|
+
let l = [], f = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
|
|
9
|
+
for (let [p, m] of f) {
|
|
10
|
+
if (m == null) continue;
|
|
11
|
+
let f = n ? void 0 : t?.[p];
|
|
12
|
+
if (i && !n) {
|
|
13
|
+
let t = Array.isArray(e) ? r(m, o(a, [p])) : m, n = c(p, Array.isArray(t) ? t : m, f);
|
|
14
|
+
if (n) {
|
|
15
|
+
for (let e of n) l.push({
|
|
16
|
+
name: e.key,
|
|
17
|
+
value: e.value instanceof File ? `@${e.value.name}` : e.value,
|
|
18
|
+
...e.contentType ? { contentType: e.contentType } : {}
|
|
19
|
+
});
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let h = f && (f.style !== void 0 || f.explode !== void 0 || f.allowReserved !== void 0), g = h || !i ? void 0 : f?.contentType, _ = n ? null : s(p, m, f);
|
|
24
|
+
if (_) for (let e of _) l.push({
|
|
14
25
|
name: e.key,
|
|
15
26
|
value: e.value
|
|
16
27
|
});
|
|
17
|
-
else if (
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
name:
|
|
21
|
-
value: `@${
|
|
22
|
-
...
|
|
28
|
+
else if (m instanceof File) {
|
|
29
|
+
let e = u(m);
|
|
30
|
+
l.push({
|
|
31
|
+
name: p,
|
|
32
|
+
value: `@${e.name}`,
|
|
33
|
+
...g ? { contentType: g } : {}
|
|
23
34
|
});
|
|
24
|
-
} else if (
|
|
25
|
-
name:
|
|
26
|
-
value: JSON.stringify(
|
|
27
|
-
contentType:
|
|
35
|
+
} else if (g && typeof m == "object") l.push({
|
|
36
|
+
name: p,
|
|
37
|
+
value: JSON.stringify(u(m)),
|
|
38
|
+
contentType: g
|
|
28
39
|
});
|
|
29
|
-
else if (
|
|
30
|
-
name:
|
|
31
|
-
value: JSON.stringify(
|
|
40
|
+
else if (i && !n && !h && typeof m == "object" && !Array.isArray(m)) l.push({
|
|
41
|
+
name: p,
|
|
42
|
+
value: JSON.stringify(u(m)),
|
|
32
43
|
contentType: "application/json"
|
|
33
44
|
});
|
|
34
|
-
else if (Array.isArray(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else if (Array.isArray(u)) for (let t of u) if (t instanceof File) {
|
|
40
|
-
let n = s(t);
|
|
41
|
-
a.push({
|
|
42
|
-
name: e,
|
|
43
|
-
value: `@${n.name}`
|
|
45
|
+
else if (Array.isArray(m)) for (let e of m) if (e instanceof File) {
|
|
46
|
+
let t = u(e);
|
|
47
|
+
l.push({
|
|
48
|
+
name: p,
|
|
49
|
+
value: `@${t.name}`
|
|
44
50
|
});
|
|
45
|
-
} else
|
|
46
|
-
name:
|
|
47
|
-
value: String(
|
|
51
|
+
} else l.push({
|
|
52
|
+
name: p,
|
|
53
|
+
value: String(e)
|
|
48
54
|
});
|
|
49
|
-
else if (typeof
|
|
50
|
-
let
|
|
51
|
-
for (let
|
|
52
|
-
name: `${
|
|
53
|
-
value:
|
|
55
|
+
else if (typeof m == "object") {
|
|
56
|
+
let e = d(m, void 0, p);
|
|
57
|
+
for (let t of e) l.push({
|
|
58
|
+
name: `${p}.${t.name}`,
|
|
59
|
+
value: t.value
|
|
54
60
|
});
|
|
55
|
-
} else
|
|
56
|
-
name:
|
|
57
|
-
value: String(
|
|
58
|
-
...
|
|
61
|
+
} else l.push({
|
|
62
|
+
name: p,
|
|
63
|
+
value: String(m),
|
|
64
|
+
...g ? { contentType: g } : {}
|
|
59
65
|
});
|
|
60
66
|
}
|
|
61
|
-
return
|
|
62
|
-
},
|
|
63
|
-
let
|
|
64
|
-
if (
|
|
65
|
-
let e = typeof
|
|
66
|
-
return
|
|
67
|
-
mimeType:
|
|
68
|
-
params:
|
|
69
|
-
} :
|
|
70
|
-
mimeType:
|
|
71
|
-
text:
|
|
67
|
+
return l;
|
|
68
|
+
}, f = ({ requestBody: r, contentType: o, example: s, requestBodyCompositionSelection: c }) => {
|
|
69
|
+
let f = o || Object.keys(r.content)[0] || "", p = f === "other" ? "" : f, m = (e) => `@${u(e).name || "filename"}`, h = r.content[f]?.encoding, g = f === "multipart/form-data" || f === "application/x-www-form-urlencoded", _ = f === "application/xml", v = i(r, s, o)?.value;
|
|
70
|
+
if (v !== void 0) {
|
|
71
|
+
let e = typeof v == "object" && v ? u(v) : v;
|
|
72
|
+
return g && typeof e == "object" && e ? {
|
|
73
|
+
mimeType: p,
|
|
74
|
+
params: d(e, h, void 0, f === "multipart/form-data", t(r.content[f]?.schema, n))
|
|
75
|
+
} : _ && typeof e == "object" && e ? {
|
|
76
|
+
mimeType: p,
|
|
77
|
+
text: l(e)
|
|
72
78
|
} : e instanceof File ? {
|
|
73
|
-
mimeType:
|
|
74
|
-
text:
|
|
79
|
+
mimeType: p,
|
|
80
|
+
text: m(e)
|
|
75
81
|
} : {
|
|
76
|
-
mimeType:
|
|
82
|
+
mimeType: p,
|
|
77
83
|
text: typeof e == "string" ? e : JSON.stringify(e)
|
|
78
84
|
};
|
|
79
85
|
}
|
|
80
|
-
let
|
|
81
|
-
if (
|
|
82
|
-
let t =
|
|
83
|
-
compositionSelection:
|
|
86
|
+
let y = t(r.content[f]?.schema);
|
|
87
|
+
if (y !== void 0) {
|
|
88
|
+
let t = a(e(y), {
|
|
89
|
+
compositionSelection: c,
|
|
84
90
|
mode: "write",
|
|
85
|
-
xml:
|
|
91
|
+
xml: _
|
|
86
92
|
}, { schemaPath: ["requestBody"] });
|
|
87
|
-
if (t !== void 0) return
|
|
88
|
-
mimeType:
|
|
89
|
-
params:
|
|
90
|
-
} :
|
|
91
|
-
mimeType:
|
|
92
|
-
text:
|
|
93
|
+
if (t !== void 0) return g && typeof t == "object" && t ? {
|
|
94
|
+
mimeType: p,
|
|
95
|
+
params: d(t, h, void 0, f === "multipart/form-data")
|
|
96
|
+
} : _ && typeof t == "object" && t ? {
|
|
97
|
+
mimeType: p,
|
|
98
|
+
text: l(t)
|
|
93
99
|
} : {
|
|
94
|
-
mimeType:
|
|
100
|
+
mimeType: p,
|
|
95
101
|
text: typeof t == "string" ? t : JSON.stringify(t)
|
|
96
102
|
};
|
|
97
103
|
}
|
|
98
104
|
};
|
|
99
105
|
//#endregion
|
|
100
|
-
export {
|
|
106
|
+
export { f as processBody };
|
|
101
107
|
|
|
102
108
|
//# sourceMappingURL=process-body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport { isObjectLike } from '@scalar/helpers/object/is-object'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { getResolvedRefDeep } from '@scalar/workspace-store/helpers/get-resolved-ref-deep'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExample,\n getExampleFromSchema,\n serializeFormPropertyWithEncoding,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example' | 'requestBodyCompositionSelection'> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * When only `contentType` is set, the property becomes a single part with that\n * type. Otherwise spec defaults apply (object → `application/json` for multipart,\n * primitives → `text/plain`).\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object/array properties that should become a single `application/json`\n * part. Urlencoded bodies skip those branches and fall through to flattening.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push({\n name: key,\n value: `@${file.name}`,\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (\n Array.isArray(value) &&\n isMultipart &&\n !parentKey &&\n !hasFormStyle &&\n value.some((item) => isObjectLike(item) && !(item instanceof File))\n ) {\n /**\n * Per OpenAPI 3.x: a top-level multipart array whose items are objects defaults to a single\n * `application/json` part containing the whole array. Serializing each item into its own part\n * would drop the enclosing array wrapper and emit a bare object (see issue #9688), so keep the\n * array intact and stringify it as one value.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push({ name: key, value: `@${file.name}` })\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n const isXml = _contentType === 'application/xml'\n\n // Get the example value\n const _example = getExample(requestBody, example, contentType)?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(exampleValue, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(exampleValue),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof exampleValue === 'string' ? exampleValue : JSON.stringify(exampleValue),\n }\n }\n\n // Try to extract examples from the schema\n const contentSchema = getResolvedRef(requestBody.content[_contentType]?.schema)\n if (typeof contentSchema !== 'undefined') {\n const resolvedContentSchema = getResolvedRefDeep(contentSchema) as SchemaObject\n const extractedExample = getExampleFromSchema(\n resolvedContentSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n xml: isXml,\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(extractedExample, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(extractedExample),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;AA8CA,IAAM,KACJ,GACA,GACA,GACA,IAAc,OACF;CACZ,IAAM,IAAkB,CAAC,GAGnB,IAA+B,MAAM,QAAQ,CAAG,IAClD,EAAI,QAAQ,MAAS,CAAC,EAAK,UAAU,CAAC,CAAC,KAAK,MAAS,CAAC,OAAO,EAAK,IAAI,GAAG,EAAK,KAAK,CAAC,IACpF,OAAO,QAAQ,CAAG;CAEtB,KAAK,IAAM,CAAC,GAAK,MAAU,GAAS;EAClC,IAAI,KAAiC,MACnC;EAGF,IAAM,IAAe,IAAY,KAAA,IAAY,IAAW,IAMlD,IACJ,MACC,EAAa,UAAU,KAAA,KACtB,EAAa,YAAY,KAAA,KACzB,EAAa,kBAAkB,KAAA,IAO7B,IAAsB,KAAgB,CAAC,IAAc,KAAA,IAAY,GAAc,aAS/E,IAAc,IAAY,OAAO,EAAkC,GAAK,GAAO,CAAY;EACjG,IAAI,GACF,KAAK,IAAM,KAAS,GAClB,EAAO,KAAK;GAAE,MAAM,EAAM;GAAK,OAAO,EAAM;EAAM,CAAC;OAEhD,IAAI,aAAiB,MAAM;GAKhC,IAAM,IAAO,EAAkB,CAAK;GACpC,EAAO,KAAK;IACV,MAAM;IACN,OAAO,IAAI,EAAK;IAChB,GAAI,IAAsB,EAAE,aAAa,EAAoB,IAAI,CAAC;GACpE,CAAC;EACH,OAAO,IAAI,KAAuB,OAAO,KAAU,UAOjD,EAAO,KAAK;GACV,MAAM;GACN,OAAO,KAAK,UAAU,EAAkB,CAAK,CAAC;GAC9C,aAAa;EACf,CAAC;OACI,IAAI,KAAe,CAAC,KAAa,CAAC,KAAgB,OAAO,KAAU,YAAY,CAAC,MAAM,QAAQ,CAAK,GAMxG,EAAO,KAAK;GACV,MAAM;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a,QAAa;EACnC,IAAM,IAAoC,OAAO,KAAa,YAAzC,IAAoD,EAAkB,CAAQ,IAAI;EAuBvG,OArBI,KAAc,OAAO,KAAiB,YAAY,IAC7C;GACL,UAAU;GACV,QAAQ,EAAmB,GAAc,GAAU,KAAA,GAAW,MAAiB,qBAAqB;EACtG,IAGE,KAAS,OAAO,KAAiB,YAAY,IACxC;GACL,UAAU;GACV,MAAM,EAAS,CAAY;EAC7B,IAGE,aAAwB,OACnB;GACL,UAAU;GACV,MAAM,EAAiB,CAAY;EACrC,IAGK;GACL,UAAU;GACV,MAAM,OAAO,KAAiB,WAAW,IAAe,KAAK,UAAU,CAAY;EACrF;CACF;CAGA,IAAM,IAAgB,EAAe,EAAY,QAAQ,EAAa,EAAE,MAAM;CAC9E,IAAW,MAAkB,QAAa;EAExC,IAAM,IAAmB,EADK,EAAmB,CAE/C,GACA;GACE,sBAAsB;GACtB,MAAM;GACN,KAAK;EACP,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI,MAAqB,KAAA,GAevB,OAdI,KAAc,OAAO,KAAqB,YAAY,IACjD;GACL,UAAU;GACV,QAAQ,EAAmB,GAAkB,GAAU,KAAA,GAAW,MAAiB,qBAAqB;EAC1G,IAGE,KAAS,OAAO,KAAqB,YAAY,IAC5C;GACL,UAAU;GACV,MAAM,EAAS,CAAgB;EACjC,IAGK;GACL,UAAU;GACV,MAAM,OAAO,KAAqB,WAAW,IAAmB,KAAK,UAAU,CAAgB;EACjG;CAEJ;AAGF"}
|
|
1
|
+
{"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { getResolvedRefDeep } from '@scalar/workspace-store/helpers/get-resolved-ref-deep'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromSchema,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example' | 'requestBodyCompositionSelection'> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * Multipart arrays apply the encoding to each item and repeat the property name.\n * Object items default to JSON, and uploaded files retain their filename references.\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object properties and array items. Urlencoded bodies retain their existing\n * serialization and flattening behavior.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n schema?: SchemaObject,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n\n if (isMultipart && !parentKey) {\n const restored = Array.isArray(obj) ? coerceLeafValueToSchemaType(value, resolveLeafSchema(schema, [key])) : value\n const arrayParts = serializeMultipartArray(key, Array.isArray(restored) ? restored : value, partEncoding)\n if (arrayParts) {\n for (const part of arrayParts) {\n params.push({\n name: part.key,\n value: part.value instanceof File ? `@${part.value.name}` : part.value,\n ...(part.contentType ? { contentType: part.contentType } : {}),\n })\n }\n continue\n }\n }\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push({\n name: key,\n value: `@${file.name}`,\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push({ name: key, value: `@${file.name}` })\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n const isXml = _contentType === 'application/xml'\n\n // Get the example value\n const _example = getExample(requestBody, example, contentType)?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n exampleValue,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n getResolvedRef(requestBody.content[_contentType]?.schema, mergeSiblingReferences),\n ),\n }\n }\n\n if (isXml && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(exampleValue),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof exampleValue === 'string' ? exampleValue : JSON.stringify(exampleValue),\n }\n }\n\n // Try to extract examples from the schema\n const contentSchema = getResolvedRef(requestBody.content[_contentType]?.schema)\n if (typeof contentSchema !== 'undefined') {\n const resolvedContentSchema = getResolvedRefDeep(contentSchema) as SchemaObject\n const extractedExample = getExampleFromSchema(\n resolvedContentSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n xml: isXml,\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(extractedExample, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(extractedExample),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;AA+CA,IAAM,KACJ,GACA,GACA,GACA,IAAc,IACd,MACY;CACZ,IAAM,IAAkB,CAAC,GAGnB,IAA+B,MAAM,QAAQ,CAAG,IAClD,EAAI,QAAQ,MAAS,CAAC,EAAK,UAAU,CAAC,CAAC,KAAK,MAAS,CAAC,OAAO,EAAK,IAAI,GAAG,EAAK,KAAK,CAAC,IACpF,OAAO,QAAQ,CAAG;CAEtB,KAAK,IAAM,CAAC,GAAK,MAAU,GAAS;EAClC,IAAI,KAAiC,MACnC;EAGF,IAAM,IAAe,IAAY,KAAA,IAAY,IAAW;EAExD,IAAI,KAAe,CAAC,GAAW;GAC7B,IAAM,IAAW,MAAM,QAAQ,CAAG,IAAI,EAA4B,GAAO,EAAkB,GAAQ,CAAC,CAAG,CAAC,CAAC,IAAI,GACvG,IAAa,EAAwB,GAAK,MAAM,QAAQ,CAAQ,IAAI,IAAW,GAAO,CAAY;GACxG,IAAI,GAAY;IACd,KAAK,IAAM,KAAQ,GACjB,EAAO,KAAK;KACV,MAAM,EAAK;KACX,OAAO,EAAK,iBAAiB,OAAO,IAAI,EAAK,MAAM,SAAS,EAAK;KACjE,GAAI,EAAK,cAAc,EAAE,aAAa,EAAK,YAAY,IAAI,CAAC;IAC9D,CAAC;IAEH;GACF;EACF;EAMA,IAAM,IACJ,MACC,EAAa,UAAU,KAAA,KACtB,EAAa,YAAY,KAAA,KACzB,EAAa,kBAAkB,KAAA,IAO7B,IAAsB,KAAgB,CAAC,IAAc,KAAA,IAAY,GAAc,aAS/E,IAAc,IAAY,OAAO,EAAkC,GAAK,GAAO,CAAY;EACjG,IAAI,GACF,KAAK,IAAM,KAAS,GAClB,EAAO,KAAK;GAAE,MAAM,EAAM;GAAK,OAAO,EAAM;EAAM,CAAC;OAEhD,IAAI,aAAiB,MAAM;GAKhC,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as/v3.
|
|
1
|
+
import type { OperationObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
2
|
import type { Request as HarRequest } from 'har-format';
|
|
3
3
|
type ProcessedParameters = {
|
|
4
4
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,8DAA8D,CAAA;AACpH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;IACtC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;CAC/B,CAAA;AAiGD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,uDAK/B;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,CAAA;IACzC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,gDAAgD;IAChD,eAAe,EAAE,OAAO,CAAA;CACzB,KAAG,mBAyIH,CAAA"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getResolvedRef as e } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
2
|
import { deSerializeParameter as t, getExample as n, getExampleFromSchema as r, isParamDisabled as i, serializeContentValue as a, serializeDeepObjectStyle as o, serializeFormStyle as s, serializeFormStyleForCookies as c, serializePipeDelimitedStyle as l, serializeSimpleStyle as u, serializeSpaceDelimitedStyle as d } from "@scalar/workspace-store/request-example";
|
|
3
|
+
import { isObjectLike as f } from "@scalar/helpers/object/is-object";
|
|
3
4
|
//#region src/code-example/helpers/operation-to-har/process-parameters.ts
|
|
4
|
-
var
|
|
5
|
+
var p = (t) => (t ?? []).map((t) => e(t)).filter((e) => e !== void 0), m = (e) => "allowReserved" in e && e.allowReserved !== void 0 ? e.allowReserved : "schema" in e && e.schema && typeof e.schema == "object" && "allowReserved" in e.schema ? e.schema.allowReserved === !0 : !1, h = (e, t) => m(t) ? e : encodeURIComponent(e), g = (e) => {
|
|
5
6
|
if (e.in === "header") return {
|
|
6
7
|
style: "simple",
|
|
7
8
|
explode: "explode" in e && e.explode !== void 0 && e.explode
|
|
@@ -15,100 +16,101 @@ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.
|
|
|
15
16
|
query: "form",
|
|
16
17
|
header: "simple",
|
|
17
18
|
cookie: "form"
|
|
18
|
-
}[e.in], n = "style" in e && e.style ? e.style : t;
|
|
19
|
+
}[e.in] ?? "form", n = "style" in e && e.style ? e.style : t;
|
|
19
20
|
return {
|
|
20
21
|
style: n,
|
|
21
22
|
explode: "explode" in e && e.explode !== void 0 ? e.explode : n === "form"
|
|
22
23
|
};
|
|
23
|
-
},
|
|
24
|
+
}, _ = (a, o, s, c) => {
|
|
24
25
|
let l = n(a, o, s);
|
|
25
26
|
if (i(a, l, c)) return;
|
|
26
27
|
if (l?.value !== void 0) return t(l.value, a);
|
|
27
28
|
if (!("schema" in a) || !a.schema) return;
|
|
28
|
-
let u = a.in === "path" ? { emptyString: `{${a.name}}` } : {};
|
|
29
|
-
return r(
|
|
30
|
-
},
|
|
31
|
-
let i = [...e.headers],
|
|
32
|
-
for (let t of
|
|
29
|
+
let u = a.in === "path" ? { emptyString: `{${a.name}}` } : {}, d = e(a.schema);
|
|
30
|
+
return d ? r(d, u) : void 0;
|
|
31
|
+
}, v = ({ harRequest: e, parameters: t, example: n, defaultDisabled: r }) => {
|
|
32
|
+
let i = [...e.headers], f = [...e.queryString], m = e.url, v = p(t);
|
|
33
|
+
for (let t of v) {
|
|
33
34
|
if (!t.in || !t.name) continue;
|
|
34
|
-
let
|
|
35
|
-
if (
|
|
36
|
-
let { style:
|
|
35
|
+
let p = _(t, n, void 0, r);
|
|
36
|
+
if (p === void 0) continue;
|
|
37
|
+
let { style: v, explode: b } = g(t);
|
|
37
38
|
switch (t.in) {
|
|
38
39
|
case "path":
|
|
39
|
-
|
|
40
|
+
m = y(m, t, p, v, b);
|
|
40
41
|
break;
|
|
41
42
|
case "query":
|
|
43
|
+
case "querystring":
|
|
42
44
|
if ("content" in t && t.content) {
|
|
43
|
-
let e = a(
|
|
44
|
-
|
|
45
|
+
let e = a(p, Object.keys(t.content)[0] ?? "application/json");
|
|
46
|
+
f.push({
|
|
45
47
|
name: t.name,
|
|
46
|
-
value:
|
|
48
|
+
value: h(e, t)
|
|
47
49
|
});
|
|
48
50
|
break;
|
|
49
51
|
}
|
|
50
|
-
switch (
|
|
52
|
+
switch (v) {
|
|
51
53
|
case "form": {
|
|
52
|
-
let e = s(
|
|
54
|
+
let e = s(p, b);
|
|
53
55
|
if (Array.isArray(e)) for (let n of e) {
|
|
54
56
|
let e = n.key || t.name;
|
|
55
|
-
|
|
57
|
+
f.push({
|
|
56
58
|
name: e,
|
|
57
|
-
value:
|
|
59
|
+
value: h(String(n.value), t)
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
|
-
else
|
|
62
|
+
else f.push({
|
|
61
63
|
name: t.name,
|
|
62
|
-
value:
|
|
64
|
+
value: h(String(e), t)
|
|
63
65
|
});
|
|
64
66
|
break;
|
|
65
67
|
}
|
|
66
68
|
case "spaceDelimited": {
|
|
67
|
-
let e = d(
|
|
68
|
-
|
|
69
|
+
let e = d(p);
|
|
70
|
+
f.push({
|
|
69
71
|
name: t.name,
|
|
70
|
-
value:
|
|
72
|
+
value: h(e, t)
|
|
71
73
|
});
|
|
72
74
|
break;
|
|
73
75
|
}
|
|
74
76
|
case "pipeDelimited": {
|
|
75
|
-
let e = l(
|
|
76
|
-
|
|
77
|
+
let e = l(p);
|
|
78
|
+
f.push({
|
|
77
79
|
name: t.name,
|
|
78
|
-
value:
|
|
80
|
+
value: h(e, t)
|
|
79
81
|
});
|
|
80
82
|
break;
|
|
81
83
|
}
|
|
82
84
|
case "deepObject":
|
|
83
|
-
if (Array.isArray(
|
|
84
|
-
let e = s(
|
|
85
|
+
if (Array.isArray(p)) {
|
|
86
|
+
let e = s(p, !0);
|
|
85
87
|
if (Array.isArray(e)) for (let n of e) {
|
|
86
88
|
let e = n.key || t.name;
|
|
87
|
-
|
|
89
|
+
f.push({
|
|
88
90
|
name: e,
|
|
89
|
-
value:
|
|
91
|
+
value: h(String(n.value), t)
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
|
-
else
|
|
94
|
+
else f.push({
|
|
93
95
|
name: t.name,
|
|
94
|
-
value:
|
|
96
|
+
value: h(String(e), t)
|
|
95
97
|
});
|
|
96
98
|
} else {
|
|
97
|
-
let e = o(t.name,
|
|
98
|
-
for (let n of e)
|
|
99
|
+
let e = o(t.name, p);
|
|
100
|
+
for (let n of e) f.push({
|
|
99
101
|
name: n.key,
|
|
100
|
-
value:
|
|
102
|
+
value: h(n.value, t)
|
|
101
103
|
});
|
|
102
104
|
}
|
|
103
105
|
break;
|
|
104
|
-
default:
|
|
106
|
+
default: f.push({
|
|
105
107
|
name: t.name,
|
|
106
|
-
value:
|
|
108
|
+
value: h(String(p), t)
|
|
107
109
|
});
|
|
108
110
|
}
|
|
109
111
|
break;
|
|
110
112
|
case "header": {
|
|
111
|
-
let e = u(
|
|
113
|
+
let e = u(p, b);
|
|
112
114
|
i.push({
|
|
113
115
|
name: t.name,
|
|
114
116
|
value: String(e)
|
|
@@ -116,7 +118,7 @@ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.
|
|
|
116
118
|
break;
|
|
117
119
|
}
|
|
118
120
|
case "cookie": {
|
|
119
|
-
let n = c(
|
|
121
|
+
let n = c(p, b);
|
|
120
122
|
if (Array.isArray(n)) for (let r of n) {
|
|
121
123
|
let n = r.key || t.name, i = r.value === null ? "null" : String(r.value);
|
|
122
124
|
e.cookies.push({
|
|
@@ -136,12 +138,12 @@ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.
|
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
return {
|
|
139
|
-
url:
|
|
141
|
+
url: m,
|
|
140
142
|
headers: i,
|
|
141
|
-
queryString:
|
|
143
|
+
queryString: f,
|
|
142
144
|
cookies: e.cookies
|
|
143
145
|
};
|
|
144
|
-
},
|
|
146
|
+
}, y = (e, t, n, r, i) => {
|
|
145
147
|
switch (r) {
|
|
146
148
|
case "matrix":
|
|
147
149
|
if (i) {
|
|
@@ -149,14 +151,14 @@ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.
|
|
|
149
151
|
let r = n.map((e) => `${t.name}=${e}`).join(";");
|
|
150
152
|
return e.replace(`{;${t.name}}`, `;${r}`);
|
|
151
153
|
}
|
|
152
|
-
if (
|
|
154
|
+
if (f(n)) {
|
|
153
155
|
let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(";");
|
|
154
156
|
return e.replace(`{;${t.name}}`, `;${r}`);
|
|
155
157
|
}
|
|
156
158
|
return e.replace(`{;${t.name}}`, `;${t.name}=${n}`);
|
|
157
159
|
}
|
|
158
160
|
if (Array.isArray(n)) return e.replace(`{;${t.name}}`, `;${t.name}=${n.join(",")}`);
|
|
159
|
-
if (
|
|
161
|
+
if (f(n)) {
|
|
160
162
|
let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
|
|
161
163
|
return e.replace(`{;${t.name}}`, `;${t.name}=${r}`);
|
|
162
164
|
}
|
|
@@ -164,14 +166,14 @@ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.
|
|
|
164
166
|
case "label":
|
|
165
167
|
if (i) {
|
|
166
168
|
if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(".")}`);
|
|
167
|
-
if (
|
|
169
|
+
if (f(n)) {
|
|
168
170
|
let r = Object.entries(n).map(([e, t]) => `${e}=${t}`).join(".");
|
|
169
171
|
return e.replace(`{.${t.name}}`, `.${r}`);
|
|
170
172
|
}
|
|
171
173
|
return e.replace(`{.${t.name}}`, `.${n}`);
|
|
172
174
|
}
|
|
173
175
|
if (Array.isArray(n)) return e.replace(`{.${t.name}}`, `.${n.join(",")}`);
|
|
174
|
-
if (
|
|
176
|
+
if (f(n)) {
|
|
175
177
|
let r = Object.entries(n).map(([e, t]) => `${e},${t}`).join(",");
|
|
176
178
|
return e.replace(`{.${t.name}}`, `.${r}`);
|
|
177
179
|
}
|
|
@@ -184,6 +186,6 @@ var f = (t) => (t ?? []).map((t) => e(t)), p = (e) => "allowReserved" in e && e.
|
|
|
184
186
|
}
|
|
185
187
|
};
|
|
186
188
|
//#endregion
|
|
187
|
-
export {
|
|
189
|
+
export { v as processParameters };
|
|
188
190
|
|
|
189
191
|
//# sourceMappingURL=process-parameters.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-parameters.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"sourcesContent":["import { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n deSerializeParameter,\n getExample,\n getExampleFromSchema,\n isParamDisabled,\n serializeContentValue,\n serializeDeepObjectStyle,\n serializeFormStyle,\n serializeFormStyleForCookies,\n serializePipeDelimitedStyle,\n serializeSimpleStyle,\n serializeSpaceDelimitedStyle,\n} from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ParameterObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\ntype ProcessedParameters = {\n url: string\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n}\n\n/** Ensures we don't have any references in the parameters */\nconst deReferenceParams = (params: OperationObject['parameters']): ParameterObject[] =>\n (params ?? []).map((param) => getResolvedRef(param))\n\n/** Whether the parameter allows reserved characters (from param or schema). */\nconst isAllowReserved = (param: ParameterObject): boolean => {\n if ('allowReserved' in param && param.allowReserved !== undefined) {\n return param.allowReserved\n }\n if ('schema' in param && param.schema && typeof param.schema === 'object' && 'allowReserved' in param.schema) {\n return (param.schema as { allowReserved?: boolean }).allowReserved === true\n }\n return false\n}\n\n/** URL encode a value if allowReserved is not set to true. */\nconst encodeQueryValue = (value: string, param: ParameterObject): string => {\n if (isAllowReserved(param)) {\n return value\n }\n return encodeURIComponent(value)\n}\n\n/**\n * Get the style and explode values for a parameter according to OpenAPI 3.1.1 specification.\n * Handles defaults and validation for parameter location restrictions.\n */\nconst getParameterStyleAndExplode = (param: ParameterObject): { style: string; explode: boolean } => {\n // Headers only support 'simple' style\n if (param.in === 'header') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : false\n return { style: 'simple', explode }\n }\n\n // Cookies only support 'form' style\n if (param.in === 'cookie') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : true\n return { style: 'form', explode }\n }\n\n const defaultStyle = {\n path: 'simple',\n query: 'form',\n header: 'simple',\n cookie: 'form',\n }[param.in]\n\n // Use provided style or default based on location\n const style = 'style' in param && param.style ? param.style : defaultStyle\n\n // Determine explode value: use provided value or default based on style\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : style === 'form'\n\n return { style, explode }\n}\n\n/**\n * Extract the value for a parameter from example data or schema.\n * Prioritizes example data over schema examples.\n * Returns null if the parameter is disabled so we can skip it.\n */\nconst getParameterValue = (\n param: ParameterObject,\n example: string | undefined,\n contentType: string | undefined,\n defaultDisabled: boolean,\n): unknown => {\n // Try to get value from example first\n const exampleValue = getExample(param, example, contentType)\n\n // If the parameter is disabled, return undefined so we can skip it.\n if (isParamDisabled(param, exampleValue, defaultDisabled)) {\n return undefined\n }\n\n // If the example value is set, return it.\n if (exampleValue?.value !== undefined) {\n return deSerializeParameter(exampleValue.value, param)\n }\n\n // Fall back to schema example if available\n if (!('schema' in param) || !param.schema) {\n return undefined\n }\n\n const options = param.in === 'path' ? { emptyString: `{${param.name}}` } : {}\n return getExampleFromSchema(getResolvedRef(param.schema), options)\n}\n\n/**\n * Process OpenAPI parameters and return the updated properties.\n * Handles path, query, and header parameters with various styles and explode options.\n *\n * @see https://spec.openapis.org/oas/latest.html#style-values\n */\nexport const processParameters = ({\n harRequest,\n parameters,\n example,\n defaultDisabled,\n}: {\n harRequest: HarRequest\n parameters: OperationObject['parameters']\n /** The name of the example to use */\n example?: string | undefined\n /** Whether to disable parameters by default. */\n defaultDisabled: boolean\n}): ProcessedParameters => {\n // Create copies of the arrays to avoid modifying the input\n const newHeaders = [...harRequest.headers]\n const newQueryString = [...harRequest.queryString]\n let newUrl = harRequest.url\n\n // Filter out references\n const deReferencedParams = deReferenceParams(parameters)\n\n for (const param of deReferencedParams) {\n if (!param.in || !param.name) {\n continue\n }\n\n const paramValue = getParameterValue(param, example, undefined, defaultDisabled)\n if (paramValue === undefined) {\n continue\n }\n\n const { style, explode } = getParameterStyleAndExplode(param)\n\n switch (param.in) {\n case 'path': {\n newUrl = processPathParameters(newUrl, param, paramValue, style, explode)\n break\n }\n\n case 'query': {\n // Content type parameters should be serialized according to the parameter's own content type\n if ('content' in param && param.content) {\n // We grab the first for now but eventually we should support selecting the content type per parameter\n const paramContentType = Object.keys(param.content)[0] ?? 'application/json'\n const serializedValue = serializeContentValue(paramValue, paramContentType)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serializedValue, param) })\n break\n }\n\n // Handle query parameters\n switch (style) {\n case 'form': {\n const serialized = serializeFormStyle(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n newQueryString.push({ name: key, value: encodeQueryValue(String(entry.value), param) })\n }\n }\n // Otherwise, convert to string\n else {\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(serialized), param) })\n }\n break\n }\n case 'spaceDelimited': {\n const serialized = serializeSpaceDelimitedStyle(paramValue)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serialized, param) })\n break\n }\n case 'pipeDelimited': {\n const serialized = serializePipeDelimitedStyle(paramValue)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serialized, param) })\n break\n }\n case 'deepObject': {\n // OAS marks deepObject-on-array and deepObject+explode:false as undefined.\n // Mirror process-body: fall back to form/explode:true for arrays and always\n // invoke the serializer for objects so authors get useful output instead of\n // a silently-dropped parameter.\n if (Array.isArray(paramValue)) {\n const serialized = serializeFormStyle(paramValue, true)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n newQueryString.push({ name: key, value: encodeQueryValue(String(entry.value), param) })\n }\n } else {\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(serialized), param) })\n }\n } else {\n const entries = serializeDeepObjectStyle(param.name, paramValue)\n for (const entry of entries) {\n newQueryString.push({ name: entry.key, value: encodeQueryValue(entry.value, param) })\n }\n }\n break\n }\n\n // Default to form style\n default:\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(paramValue), param) })\n }\n break\n }\n\n // Headers only support 'simple' style according to OpenAPI 3.1.1\n // For arrays, simple style always produces comma-separated values regardless of explode\n // The explode parameter only affects object serialization\n case 'header': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n newHeaders.push({ name: param.name, value: String(serialized) })\n break\n }\n\n // Cookies only support 'form' style according to OpenAPI 3.1.1\n case 'cookie': {\n const serialized = serializeFormStyleForCookies(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n const value = entry.value === null ? 'null' : String(entry.value)\n harRequest.cookies.push({ name: key, value })\n }\n }\n // Otherwise, convert to string\n else {\n const value = serialized === null ? 'null' : String(serialized)\n harRequest.cookies.push({ name: param.name, value })\n }\n break\n }\n }\n }\n\n return {\n url: newUrl,\n headers: newHeaders,\n queryString: newQueryString,\n cookies: harRequest.cookies,\n }\n}\n\n/**\n * Process path parameters according to OpenAPI specification.\n * Handles matrix, label, and simple styles with explode options.\n *\n * @param url - The URL to process\n * @param param - The parameter object\n * @param paramValue - The value of the parameter\n * @param style - The style of the parameter (matrix, label, simple)\n * @param explode - Whether to explode the parameter\n * @returns The updated URL with processed path parameters\n */\nconst processPathParameters = (\n url: string,\n param: ParameterObject,\n paramValue: unknown,\n style: string,\n explode: boolean,\n): string => {\n switch (style) {\n case 'matrix': {\n if (explode) {\n // Matrix explode array: ;color=blue;color=black;color=brown\n if (Array.isArray(paramValue)) {\n const values = (paramValue as unknown[]).map((v) => `${param.name}=${v}`).join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode object: ;R=100;G=200;B=150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k}=${v}`)\n .join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n\n // Matrix no explode array: ;color=blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{;${param.name}}`, `;${param.name}=${(paramValue as unknown[]).join(',')}`)\n }\n\n // Matrix no explode object: ;color=R,100,G,200,B,150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n return url.replace(`{;${param.name}}`, `;${param.name}=${values}`)\n }\n\n // Matrix no explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n case 'label': {\n if (explode) {\n // Label explode array: .blue.black.brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${(paramValue as unknown[]).join('.')}`)\n }\n\n // Label explode object: .R=100.G=200.B=150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n // Label no explode array: .blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${(paramValue as unknown[]).join(',')}`)\n }\n\n // Label no explode object: .R,100,G,200,B,150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label no explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n case 'simple': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n return url.replace(`{${param.name}}`, String(serialized))\n }\n\n // Default to simple style\n default:\n return url.replace(`{${param.name}}`, String(paramValue))\n }\n}\n"],"mappings":";;;AAyBA,IAAM,KAAqB,OACxB,KAAU,CAAC,EAAA,CAAG,KAAK,MAAU,EAAe,CAAK,CAAC,GAG/C,KAAmB,MACnB,mBAAmB,KAAS,EAAM,kBAAkB,KAAA,IAC/C,EAAM,gBAEX,YAAY,KAAS,EAAM,UAAU,OAAO,EAAM,UAAW,YAAY,mBAAmB,EAAM,SAC5F,EAAM,OAAuC,kBAAkB,KAElE,IAIH,KAAoB,GAAe,MACnC,EAAgB,CAAK,IAChB,IAEF,mBAAmB,CAAK,GAO3B,KAA+B,MAAgE;CAEnG,IAAI,EAAM,OAAO,UAEf,OAAO;EAAE,OAAO;EAAU,SADV,aAAa,KAAS,EAAM,YAAY,KAAA,KAAY,EAAM;CACxC;CAIpC,IAAI,EAAM,OAAO,UAEf,OAAO;EAAE,OAAO;EAAQ,SADR,aAAa,KAAS,EAAM,YAAY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AqB;IACzD,IAAM,IAAS,OAAO,QAAQ,CAAqC,CAAC,CACjE,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,GAAG,CAAC,CAC5B,KAAK,GAAG;IAEX,OAAO,EAAI,QAAQ,KAAK,EAAM,KAAK,IAAI,IAAI,GAAQ;GACrD;GAGA,OAAO,EAAI,QAAQ,KAAK,EAAM,KAAK,IAAI,IAAI,GAAY;EAGzD,KAAK,UAAU;GACb,IAAM,IAAa,EAAqB,GAAY,CAAO;GAC3D,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;EAC1D;EAGA,SACE,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;CAC5D;AACF"}
|
|
1
|
+
{"version":3,"file":"process-parameters.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"sourcesContent":["import { isObjectLike } from '@scalar/helpers/object/is-object'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n deSerializeParameter,\n getExample,\n getExampleFromSchema,\n isParamDisabled,\n serializeContentValue,\n serializeDeepObjectStyle,\n serializeFormStyle,\n serializeFormStyleForCookies,\n serializePipeDelimitedStyle,\n serializeSimpleStyle,\n serializeSpaceDelimitedStyle,\n} from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ParameterObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\ntype ProcessedParameters = {\n url: string\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n}\n\n/** Ensures we don't have any references in the parameters */\nconst deReferenceParams = (params: OperationObject['parameters']): ParameterObject[] =>\n (params ?? []).map((param) => getResolvedRef(param)).filter((param) => param !== undefined)\n\n/** Whether the parameter allows reserved characters (from param or schema). */\nconst isAllowReserved = (param: ParameterObject): boolean => {\n if ('allowReserved' in param && param.allowReserved !== undefined) {\n return param.allowReserved\n }\n if ('schema' in param && param.schema && typeof param.schema === 'object' && 'allowReserved' in param.schema) {\n return (param.schema as { allowReserved?: boolean }).allowReserved === true\n }\n return false\n}\n\n/** URL encode a value if allowReserved is not set to true. */\nconst encodeQueryValue = (value: string, param: ParameterObject): string => {\n if (isAllowReserved(param)) {\n return value\n }\n return encodeURIComponent(value)\n}\n\n/**\n * Get the style and explode values for a parameter according to OpenAPI 3.1.1 specification.\n * Handles defaults and validation for parameter location restrictions.\n */\nconst getParameterStyleAndExplode = (param: ParameterObject): { style: string; explode: boolean } => {\n // Headers only support 'simple' style\n if (param.in === 'header') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : false\n return { style: 'simple', explode }\n }\n\n // Cookies only support 'form' style\n if (param.in === 'cookie') {\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : true\n return { style: 'form', explode }\n }\n\n // The 3.2 `querystring` location has no style/explode of its own, so it falls through to the\n // `form` default here and is then serialized like a regular query parameter (see the switch below).\n const defaultStyle =\n (\n {\n path: 'simple',\n query: 'form',\n header: 'simple',\n cookie: 'form',\n } as Record<string, string>\n )[param.in] ?? 'form'\n\n // Use provided style or default based on location\n const style = 'style' in param && param.style ? param.style : defaultStyle\n\n // Determine explode value: use provided value or default based on style\n const explode = 'explode' in param && param.explode !== undefined ? param.explode : style === 'form'\n\n return { style, explode }\n}\n\n/**\n * Extract the value for a parameter from example data or schema.\n * Prioritizes example data over schema examples.\n * Returns null if the parameter is disabled so we can skip it.\n */\nconst getParameterValue = (\n param: ParameterObject,\n example: string | undefined,\n contentType: string | undefined,\n defaultDisabled: boolean,\n): unknown => {\n // Try to get value from example first\n const exampleValue = getExample(param, example, contentType)\n\n // If the parameter is disabled, return undefined so we can skip it.\n if (isParamDisabled(param, exampleValue, defaultDisabled)) {\n return undefined\n }\n\n // If the example value is set, return it.\n if (exampleValue?.value !== undefined) {\n return deSerializeParameter(exampleValue.value, param)\n }\n\n // Fall back to schema example if available\n if (!('schema' in param) || !param.schema) {\n return undefined\n }\n\n const options = param.in === 'path' ? { emptyString: `{${param.name}}` } : {}\n const schema = getResolvedRef(param.schema)\n return schema ? getExampleFromSchema(schema, options) : undefined\n}\n\n/**\n * Process OpenAPI parameters and return the updated properties.\n * Handles path, query, and header parameters with various styles and explode options.\n *\n * @see https://spec.openapis.org/oas/latest.html#style-values\n */\nexport const processParameters = ({\n harRequest,\n parameters,\n example,\n defaultDisabled,\n}: {\n harRequest: HarRequest\n parameters: OperationObject['parameters']\n /** The name of the example to use */\n example?: string | undefined\n /** Whether to disable parameters by default. */\n defaultDisabled: boolean\n}): ProcessedParameters => {\n // Create copies of the arrays to avoid modifying the input\n const newHeaders = [...harRequest.headers]\n const newQueryString = [...harRequest.queryString]\n let newUrl = harRequest.url\n\n // Filter out references\n const deReferencedParams = deReferenceParams(parameters)\n\n for (const param of deReferencedParams) {\n if (!param.in || !param.name) {\n continue\n }\n\n const paramValue = getParameterValue(param, example, undefined, defaultDisabled)\n if (paramValue === undefined) {\n continue\n }\n\n const { style, explode } = getParameterStyleAndExplode(param)\n\n switch (param.in) {\n case 'path': {\n newUrl = processPathParameters(newUrl, param, paramValue, style, explode)\n break\n }\n\n // The 3.2 `querystring` location represents the whole query string. Handle it like a\n // regular query parameter so its value still lands in the query string instead of\n // being silently dropped.\n case 'query':\n case 'querystring': {\n // Content type parameters should be serialized according to the parameter's own content type\n if ('content' in param && param.content) {\n // We grab the first for now but eventually we should support selecting the content type per parameter\n const paramContentType = Object.keys(param.content)[0] ?? 'application/json'\n const serializedValue = serializeContentValue(paramValue, paramContentType)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serializedValue, param) })\n break\n }\n\n // Handle query parameters\n switch (style) {\n case 'form': {\n const serialized = serializeFormStyle(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n newQueryString.push({ name: key, value: encodeQueryValue(String(entry.value), param) })\n }\n }\n // Otherwise, convert to string\n else {\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(serialized), param) })\n }\n break\n }\n case 'spaceDelimited': {\n const serialized = serializeSpaceDelimitedStyle(paramValue)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serialized, param) })\n break\n }\n case 'pipeDelimited': {\n const serialized = serializePipeDelimitedStyle(paramValue)\n newQueryString.push({ name: param.name, value: encodeQueryValue(serialized, param) })\n break\n }\n case 'deepObject': {\n // OAS marks deepObject-on-array and deepObject+explode:false as undefined.\n // Mirror process-body: fall back to form/explode:true for arrays and always\n // invoke the serializer for objects so authors get useful output instead of\n // a silently-dropped parameter.\n if (Array.isArray(paramValue)) {\n const serialized = serializeFormStyle(paramValue, true)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n newQueryString.push({ name: key, value: encodeQueryValue(String(entry.value), param) })\n }\n } else {\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(serialized), param) })\n }\n } else {\n const entries = serializeDeepObjectStyle(param.name, paramValue)\n for (const entry of entries) {\n newQueryString.push({ name: entry.key, value: encodeQueryValue(entry.value, param) })\n }\n }\n break\n }\n\n // Default to form style\n default:\n newQueryString.push({ name: param.name, value: encodeQueryValue(String(paramValue), param) })\n }\n break\n }\n\n // Headers only support 'simple' style according to OpenAPI 3.1.1\n // For arrays, simple style always produces comma-separated values regardless of explode\n // The explode parameter only affects object serialization\n case 'header': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n newHeaders.push({ name: param.name, value: String(serialized) })\n break\n }\n\n // Cookies only support 'form' style according to OpenAPI 3.1.1\n case 'cookie': {\n const serialized = serializeFormStyleForCookies(paramValue, explode)\n\n // If serialized is an array of key-value pairs (exploded object or array)\n if (Array.isArray(serialized)) {\n for (const entry of serialized) {\n const key = entry.key || param.name\n const value = entry.value === null ? 'null' : String(entry.value)\n harRequest.cookies.push({ name: key, value })\n }\n }\n // Otherwise, convert to string\n else {\n const value = serialized === null ? 'null' : String(serialized)\n harRequest.cookies.push({ name: param.name, value })\n }\n break\n }\n }\n }\n\n return {\n url: newUrl,\n headers: newHeaders,\n queryString: newQueryString,\n cookies: harRequest.cookies,\n }\n}\n\n/**\n * Process path parameters according to OpenAPI specification.\n * Handles matrix, label, and simple styles with explode options.\n *\n * @param url - The URL to process\n * @param param - The parameter object\n * @param paramValue - The value of the parameter\n * @param style - The style of the parameter (matrix, label, simple)\n * @param explode - Whether to explode the parameter\n * @returns The updated URL with processed path parameters\n */\nconst processPathParameters = (\n url: string,\n param: ParameterObject,\n paramValue: unknown,\n style: string,\n explode: boolean,\n): string => {\n switch (style) {\n case 'matrix': {\n if (explode) {\n // Matrix explode array: ;color=blue;color=black;color=brown\n if (Array.isArray(paramValue)) {\n const values = paramValue.map((v: unknown) => `${param.name}=${v}`).join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode object: ;R=100;G=200;B=150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k}=${v}`)\n .join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n\n // Matrix no explode array: ;color=blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue.join(',')}`)\n }\n\n // Matrix no explode object: ;color=R,100,G,200,B,150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n return url.replace(`{;${param.name}}`, `;${param.name}=${values}`)\n }\n\n // Matrix no explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n case 'label': {\n if (explode) {\n // Label explode array: .blue.black.brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${paramValue.join('.')}`)\n }\n\n // Label explode object: .R=100.G=200.B=150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n // Label no explode array: .blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${paramValue.join(',')}`)\n }\n\n // Label no explode object: .R,100,G,200,B,150\n if (isObjectLike(paramValue)) {\n const values = Object.entries(paramValue)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label no explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n case 'simple': {\n const serialized = serializeSimpleStyle(paramValue, explode)\n return url.replace(`{${param.name}}`, String(serialized))\n }\n\n // Default to simple style\n default:\n return url.replace(`{${param.name}}`, String(paramValue))\n }\n}\n"],"mappings":";;;;AA0BA,IAAM,KAAqB,OACxB,KAAU,CAAC,EAAA,CAAG,KAAK,MAAU,EAAe,CAAK,CAAC,CAAC,CAAC,QAAQ,MAAU,MAAU,KAAA,CAAS,GAGtF,KAAmB,MACnB,mBAAmB,KAAS,EAAM,kBAAkB,KAAA,IAC/C,EAAM,gBAEX,YAAY,KAAS,EAAM,UAAU,OAAO,EAAM,UAAW,YAAY,mBAAmB,EAAM,SAC5F,EAAM,OAAuC,kBAAkB,KAElE,IAIH,KAAoB,GAAe,MACnC,EAAgB,CAAK,IAChB,IAEF,mBAAmB,CAAK,GAO3B,KAA+B,MAAgE;CAEnG,IAAI,EAAM,OAAO,UAEf,OAAO;EAAE,OAAO;EAAU,SADV,aAAa,KAAS,EAAM,YAAY,KAAA,KAAY,EAAM;CACxC;CAIpC,IAAI,EAAM,OAAO,UAEf,OAAO;EAAE,OAAO;EAAQ,SADR,aAAa,KAAS,EAAM,YAAY,KAAA,IAAY,EAAM,UAAU;CACpD;CAKlC,IAAM,IAEF;EACE,MAAM;EACN,OAAO;EACP,Q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,GAAG,OAAO,GAAG,EAAE,GAAG,GAAG,CAAC,CAC5B,KAAK,GAAG;IAEX,OAAO,EAAI,QAAQ,KAAK,EAAM,KAAK,IAAI,IAAI,GAAQ;GACrD;GAGA,OAAO,EAAI,QAAQ,KAAK,EAAM,KAAK,IAAI,IAAI,GAAY;EAGzD,KAAK,UAAU;GACb,IAAM,IAAa,EAAqB,GAAY,CAAO;GAC3D,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;EAC1D;EAGA,SACE,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;CAC5D;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServerObject } from '@scalar/workspace-store/schemas/v3.
|
|
1
|
+
import type { ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
2
|
/**
|
|
3
3
|
* Processes a server URL by replacing variables with their default values and merging with the path
|
|
4
4
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-server-url.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-server-url.ts"],"sourcesContent":["import { replaceVariables } from '@scalar/helpers/regex/replace-variables'\nimport { mergeUrls } from '@scalar/helpers/url/merge-urls'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.
|
|
1
|
+
{"version":3,"file":"process-server-url.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-server-url.ts"],"sourcesContent":["import { replaceVariables } from '@scalar/helpers/regex/replace-variables'\nimport { mergeUrls } from '@scalar/helpers/url/merge-urls'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\n\n/**\n * Processes a server URL by replacing variables with their default values and merging with the path\n */\nexport const processServerUrl = (server: ServerObject | null, path: string): string => {\n if (!server?.url) {\n return path\n }\n const serverUrl = server.url\n\n // Replace server variables with their default values\n if (server.variables) {\n const variables = Object.entries(server.variables)\n\n // Extract default values from server variables\n const defaultValues = variables.reduce<Record<string, string | number>>(\n (defaults, [variableName, variableConfig]) => {\n if (variableConfig.default !== undefined) {\n defaults[variableName] = variableConfig.default\n }\n return defaults\n },\n {},\n )\n\n // Replace variables in the server URL with their default values\n const serverUrlWithVars = replaceVariables(serverUrl, defaultValues)\n\n return mergeUrls(serverUrlWithVars, path)\n }\n\n return mergeUrls(serverUrl, path)\n}\n"],"mappings":";;;AAOA,IAAa,KAAoB,GAA6B,MAAyB;CACrF,IAAI,CAAC,GAAQ,KACX,OAAO;CAET,IAAM,IAAY,EAAO;CAuBzB,OApBI,EAAO,YAiBF,EAFmB,EAAiB,GAdzB,OAAO,QAAQ,EAAO,SAGlB,CAAA,CAAU,QAC7B,GAAU,CAAC,GAAc,QACpB,EAAe,YAAY,KAAA,MAC7B,EAAS,KAAgB,EAAe,UAEnC,IAET,CAAC,CAImD,CAErC,GAAmB,CAAI,IAGnC,EAAU,GAAW,CAAI;AAClC"}
|
|
@@ -2,7 +2,7 @@ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
|
|
|
2
2
|
import type { AvailableClients } from '@scalar/snippetz';
|
|
3
3
|
import type { WorkspaceStore } from '@scalar/workspace-store/client';
|
|
4
4
|
import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example';
|
|
5
|
-
import type { ServerObject } from '@scalar/workspace-store/schemas/v3.
|
|
5
|
+
import type { ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
6
6
|
export type CreateCodeExampleOptions = {
|
|
7
7
|
/** Workspace store that holds the OpenAPI document(s) to render from. */
|
|
8
8
|
store: WorkspaceStore;
|