@scalar/blocks 0.1.8 → 0.1.10
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 +12 -0
- package/README.md +1 -1
- package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
- package/dist/code-example/components/CodeExample.vue.js +1 -1
- package/dist/code-example/components/CodeExample.vue.script.js +1 -1
- package/dist/code-example/components/CodeExample.vue.script.js.map +1 -1
- package/dist/code-example/components/ExamplePicker.vue.script.js +2 -2
- package/dist/code-example/components/ExamplePicker.vue.script.js.map +1 -1
- package/dist/code-example/components/HttpMethod.vue.script.js +1 -1
- package/dist/code-example/components/HttpMethod.vue.script.js.map +1 -1
- package/dist/code-example/helpers/filter-clients-by-query.js.map +1 -1
- package/dist/code-example/helpers/find-client.js.map +1 -1
- package/dist/code-example/helpers/format-language.js.map +1 -1
- package/dist/code-example/helpers/generate-client-options.js.map +1 -1
- package/dist/code-example/helpers/generate-code-snippet.js.map +1 -1
- package/dist/code-example/helpers/get-clients.js.map +1 -1
- package/dist/code-example/helpers/get-custom-code-samples.js.map +1 -1
- package/dist/code-example/helpers/get-secrets.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.js.map +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 +34 -32
- package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.js +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-security-schemes.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-server-url.js.map +1 -1
- package/dist/code-example/mount.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/style.css +2239 -2807
- package/package.json +17 -26
|
@@ -2,68 +2,70 @@ import { getResolvedRefDeep as e } from "@scalar/workspace-store/helpers/get-res
|
|
|
2
2
|
import { getResolvedRef as t } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
3
3
|
import { getExample as n, getExampleFromSchema as r, serializeFormPropertyWithEncoding as i } from "@scalar/workspace-store/request-example";
|
|
4
4
|
import { json2xml as a } from "@scalar/helpers/file/json2xml";
|
|
5
|
-
import {
|
|
5
|
+
import { isObjectLike as o } from "@scalar/helpers/object/is-object";
|
|
6
|
+
import { unpackProxyObject as s } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
6
7
|
//#region src/code-example/helpers/operation-to-har/process-body.ts
|
|
7
|
-
var
|
|
8
|
-
let a = [],
|
|
9
|
-
for (let [e,
|
|
10
|
-
if (
|
|
11
|
-
let
|
|
12
|
-
if (
|
|
8
|
+
var c = (e, t, n, r = !1) => {
|
|
9
|
+
let a = [], l = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
|
|
10
|
+
for (let [e, u] of l) {
|
|
11
|
+
if (u == null) continue;
|
|
12
|
+
let l = n ? void 0 : t?.[e], d = l && (l.style !== void 0 || l.explode !== void 0 || l.allowReserved !== void 0), f = d || !r ? void 0 : l?.contentType, p = n ? null : i(e, u, l);
|
|
13
|
+
if (p) for (let e of p) a.push({
|
|
13
14
|
name: e.key,
|
|
14
15
|
value: e.value
|
|
15
16
|
});
|
|
16
|
-
else if (
|
|
17
|
-
let t =
|
|
17
|
+
else if (u instanceof File) {
|
|
18
|
+
let t = s(u);
|
|
18
19
|
a.push({
|
|
19
20
|
name: e,
|
|
20
21
|
value: `@${t.name}`,
|
|
21
|
-
...
|
|
22
|
+
...f ? { contentType: f } : {}
|
|
22
23
|
});
|
|
23
|
-
} else if (
|
|
24
|
+
} else if (f && typeof u == "object") a.push({
|
|
24
25
|
name: e,
|
|
25
|
-
value: JSON.stringify(
|
|
26
|
-
contentType:
|
|
26
|
+
value: JSON.stringify(s(u)),
|
|
27
|
+
contentType: f
|
|
27
28
|
});
|
|
28
|
-
else if (r && !n && !
|
|
29
|
+
else if (r && !n && !d && typeof u == "object" && !Array.isArray(u)) a.push({
|
|
29
30
|
name: e,
|
|
30
|
-
value: JSON.stringify(
|
|
31
|
+
value: JSON.stringify(s(u)),
|
|
31
32
|
contentType: "application/json"
|
|
32
33
|
});
|
|
33
|
-
else if (Array.isArray(
|
|
34
|
-
|
|
34
|
+
else if (Array.isArray(u) && r && !n && !d && u.some((e) => o(e) && !(e instanceof File))) a.push({
|
|
35
|
+
name: e,
|
|
36
|
+
value: JSON.stringify(s(u)),
|
|
37
|
+
contentType: "application/json"
|
|
38
|
+
});
|
|
39
|
+
else if (Array.isArray(u)) for (let t of u) if (t instanceof File) {
|
|
40
|
+
let n = s(t);
|
|
35
41
|
a.push({
|
|
36
42
|
name: e,
|
|
37
43
|
value: `@${n.name}`
|
|
38
44
|
});
|
|
39
|
-
} else
|
|
40
|
-
name: e,
|
|
41
|
-
value: JSON.stringify(o(t)),
|
|
42
|
-
contentType: "application/json"
|
|
43
|
-
}) : a.push({
|
|
45
|
+
} else a.push({
|
|
44
46
|
name: e,
|
|
45
47
|
value: String(t)
|
|
46
48
|
});
|
|
47
|
-
else if (typeof
|
|
48
|
-
let t =
|
|
49
|
+
else if (typeof u == "object") {
|
|
50
|
+
let t = c(u, void 0, e);
|
|
49
51
|
for (let n of t) a.push({
|
|
50
52
|
name: `${e}.${n.name}`,
|
|
51
53
|
value: n.value
|
|
52
54
|
});
|
|
53
55
|
} else a.push({
|
|
54
56
|
name: e,
|
|
55
|
-
value: String(
|
|
56
|
-
...
|
|
57
|
+
value: String(u),
|
|
58
|
+
...f ? { contentType: f } : {}
|
|
57
59
|
});
|
|
58
60
|
}
|
|
59
61
|
return a;
|
|
60
|
-
},
|
|
61
|
-
let d =
|
|
62
|
+
}, l = ({ requestBody: i, contentType: o, example: l, requestBodyCompositionSelection: u }) => {
|
|
63
|
+
let d = o || Object.keys(i.content)[0] || "", f = d === "other" ? "" : d, p = (e) => `@${s(e).name || "filename"}`, m = i.content[d]?.encoding, h = d === "multipart/form-data" || d === "application/x-www-form-urlencoded", g = d === "application/xml", _ = n(i, l, o)?.value;
|
|
62
64
|
if (_ !== void 0) {
|
|
63
|
-
let e = typeof _ == "object" && _ ?
|
|
65
|
+
let e = typeof _ == "object" && _ ? s(_) : _;
|
|
64
66
|
return h && typeof e == "object" && e ? {
|
|
65
67
|
mimeType: f,
|
|
66
|
-
params:
|
|
68
|
+
params: c(e, m, void 0, d === "multipart/form-data")
|
|
67
69
|
} : g && typeof e == "object" && e ? {
|
|
68
70
|
mimeType: f,
|
|
69
71
|
text: a(e)
|
|
@@ -84,7 +86,7 @@ var s = (e, t, n, r = !1) => {
|
|
|
84
86
|
}, { schemaPath: ["requestBody"] });
|
|
85
87
|
if (t !== void 0) return h && typeof t == "object" && t ? {
|
|
86
88
|
mimeType: f,
|
|
87
|
-
params:
|
|
89
|
+
params: c(t, m, void 0, d === "multipart/form-data")
|
|
88
90
|
} : g && typeof t == "object" && t ? {
|
|
89
91
|
mimeType: f,
|
|
90
92
|
text: a(t)
|
|
@@ -95,6 +97,6 @@ var s = (e, t, n, r = !1) => {
|
|
|
95
97
|
}
|
|
96
98
|
};
|
|
97
99
|
//#endregion
|
|
98
|
-
export {
|
|
100
|
+
export { l as processBody };
|
|
99
101
|
|
|
100
102
|
//# 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 { 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 (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 if (isMultipart && !parentKey && !hasFormStyle && typeof item === 'object' && item !== null) {\n /**\n * Per OpenAPI 3.x: a top-level multipart array of complex items defaults each part\n * to application/json, instead of flattening object items into dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(item)),\n contentType: 'application/json',\n })\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":";;;;;;AA6CA,IAAM,KACJ,GACA,GACA,GACA,IAAc,OACF;CACZ,IAAM,IAAkB,EAAE,EAGpB,IAA+B,MAAM,QAAQ,EAAI,GACnD,EAAI,QAAQ,MAAS,CAAC,EAAK,WA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e,OAAO;AAC/E,KAAW,MAAkB,QAAa;EAExC,IAAM,IAAmB,EADK,EAAmB,EAAc,EAG7D;GACE,sBAAsB;GACtB,MAAM;GACN,KAAK;GACN,EACD,EACE,YAAY,CAAC,cAAc,EAC5B,CACF;AAED,MAAI,MAAqB,KAAA,EAevB,QAdI,KAAc,OAAO,KAAqB,YAAY,IACjD;GACL,UAAU;GACV,QAAQ,EAAmB,GAAkB,GAAU,KAAA,GAAW,MAAiB,sBAAsB;GAC1G,GAGC,KAAS,OAAO,KAAqB,YAAY,IAC5C;GACL,UAAU;GACV,MAAM,EAAS,EAAiB;GACjC,GAGI;GACL,UAAU;GACV,MAAM,OAAO,KAAqB,WAAW,IAAmB,KAAK,UAAU,EAAiB;GACjG"}
|
|
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,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AAK;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"}
|
|
@@ -4,7 +4,7 @@ import { deSerializeParameter as t, getExample as n, getExampleFromSchema as r,
|
|
|
4
4
|
var f = (t) => (t ?? []).map((t) => e(t)), p = (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, m = (e, t) => p(t) ? e : encodeURIComponent(e), h = (e) => {
|
|
5
5
|
if (e.in === "header") return {
|
|
6
6
|
style: "simple",
|
|
7
|
-
explode: "explode" in e && e.explode !== void 0
|
|
7
|
+
explode: "explode" in e && e.explode !== void 0 && e.explode
|
|
8
8
|
};
|
|
9
9
|
if (e.in === "cookie") return {
|
|
10
10
|
style: "form",
|
|
@@ -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,EAAE,EAAE,KAAK,MAAU,EAAe,EAAM,CAAC,EAGhD,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,EAAM,GACjB,IAEF,mBAAmB,EAAM,EAO5B,KAA+B,MAAgE;AAEnG,KAAI,EAAM,OAAO,SAEf,QAAO;EAAE,OAAO;EAAU,SADV,aAAa,KAAS,EAAM,YAAY,KAAA,IAAY,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EAAsC,CACjE,KAAK,CAAC,GAAG,OAAO,GAAG,EAAE,GAAG,IAAI,CAC5B,KAAK,IAAI;AAEZ,WAAO,EAAI,QAAQ,KAAK,EAAM,KAAK,IAAI,IAAI,IAAS;;AAItD,UAAO,EAAI,QAAQ,KAAK,EAAM,KAAK,IAAI,IAAI,IAAa;EAG1D,KAAK,UAAU;GACb,IAAM,IAAa,EAAqB,GAAY,EAAQ;AAC5D,UAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,EAAW,CAAC;;EAI3D,QACE,QAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,EAAW,CAAC"}
|
|
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,KAAA,IAAY,EAAM,UAAU;CACpD;CAGlC,IAAM,IAAe;EACnB,MAAM;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;CACV,EAAE,EAAM,KAGF,IAAQ,WAAW,KAAS,EAAM,QAAQ,EAAM,QAAQ;CAK9D,OAAO;EAAE;EAAO,SAFA,aAAa,KAAS,EAAM,YAAY,KAAA,IAAY,EAAM,UAAU,MAAU;CAEtE;AAC1B,GAOM,KACJ,GACA,GACA,GACA,MACY;CAEZ,IAAM,IAAe,EAAW,GAAO,GAAS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QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;EAC1D;EAGA,SACE,OAAO,EAAI,QAAQ,IAAI,EAAM,KAAK,IAAI,OAAO,CAAU,CAAC;CAC5D;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-security-schemes.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-security-schemes.ts"],"sourcesContent":["import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { Request as HarRequest } from 'har-format'\nimport { encode } from 'js-base64'\n\ntype ProcessedSecuritySchemesReturn = {\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n}\n\n/**\n * Process security schemes into whichever parameters they are applicable to\n *\n * TODO: we probably want to be able to disable YOUR_SECRET_TOKEN placeholder text + or allow it to be customzied\n */\nexport const processSecuritySchemes = (\n securitySchemes: SecuritySchemeObjectSecret[],\n): ProcessedSecuritySchemesReturn => {\n const result: ProcessedSecuritySchemesReturn = {\n headers: [],\n queryString: [],\n cookies: [],\n }\n\n for (const scheme of securitySchemes) {\n // Handle apiKey type\n if (scheme.type === 'apiKey') {\n const value = scheme['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n if (!scheme.name) {\n continue\n }\n\n const param = { name: scheme.name, value }\n\n switch (scheme.in) {\n case 'header':\n result.headers.push(param)\n break\n case 'query':\n result.queryString.push(param)\n break\n case 'cookie':\n result.cookies.push(param)\n break\n }\n continue\n }\n\n // Handle http type\n if (scheme.type === 'http') {\n if (scheme.scheme === 'basic') {\n const username = scheme['x-scalar-secret-username'] || ''\n const password = scheme['x-scalar-secret-password'] || ''\n\n // The snippet is documentation, so we always show an Authorization header. When both\n // fields are empty we render a readable `username:password` placeholder, mirroring the\n // `YOUR_SECRET_TOKEN` placeholder used by the other schemes. (The real request omits the\n // header entirely in that case — see buildRequestSecurity.)\n const value = `${username}:${password}`\n const auth = value === ':' ? 'username:password' : encode(value)\n\n result.headers.push({\n name: 'Authorization',\n value: `Basic ${auth}`,\n })\n } else if (scheme.scheme === 'bearer') {\n const token = scheme['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n continue\n }\n\n // Handle oauth2 type\n if (scheme.type === 'oauth2' && scheme.flows) {\n const flows = Object.values(scheme.flows)\n\n // Find the first flow with a token\n const flow = flows.find((f) => f['x-scalar-secret-token'])\n const token = flow?.['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n }\n\n return result\n}\n"],"mappings":";;AAeA,IAAa,KACX,MACmC;CACnC,IAAM,IAAyC;EAC7C,SAAS,
|
|
1
|
+
{"version":3,"file":"process-security-schemes.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-security-schemes.ts"],"sourcesContent":["import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { Request as HarRequest } from 'har-format'\nimport { encode } from 'js-base64'\n\ntype ProcessedSecuritySchemesReturn = {\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n}\n\n/**\n * Process security schemes into whichever parameters they are applicable to\n *\n * TODO: we probably want to be able to disable YOUR_SECRET_TOKEN placeholder text + or allow it to be customzied\n */\nexport const processSecuritySchemes = (\n securitySchemes: SecuritySchemeObjectSecret[],\n): ProcessedSecuritySchemesReturn => {\n const result: ProcessedSecuritySchemesReturn = {\n headers: [],\n queryString: [],\n cookies: [],\n }\n\n for (const scheme of securitySchemes) {\n // Handle apiKey type\n if (scheme.type === 'apiKey') {\n const value = scheme['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n if (!scheme.name) {\n continue\n }\n\n const param = { name: scheme.name, value }\n\n switch (scheme.in) {\n case 'header':\n result.headers.push(param)\n break\n case 'query':\n result.queryString.push(param)\n break\n case 'cookie':\n result.cookies.push(param)\n break\n }\n continue\n }\n\n // Handle http type\n if (scheme.type === 'http') {\n if (scheme.scheme === 'basic') {\n const username = scheme['x-scalar-secret-username'] || ''\n const password = scheme['x-scalar-secret-password'] || ''\n\n // The snippet is documentation, so we always show an Authorization header. When both\n // fields are empty we render a readable `username:password` placeholder, mirroring the\n // `YOUR_SECRET_TOKEN` placeholder used by the other schemes. (The real request omits the\n // header entirely in that case — see buildRequestSecurity.)\n const value = `${username}:${password}`\n const auth = value === ':' ? 'username:password' : encode(value)\n\n result.headers.push({\n name: 'Authorization',\n value: `Basic ${auth}`,\n })\n } else if (scheme.scheme === 'bearer') {\n const token = scheme['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n continue\n }\n\n // Handle oauth2 type\n if (scheme.type === 'oauth2' && scheme.flows) {\n const flows = Object.values(scheme.flows)\n\n // Find the first flow with a token\n const flow = flows.find((f) => f['x-scalar-secret-token'])\n const token = flow?.['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n }\n\n return result\n}\n"],"mappings":";;AAeA,IAAa,KACX,MACmC;CACnC,IAAM,IAAyC;EAC7C,SAAS,CAAC;EACV,aAAa,CAAC;EACd,SAAS,CAAC;CACZ;CAEA,KAAK,IAAM,KAAU,GAAiB;EAEpC,IAAI,EAAO,SAAS,UAAU;GAC5B,IAAM,IAAQ,EAAO,4BAA4B;GACjD,IAAI,CAAC,EAAO,MACV;GAGF,IAAM,IAAQ;IAAE,MAAM,EAAO;IAAM;GAAM;GAEzC,QAAQ,EAAO,IAAf;IACE,KAAK;KACH,EAAO,QAAQ,KAAK,CAAK;KACzB;IACF,KAAK;KACH,EAAO,YAAY,KAAK,CAAK;KAC7B;IACF,KAAK;KACH,EAAO,QAAQ,KAAK,CAAK;KACzB;GACJ;GACA;EACF;EAGA,IAAI,EAAO,SAAS,QAAQ;GAC1B,IAAI,EAAO,WAAW,SAAS;IAQ7B,IAAM,IAAQ,GAPG,EAAO,+BAA+B,GAO7B,GANT,EAAO,+BAA+B,MAOjD,IAAO,MAAU,MAAM,sBAAsB,EAAO,CAAK;IAE/D,EAAO,QAAQ,KAAK;KAClB,MAAM;KACN,OAAO,SAAS;IAClB,CAAC;GACH,OAAO,IAAI,EAAO,WAAW,UAAU;IACrC,IAAM,IAAQ,EAAO,4BAA4B;IAEjD,EAAO,QAAQ,KAAK;KAClB,MAAM;KACN,OAAO,UAAU;IACnB,CAAC;GACH;GACA;EACF;EAGA,IAAI,EAAO,SAAS,YAAY,EAAO,OAAO;GAK5C,IAAM,IAJQ,OAAO,OAAO,EAAO,KAGtB,CAAA,CAAM,MAAM,MAAM,EAAE,wBACnB,CAAA,GAAO,4BAA4B;GAEjD,EAAO,QAAQ,KAAK;IAClB,MAAM;IACN,OAAO,UAAU;GACnB,CAAC;EACH;CACF;CAEA,OAAO;AACT"}
|
|
@@ -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/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(\n (defaults, [variableName, variableConfig]) => {\n if (variableConfig.default !== undefined) {\n defaults[variableName] = variableConfig.default\n }\n return defaults\n },\n {} as Record<string, string | number>,\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;
|
|
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/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(\n (defaults, [variableName, variableConfig]) => {\n if (variableConfig.default !== undefined) {\n defaults[variableName] = variableConfig.default\n }\n return defaults\n },\n {} as Record<string, string | number>,\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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.js","names":[],"sources":["../../src/code-example/mount.ts"],"sourcesContent":["import { ScalarTeleportRoot } from '@scalar/components/teleport'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClients } from '@scalar/snippetz'\nimport type { WorkspaceStore } from '@scalar/workspace-store/client'\nimport { createWorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getFirstServer } from '@scalar/workspace-store/helpers/get-first-server'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { generateClientMutators } from '@scalar/workspace-store/mutators'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport { createApp, h, reactive } from 'vue'\n\nimport CodeExample, { type CodeExampleProps } from './components/CodeExample.vue'\nimport { generateClientOptions } from './helpers/generate-client-options'\n\nexport type CreateCodeExampleOptions = {\n /** Workspace store that holds the OpenAPI document(s) to render from. */\n store: WorkspaceStore\n /** Path of the operation to render, e.g. '/users/{id}'. */\n path: string\n /** HTTP method of the operation to render. */\n method: HttpMethod\n /** Pre-selected client ID, e.g. 'shell/curl'. */\n selectedClient?: AvailableClients[number]\n /**\n * Server object override used to build the example request.\n *\n * When omitted, the server is derived from the active document (operation,\n * then path item, then document level), mirroring the API reference. Pass\n * `null` to force \"no server\".\n */\n selectedServer?: ServerObject | null\n /**\n * Pre-selected example key for parameters and the request body.\n *\n * The store is the source of truth once an example is picked, so\n * `x-scalar-default-example` wins over this initial seed and the selection\n * round-trips through the store like the client selection does.\n */\n selectedExample?: string\n /** Security schemes applicable to the operation. */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /**\n * Force a color mode on the rendered block.\n *\n * When omitted, the block inherits the ambient theme of the host page.\n * Pass `true` for dark mode or `false` for light mode.\n */\n darkMode?: boolean\n}\n\n/**\n * Builds the wrapper classes for the mounted block.\n *\n * The `.scalar-app` class scopes the Tailwind utilities, and the optional\n * color-mode class lets consumers pin the block to dark or light.\n */\nconst getWrapperClass = (darkMode: boolean | undefined): string =>\n ['scalar-app', darkMode === true ? 'dark-mode' : darkMode === false ? 'light-mode' : ''].filter(Boolean).join(' ')\n\n/**\n * Mount the CodeExample block to a DOM element without Vue.\n *\n * The consumer creates and controls their own workspace store,\n * then passes it in along with the path and method to render.\n */\nexport const createCodeExample = (el: HTMLElement | string, options: CreateCodeExampleOptions) => {\n const element = typeof el === 'string' ? document.querySelector(el) : el\n if (!element) {\n throw new Error(`Element not found: ${el}`)\n }\n\n const eventBus = createWorkspaceEventBus()\n const clientOptions = generateClientOptions()\n\n // Persist client changes back to the store. The block emits\n // `workspace:update:selected-client` on its private bus when the user picks a\n // client; without this subscription the choice would never reach the store\n // and `x-scalar-default-client` (the source of truth read below) would stay\n // stale, so the selection would not survive a re-render or be shared with\n // other blocks reading from the same store.\n const mutators = generateClientMutators(options.store)\n const unsubscribeClient = eventBus.on('workspace:update:selected-client', (payload) =>\n mutators.workspace().workspace.updateSelectedClient(payload),\n )\n\n // Persist example changes back to the store as well, mirroring the client\n // round-trip above. The block emits `workspace:update:selected-example` when\n // the user picks an example; without this the choice would never reach\n // `x-scalar-default-example` (read below) and would neither survive a\n // re-render nor sync to other blocks reading from the same store.\n const unsubscribeExample = eventBus.on('workspace:update:selected-example', (payload) =>\n mutators.workspace().workspace.updateSelectedExample(payload),\n )\n\n type OperationContext = { operation: OperationObject; server: ServerObject | null }\n\n /**\n * Resolve the operation and its effective server from the active document.\n *\n * The server is resolved from the same document the operation came from\n * (operation, then path item, then document level), so a snippet never pairs\n * an operation with a server URL from a different spec.\n */\n const resolveContext = (): OperationContext | undefined => {\n // The active document may be an AsyncAPI document, which has no `paths`.\n const activeDocument = options.store.workspace.activeDocument\n if (!activeDocument || !('paths' in activeDocument)) {\n return undefined\n }\n const pathItem = getResolvedRef(activeDocument.paths?.[options.path])\n const operation = getResolvedRef(pathItem?.[options.method])\n if (!operation) {\n return undefined\n }\n const server = getFirstServer(operation.servers ?? null, pathItem?.servers ?? null, activeDocument.servers ?? null)\n return { operation, server }\n }\n\n // Fail loudly if the path and method do not point at an operation in the store,\n // mirroring the \"element not found\" guard above.\n if (!resolveContext()) {\n throw new Error(`Operation not found: ${options.method.toUpperCase()} ${options.path}`)\n }\n\n // Remember the last context that resolved so a transient miss (e.g. the active\n // document is swapped to one without this path or method after mount) keeps\n // rendering the previous operation, paired with the server it actually came\n // from, instead of feeding `undefined` to the block.\n let lastContext: OperationContext | undefined\n\n /** Current operation + server, falling back to the last good resolution on a transient miss. */\n const currentContext = (): OperationContext => {\n const context = resolveContext()\n if (context) {\n lastContext = context\n }\n return (context ?? lastContext) as OperationContext\n }\n\n // Props are getters so the block tracks the reactive store (active document,\n // `x-scalar-default-client`, `x-scalar-default-example`) live. Change the\n // client, example, or server through the store to drive re-renders.\n const props = reactive<CodeExampleProps>({\n get operation(): OperationObject {\n return currentContext().operation\n },\n get method() {\n return options.method\n },\n get path() {\n return options.path\n },\n clientOptions,\n eventBus,\n get securitySchemes() {\n return options.securitySchemes ?? []\n },\n get selectedClient() {\n // The store is the source of truth once the user picks a client, so it\n // wins over the initial `options.selectedClient` seed and the selection\n // round-trips through the subscription above.\n return options.store.workspace['x-scalar-default-client'] ?? options.selectedClient\n },\n get selectedExample() {\n // Same as the client: the store wins over the initial seed so the example\n // selection survives re-renders and syncs across blocks.\n return options.store.workspace['x-scalar-default-example'] ?? options.selectedExample\n },\n get selectedServer() {\n // An explicit option wins (including an explicit `null` for \"no server\");\n // otherwise derive it from the same document the operation resolved from.\n return options.selectedServer !== undefined ? options.selectedServer : currentContext().server\n },\n })\n\n // Render the operation path in the header by default. The reference renders\n // this via the `#header` slot too, so the standalone block matches its look.\n const renderHeader = () => h('span', { class: 'font-code text-c-2 min-w-0 truncate' }, options.path)\n\n // Wrap the block in its own teleport root so floating UI (the client picker\n // popover) renders inside the themed `.scalar-app` wrapper instead of escaping\n // to `body`, where it would miss the color-mode variables and lose its styling.\n const app = createApp(() =>\n h('div', { class: getWrapperClass(options.darkMode) }, [\n h(ScalarTeleportRoot, null, { default: () => h(CodeExample, props, { header: renderHeader }) }),\n ]),\n )\n\n app.mount(element)\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A;EACA,IAAI,kBAAkB;AACpB,UAAO,EAAQ,mBAAmB,EAAE;;EAEtC,IAAI,iBAAiB;AAInB,UAAO,EAAQ,MAAM,UAAU,8BAA8B,EAAQ;;EAEvE,IAAI,kBAAkB;AAGpB,UAAO,EAAQ,MAAM,UAAU,+BAA+B,EAAQ;;EAExE,IAAI,iBAAiB;AAGnB,UAAO,EAAQ,mBAAmB,KAAA,IAAqC,GAAgB,CAAC,SAA1C,EAAQ;;EAEzD,CAAC,EAII,UAAqB,EAAE,QAAQ,EAAE,OAAO,uCAAuC,EAAE,EAAQ,KAAK,EAK9F,IAAM,QACV,EAAE,OAAO,EAAE,OAAO,EAAgB,EAAQ,SAAS,EAAE,EAAE,CACrD,EAAE,GAAoB,MAAM,EAAE,eAAe,EAAE,GAAa,GAAO,EAAE,QAAQ,GAAc,CAAC,EAAE,CAAC,CAChG,CAAC,CACH;AAID,QAFA,EAAI,MAAM,EAAQ,EAEX;EACL;EACA,eAAe;AAGb,GAFA,GAAmB,EACnB,GAAoB,EACpB,EAAI,SAAS;;EAEhB"}
|
|
1
|
+
{"version":3,"file":"mount.js","names":[],"sources":["../../src/code-example/mount.ts"],"sourcesContent":["import { ScalarTeleportRoot } from '@scalar/components/teleport'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClients } from '@scalar/snippetz'\nimport type { WorkspaceStore } from '@scalar/workspace-store/client'\nimport { createWorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getFirstServer } from '@scalar/workspace-store/helpers/get-first-server'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { generateClientMutators } from '@scalar/workspace-store/mutators'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport { createApp, h, reactive } from 'vue'\n\nimport CodeExample, { type CodeExampleProps } from './components/CodeExample.vue'\nimport { generateClientOptions } from './helpers/generate-client-options'\n\nexport type CreateCodeExampleOptions = {\n /** Workspace store that holds the OpenAPI document(s) to render from. */\n store: WorkspaceStore\n /** Path of the operation to render, e.g. '/users/{id}'. */\n path: string\n /** HTTP method of the operation to render. */\n method: HttpMethod\n /** Pre-selected client ID, e.g. 'shell/curl'. */\n selectedClient?: AvailableClients[number]\n /**\n * Server object override used to build the example request.\n *\n * When omitted, the server is derived from the active document (operation,\n * then path item, then document level), mirroring the API reference. Pass\n * `null` to force \"no server\".\n */\n selectedServer?: ServerObject | null\n /**\n * Pre-selected example key for parameters and the request body.\n *\n * The store is the source of truth once an example is picked, so\n * `x-scalar-default-example` wins over this initial seed and the selection\n * round-trips through the store like the client selection does.\n */\n selectedExample?: string\n /** Security schemes applicable to the operation. */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /**\n * Force a color mode on the rendered block.\n *\n * When omitted, the block inherits the ambient theme of the host page.\n * Pass `true` for dark mode or `false` for light mode.\n */\n darkMode?: boolean\n}\n\n/**\n * Builds the wrapper classes for the mounted block.\n *\n * The `.scalar-app` class scopes the Tailwind utilities, and the optional\n * color-mode class lets consumers pin the block to dark or light.\n */\nconst getWrapperClass = (darkMode: boolean | undefined): string =>\n ['scalar-app', darkMode === true ? 'dark-mode' : darkMode === false ? 'light-mode' : ''].filter(Boolean).join(' ')\n\n/**\n * Mount the CodeExample block to a DOM element without Vue.\n *\n * The consumer creates and controls their own workspace store,\n * then passes it in along with the path and method to render.\n */\nexport const createCodeExample = (el: HTMLElement | string, options: CreateCodeExampleOptions) => {\n const element = typeof el === 'string' ? document.querySelector(el) : el\n if (!element) {\n throw new Error(`Element not found: ${el}`)\n }\n\n const eventBus = createWorkspaceEventBus()\n const clientOptions = generateClientOptions()\n\n // Persist client changes back to the store. The block emits\n // `workspace:update:selected-client` on its private bus when the user picks a\n // client; without this subscription the choice would never reach the store\n // and `x-scalar-default-client` (the source of truth read below) would stay\n // stale, so the selection would not survive a re-render or be shared with\n // other blocks reading from the same store.\n const mutators = generateClientMutators(options.store)\n const unsubscribeClient = eventBus.on('workspace:update:selected-client', (payload) =>\n mutators.workspace().workspace.updateSelectedClient(payload),\n )\n\n // Persist example changes back to the store as well, mirroring the client\n // round-trip above. The block emits `workspace:update:selected-example` when\n // the user picks an example; without this the choice would never reach\n // `x-scalar-default-example` (read below) and would neither survive a\n // re-render nor sync to other blocks reading from the same store.\n const unsubscribeExample = eventBus.on('workspace:update:selected-example', (payload) =>\n mutators.workspace().workspace.updateSelectedExample(payload),\n )\n\n type OperationContext = { operation: OperationObject; server: ServerObject | null }\n\n /**\n * Resolve the operation and its effective server from the active document.\n *\n * The server is resolved from the same document the operation came from\n * (operation, then path item, then document level), so a snippet never pairs\n * an operation with a server URL from a different spec.\n */\n const resolveContext = (): OperationContext | undefined => {\n // The active document may be an AsyncAPI document, which has no `paths`.\n const activeDocument = options.store.workspace.activeDocument\n if (!activeDocument || !('paths' in activeDocument)) {\n return undefined\n }\n const pathItem = getResolvedRef(activeDocument.paths?.[options.path])\n const operation = getResolvedRef(pathItem?.[options.method])\n if (!operation) {\n return undefined\n }\n const server = getFirstServer(operation.servers ?? null, pathItem?.servers ?? null, activeDocument.servers ?? null)\n return { operation, server }\n }\n\n // Fail loudly if the path and method do not point at an operation in the store,\n // mirroring the \"element not found\" guard above.\n if (!resolveContext()) {\n throw new Error(`Operation not found: ${options.method.toUpperCase()} ${options.path}`)\n }\n\n // Remember the last context that resolved so a transient miss (e.g. the active\n // document is swapped to one without this path or method after mount) keeps\n // rendering the previous operation, paired with the server it actually came\n // from, instead of feeding `undefined` to the block.\n let lastContext: OperationContext | undefined\n\n /** Current operation + server, falling back to the last good resolution on a transient miss. */\n const currentContext = (): OperationContext => {\n const context = resolveContext()\n if (context) {\n lastContext = context\n }\n return (context ?? lastContext) as OperationContext\n }\n\n // Props are getters so the block tracks the reactive store (active document,\n // `x-scalar-default-client`, `x-scalar-default-example`) live. Change the\n // client, example, or server through the store to drive re-renders.\n const props = reactive<CodeExampleProps>({\n get operation(): OperationObject {\n return currentContext().operation\n },\n get method() {\n return options.method\n },\n get path() {\n return options.path\n },\n clientOptions,\n eventBus,\n get securitySchemes() {\n return options.securitySchemes ?? []\n },\n get selectedClient() {\n // The store is the source of truth once the user picks a client, so it\n // wins over the initial `options.selectedClient` seed and the selection\n // round-trips through the subscription above.\n return options.store.workspace['x-scalar-default-client'] ?? options.selectedClient\n },\n get selectedExample() {\n // Same as the client: the store wins over the initial seed so the example\n // selection survives re-renders and syncs across blocks.\n return options.store.workspace['x-scalar-default-example'] ?? options.selectedExample\n },\n get selectedServer() {\n // An explicit option wins (including an explicit `null` for \"no server\");\n // otherwise derive it from the same document the operation resolved from.\n return options.selectedServer !== undefined ? options.selectedServer : currentContext().server\n },\n })\n\n // Render the operation path in the header by default. The reference renders\n // this via the `#header` slot too, so the standalone block matches its look.\n const renderHeader = () => h('span', { class: 'font-code text-c-2 min-w-0 truncate' }, options.path)\n\n // Wrap the block in its own teleport root so floating UI (the client picker\n // popover) renders inside the themed `.scalar-app` wrapper instead of escaping\n // to `body`, where it would miss the color-mode variables and lose its styling.\n const app = createApp(() =>\n h('div', { class: getWrapperClass(options.darkMode) }, [\n h(ScalarTeleportRoot, null, { default: () => h(CodeExample, props, { header: renderHeader }) }),\n ]),\n )\n\n app.mount(element)\n\n return {\n app,\n destroy: () => {\n unsubscribeClient()\n unsubscribeExample()\n app.unmount()\n },\n }\n}\n"],"mappings":";;;;;;;;;AAyDA,IAAM,KAAmB,MACvB,CAAC,cAAc,MAAa,KAAO,cAAc,MAAa,KAAQ,eAAe,EAAE,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,GAQtG,KAAqB,GAA0B,MAAsC;CAChG,IAAM,IAAU,OAAO,KAAO,WAAW,SAAS,cAAc,CAAE,IAAI;CACtE,IAAI,CAAC,GACH,MAAU,MAAM,sBAAsB,GAAI;CAG5C,IAAM,IAAW,EAAwB,GACnC,IAAgB,EAAsB,GAQtC,IAAW,EAAuB,EAAQ,KAA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