@scalar/blocks 0.7.3 → 0.8.0
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 +29 -0
- package/dist/_virtual/_plugin-vue_export-helper.js +1 -2
- package/dist/code-example/components/AsyncApiCodeExample.vue.js +1 -2
- package/dist/code-example/components/AsyncApiCodeExample.vue.js.map +1 -1
- package/dist/code-example/components/AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/code-example/components/AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue.d.ts +2 -0
- package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
- package/dist/code-example/components/CodeExample.vue.js +4 -5
- package/dist/code-example/components/CodeExample.vue.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js +102 -100
- package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/code-example/components/ExamplePicker.vue.js +1 -2
- package/dist/code-example/components/ExamplePicker.vue.js.map +1 -1
- package/dist/code-example/components/ExamplePicker.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/code-example/components/HttpMethod.vue.js +1 -2
- package/dist/code-example/components/HttpMethod.vue.js.map +1 -1
- package/dist/code-example/components/HttpMethod.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/code-example/helpers/filter-clients-by-query.js +1 -2
- package/dist/code-example/helpers/find-client.js +1 -2
- package/dist/code-example/helpers/format-language.js +1 -2
- package/dist/code-example/helpers/generate-client-options.js +1 -2
- package/dist/code-example/helpers/generate-code-snippet.d.ts +2 -1
- package/dist/code-example/helpers/generate-code-snippet.d.ts.map +1 -1
- package/dist/code-example/helpers/generate-code-snippet.js +11 -11
- package/dist/code-example/helpers/generate-code-snippet.js.map +1 -1
- package/dist/code-example/helpers/get-asyncapi-example-context.js +1 -2
- package/dist/code-example/helpers/get-clients.js +8 -9
- package/dist/code-example/helpers/get-custom-code-samples.js +1 -2
- package/dist/code-example/helpers/get-generated-payload-example.js +1 -2
- package/dist/code-example/helpers/get-message-example-content.js +1 -2
- package/dist/code-example/helpers/get-secrets.js +1 -2
- package/dist/code-example/helpers/get-snippet.js +1 -2
- package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts +2 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.js +32 -31
- 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 +2 -2
- 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 +80 -52
- 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 +2 -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 +65 -58
- 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.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-security-schemes.js +31 -28
- 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 +1 -2
- package/dist/code-example/index.js +10 -10
- package/dist/code-example/mount-asyncapi.js +7 -8
- package/dist/code-example/mount.js +5 -6
- package/dist/constants.js +2 -3
- package/dist/schema/LinkButton.vue.js +1 -2
- package/dist/schema/RenderString.vue.js +1 -2
- package/dist/schema/RenderString.vue.js.map +1 -1
- package/dist/schema/RenderString.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/Schema.vue.js +4 -5
- package/dist/schema/Schema.vue.js.map +1 -1
- package/dist/schema/Schema.vue_vue_type_script_setup_true_lang.js +67 -68
- package/dist/schema/Schema.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaCollapsedPreview.vue.js +1 -2
- package/dist/schema/SchemaCollapsedPreview.vue.js.map +1 -1
- package/dist/schema/SchemaCollapsedPreview.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaCollapsedPreview.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaComposition.vue.js +4 -5
- package/dist/schema/SchemaComposition.vue.js.map +1 -1
- package/dist/schema/SchemaComposition.vue_vue_type_script_setup_true_lang.js +26 -27
- package/dist/schema/SchemaComposition.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaEnumPropertyItem.vue.js +1 -2
- package/dist/schema/SchemaEnumPropertyItem.vue.js.map +1 -1
- package/dist/schema/SchemaEnumPropertyItem.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaEnumPropertyItem.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaEnums.vue.js +4 -5
- package/dist/schema/SchemaEnums.vue.js.map +1 -1
- package/dist/schema/SchemaEnums.vue_vue_type_script_setup_true_lang.js +12 -13
- package/dist/schema/SchemaEnums.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaGlyphPuck.vue.js +1 -2
- package/dist/schema/SchemaGlyphPuck.vue.js.map +1 -1
- package/dist/schema/SchemaGlyphPuck.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaGutterToggle.vue.js +1 -2
- package/dist/schema/SchemaGutterToggle.vue.js.map +1 -1
- package/dist/schema/SchemaGutterToggle.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaHeading.vue.js +4 -5
- package/dist/schema/SchemaHeading.vue.js.map +1 -1
- package/dist/schema/SchemaHeading.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaHeading.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaObjectExampleCodeBlock.vue.js +1 -2
- package/dist/schema/SchemaObjectExampleCodeBlock.vue.js.map +1 -1
- package/dist/schema/SchemaObjectExampleCodeBlock.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaObjectExampleCodeBlock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaObjectProperties.vue.js +1 -2
- package/dist/schema/SchemaObjectProperties.vue.js.map +1 -1
- package/dist/schema/SchemaObjectProperties.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaObjectProperties.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaProperty.vue.js +4 -5
- package/dist/schema/SchemaProperty.vue.js.map +1 -1
- package/dist/schema/SchemaProperty.vue_vue_type_script_setup_true_lang.js +48 -49
- package/dist/schema/SchemaProperty.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaPropertyDefault.vue.js +4 -5
- package/dist/schema/SchemaPropertyDefault.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyDefault.vue_vue_type_script_setup_true_lang.js +9 -10
- package/dist/schema/SchemaPropertyDefault.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaPropertyDetail.vue.js +4 -5
- package/dist/schema/SchemaPropertyDetail.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyDetail.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaPropertyDetail.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaPropertyExamples.vue.js +4 -5
- package/dist/schema/SchemaPropertyExamples.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js +18 -19
- package/dist/schema/SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.js +4 -5
- package/dist/schema/SchemaPropertyHeading.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js +101 -102
- package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaPropertyPattern.vue.js +4 -5
- package/dist/schema/SchemaPropertyPattern.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyPattern.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaRailPanel.vue.js +1 -2
- package/dist/schema/SchemaRailPanel.vue.js.map +1 -1
- package/dist/schema/SchemaRailPanel.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/SchemaRailPanel.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/components/CopyLinkButton.vue.js +1 -2
- package/dist/schema/components/CopyLinkButton.vue.js.map +1 -1
- package/dist/schema/components/CopyLinkButton.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/components/WithBreadcrumb.vue.js +1 -2
- package/dist/schema/components/WithBreadcrumb.vue.js.map +1 -1
- package/dist/schema/components/WithBreadcrumb.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/schema/discriminator-metadata.js +1 -2
- package/dist/schema/helpers/dynamic-scope.js +1 -2
- package/dist/schema/helpers/format-example.js +1 -2
- package/dist/schema/helpers/format-value.js +1 -2
- package/dist/schema/helpers/get-compositions-to-render.js +19 -20
- package/dist/schema/helpers/get-discriminator-values.js +1 -2
- package/dist/schema/helpers/get-enum-values.js +1 -2
- package/dist/schema/helpers/get-property-description.js +1 -2
- package/dist/schema/helpers/get-ref-name.js +1 -2
- package/dist/schema/helpers/get-rendered-example.js +1 -2
- package/dist/schema/helpers/get-schema-type.js +1 -2
- package/dist/schema/helpers/get-type-signature-tokens.d.ts +2 -2
- package/dist/schema/helpers/get-type-signature-tokens.d.ts.map +1 -1
- package/dist/schema/helpers/get-type-signature-tokens.js +3 -4
- package/dist/schema/helpers/get-type-signature-tokens.js.map +1 -1
- package/dist/schema/helpers/has-complex-array-items.js +1 -2
- package/dist/schema/helpers/index.js +13 -13
- package/dist/schema/helpers/is-empty-schema-object.js +1 -2
- package/dist/schema/helpers/is-model-linkable.js +1 -2
- package/dist/schema/helpers/is-on-schema-target-path.js +1 -2
- package/dist/schema/helpers/is-type-object.js +1 -2
- package/dist/schema/helpers/merge-all-of-schemas.js +1 -2
- package/dist/schema/helpers/normalize-object-composition.js +1 -2
- package/dist/schema/helpers/optimize-value-for-display.js +1 -2
- package/dist/schema/helpers/partition-all-of-compositions.js +1 -2
- package/dist/schema/helpers/schema-composition.js +1 -2
- package/dist/schema/helpers/schema-cycle.js +1 -2
- package/dist/schema/helpers/schema-expansion.js +1 -2
- package/dist/schema/helpers/schema-keyboard-nav.js +1 -2
- package/dist/schema/helpers/schema-name.js +2 -3
- package/dist/schema/helpers/schema-name.js.map +1 -1
- package/dist/schema/helpers/should-display-description.js +1 -2
- package/dist/schema/helpers/should-display-heading.js +1 -2
- package/dist/schema/helpers/should-render-array-item-composition.js +1 -2
- package/dist/schema/helpers/sort-property-names.js +1 -2
- package/dist/schema/helpers/unwrap-for-read.js +1 -2
- package/dist/schema/index.js +8 -8
- package/dist/schema/localization/index.js +1 -2
- package/dist/schema/localization/locales/ar.js +1 -2
- package/dist/schema/localization/locales/de.js +1 -2
- package/dist/schema/localization/locales/en.js +1 -2
- package/dist/schema/localization/locales/es.js +1 -2
- package/dist/schema/localization/locales/fr.js +1 -2
- package/dist/schema/localization/locales/pt.js +1 -2
- package/dist/schema/localization/locales/ru.js +1 -2
- package/dist/schema/localization/locales/zh-cn.js +1 -2
- package/dist/schema/localization/locales/zh-tw.js +1 -2
- package/dist/schema/localization/translations.js +1 -2
- package/dist/schema/protobuf-metadata.js +1 -2
- package/dist/schema/recursive-metadata.js +1 -2
- package/dist/schema/request-body-composition-index.js +1 -2
- package/dist/shared/Badge.vue.d.ts.map +1 -1
- package/dist/shared/Badge.vue.js +4 -5
- package/dist/shared/Badge.vue.js.map +1 -1
- package/dist/shared/Badge.vue_vue_type_script_setup_true_lang.js +2 -3
- package/dist/shared/Badge.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/shared/ExternalDocs.vue.js +1 -2
- package/dist/shared/ExternalDocs.vue.js.map +1 -1
- package/dist/shared/ExternalDocs.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/shared/ExternalDocs.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/shared/ScreenReader.vue.js +1 -2
- package/dist/shared/ScreenReader.vue.js.map +1 -1
- package/dist/shared/ScreenReader.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/shared/index.js +4 -4
- package/dist/specification-extensions/ExtensionValue.vue.js +1 -2
- package/dist/specification-extensions/ExtensionValue.vue.js.map +1 -1
- package/dist/specification-extensions/ExtensionValue.vue_vue_type_script_setup_true_lang.js +5 -6
- package/dist/specification-extensions/ExtensionValue.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/specification-extensions/SpecificationExtensions.vue.js +1 -2
- package/dist/specification-extensions/SpecificationExtensions.vue.js.map +1 -1
- package/dist/specification-extensions/SpecificationExtensions.vue_vue_type_script_setup_true_lang.js +1 -2
- package/dist/specification-extensions/SpecificationExtensions.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/style.css +42 -22
- package/dist/vue-styles.css +1 -1
- package/package.json +24 -24
|
@@ -3,15 +3,19 @@ import { buildRequestBody as t, coerceLeafValueToSchemaType as n, getExample as
|
|
|
3
3
|
import { isXmlMediaType as d } from "@scalar/helpers/http/is-xml-media-type";
|
|
4
4
|
import { getExampleValue as f, getExplicitExampleText as p } from "@scalar/workspace-store/helpers/get-example-value";
|
|
5
5
|
import { getResolvedRef as m, mergeSiblingReferences as h } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { getStreamFormat as g } from "@scalar/helpers/http/is-streaming-content-type";
|
|
7
|
+
import { isFileSchema as _ } from "@scalar/workspace-store/helpers/is-file-schema";
|
|
8
|
+
import { serializeStreamExample as v } from "@scalar/workspace-store/helpers/serialize-stream-example";
|
|
9
|
+
import { unpackProxyObject as y } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
10
|
+
import { resolve as b } from "@scalar/workspace-store/resolve";
|
|
11
|
+
import { isArraySchema as x, isObjectSchema as S } from "@scalar/workspace-store/schemas/v3.2/strict/type-guards";
|
|
12
|
+
// src/code-example/helpers/operation-to-har/process-body.ts
|
|
13
|
+
var C = (e, t, n) => ({
|
|
10
14
|
name: e,
|
|
11
15
|
value: `@${t}`,
|
|
12
16
|
fileName: t,
|
|
13
17
|
...n ? { contentType: n } : {}
|
|
14
|
-
}),
|
|
18
|
+
}), w = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", T = (e, t) => typeof e == "string" && e.startsWith("@") && w(t) ? e.slice(1) : void 0, E = (e, t, r, i = !1, a) => {
|
|
15
19
|
let o = [], u = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
|
|
16
20
|
for (let [d, f] of u) {
|
|
17
21
|
if (f == null) continue;
|
|
@@ -19,7 +23,7 @@ var v = (e, t, n) => ({
|
|
|
19
23
|
if (i && !r) {
|
|
20
24
|
let t = Array.isArray(e) ? n(f, s(a, [d])) : f, r = l(d, Array.isArray(t) ? t : f, u);
|
|
21
25
|
if (r) {
|
|
22
|
-
for (let e of r) e.value instanceof File ? o.push(
|
|
26
|
+
for (let e of r) e.value instanceof File ? o.push(C(e.key, e.value.name, e.contentType ?? e.value.type)) : o.push({
|
|
23
27
|
name: e.key,
|
|
24
28
|
value: e.value,
|
|
25
29
|
...e.contentType ? { contentType: e.contentType } : {}
|
|
@@ -27,34 +31,34 @@ var v = (e, t, n) => ({
|
|
|
27
31
|
continue;
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
|
-
let p = u && (u.style !== void 0 || u.explode !== void 0 || u.allowReserved !== void 0), m = p || !i ? void 0 : u?.contentType, h = i && !r ?
|
|
34
|
+
let p = u && (u.style !== void 0 || u.explode !== void 0 || u.allowReserved !== void 0), m = p || !i ? void 0 : u?.contentType, h = i && !r ? T(f, s(a, [d])) : void 0, g = r ? null : c(d, f, u);
|
|
31
35
|
if (g) for (let e of g) o.push({
|
|
32
36
|
name: e.key,
|
|
33
37
|
value: e.value
|
|
34
38
|
});
|
|
35
39
|
else if (f instanceof File) {
|
|
36
|
-
let e =
|
|
37
|
-
o.push(
|
|
38
|
-
} else if (h !== void 0) o.push(
|
|
40
|
+
let e = y(f);
|
|
41
|
+
o.push(C(d, e.name, m ?? (i ? e.type : void 0)));
|
|
42
|
+
} else if (h !== void 0) o.push(C(d, h, m));
|
|
39
43
|
else if (m && typeof f == "object") o.push({
|
|
40
44
|
name: d,
|
|
41
|
-
value: JSON.stringify(
|
|
45
|
+
value: JSON.stringify(y(f)),
|
|
42
46
|
contentType: m
|
|
43
47
|
});
|
|
44
48
|
else if (i && !r && !p && typeof f == "object" && !Array.isArray(f)) o.push({
|
|
45
49
|
name: d,
|
|
46
|
-
value: JSON.stringify(
|
|
50
|
+
value: JSON.stringify(y(f)),
|
|
47
51
|
contentType: "application/json"
|
|
48
52
|
});
|
|
49
53
|
else if (Array.isArray(f)) for (let e of f) if (e instanceof File) {
|
|
50
|
-
let t =
|
|
51
|
-
o.push(
|
|
54
|
+
let t = y(e);
|
|
55
|
+
o.push(C(d, t.name, i ? t.type : void 0));
|
|
52
56
|
} else o.push({
|
|
53
57
|
name: d,
|
|
54
58
|
value: String(e)
|
|
55
59
|
});
|
|
56
60
|
else if (typeof f == "object") {
|
|
57
|
-
let e =
|
|
61
|
+
let e = E(f, void 0, d);
|
|
58
62
|
for (let t of e) o.push({
|
|
59
63
|
name: `${d}.${t.name}`,
|
|
60
64
|
value: t.value
|
|
@@ -66,65 +70,89 @@ var v = (e, t, n) => ({
|
|
|
66
70
|
});
|
|
67
71
|
}
|
|
68
72
|
return o;
|
|
69
|
-
},
|
|
70
|
-
let
|
|
71
|
-
if (
|
|
72
|
-
let e = c ?? Object.keys(
|
|
73
|
+
}, D = ({ requestBody: n, contentType: s, example: c, openapiVersion: l, jsonSchemaDialect: C, requestBodyCompositionSelection: w }) => {
|
|
74
|
+
let T = s || Object.keys(n.content)[0] || "", D = T === "other" ? "" : T, O = (e) => `@${y(e).name || "filename"}`, k = n.content[T]?.encoding, A = n.content[T];
|
|
75
|
+
if (A && o(T, A)) {
|
|
76
|
+
let e = c ?? Object.keys(A.examples ?? {})[0] ?? "default", r = t({
|
|
73
77
|
...n,
|
|
74
|
-
"x-scalar-selected-content-type": { [e]:
|
|
75
|
-
}, e,
|
|
78
|
+
"x-scalar-selected-content-type": { [e]: T }
|
|
79
|
+
}, e, w, l, C);
|
|
76
80
|
if (r?.mode === "multipart") {
|
|
77
81
|
let e = u(r.value, r.contentType);
|
|
78
82
|
return {
|
|
79
83
|
mimeType: e.contentType,
|
|
80
|
-
text: e.chunks.map((e) => e instanceof File ?
|
|
84
|
+
text: e.chunks.map((e) => e instanceof File ? O(e) : e instanceof Blob ? "BINARY" : String(e)).join("")
|
|
81
85
|
};
|
|
82
86
|
}
|
|
83
87
|
}
|
|
84
|
-
let
|
|
85
|
-
if (d(
|
|
86
|
-
let e = i(n,
|
|
88
|
+
let j = T === "multipart/form-data" || T === "application/x-www-form-urlencoded";
|
|
89
|
+
if (d(T)) {
|
|
90
|
+
let e = i(n, T, c ?? "", w, l, C);
|
|
87
91
|
return e ? {
|
|
88
|
-
mimeType:
|
|
92
|
+
mimeType: D,
|
|
89
93
|
text: e.value
|
|
90
94
|
} : void 0;
|
|
91
95
|
}
|
|
92
|
-
let
|
|
93
|
-
if (
|
|
94
|
-
mimeType:
|
|
95
|
-
text:
|
|
96
|
+
let M = f(r(n, c, s)), N = p(M, T);
|
|
97
|
+
if (N !== void 0) return {
|
|
98
|
+
mimeType: D,
|
|
99
|
+
text: N
|
|
96
100
|
};
|
|
97
|
-
let
|
|
98
|
-
if (
|
|
99
|
-
let e = typeof
|
|
100
|
-
return
|
|
101
|
-
mimeType:
|
|
102
|
-
params:
|
|
101
|
+
let P = M?.value;
|
|
102
|
+
if (P !== void 0) {
|
|
103
|
+
let e = typeof P == "object" && P ? y(P) : P;
|
|
104
|
+
return j && typeof e == "object" && e ? {
|
|
105
|
+
mimeType: D,
|
|
106
|
+
params: E(e, k, void 0, T === "multipart/form-data", m(n.content[T]?.schema, h))
|
|
103
107
|
} : e instanceof File ? {
|
|
104
|
-
mimeType:
|
|
105
|
-
text:
|
|
108
|
+
mimeType: D,
|
|
109
|
+
text: O(e)
|
|
106
110
|
} : {
|
|
107
|
-
mimeType:
|
|
108
|
-
text: typeof e == "string" ? e :
|
|
111
|
+
mimeType: D,
|
|
112
|
+
text: typeof e == "string" ? e : v(e, T, !1) ?? JSON.stringify(e)
|
|
109
113
|
};
|
|
110
114
|
}
|
|
111
|
-
let
|
|
112
|
-
if (
|
|
113
|
-
let t =
|
|
114
|
-
|
|
115
|
+
let F = n.content[T], I = m(F?.schema ?? F?.itemSchema);
|
|
116
|
+
if (I !== void 0) {
|
|
117
|
+
let t = e(I);
|
|
118
|
+
if (T === "multipart/form-data" && S(t)) for (let [e, n] of Object.entries(t.properties ?? {})) {
|
|
119
|
+
let r = b.schema(n), i = r && x(r) ? b.schema(r.items) : r;
|
|
120
|
+
if (i && !("type" in i) && !("properties" in i) && !i.allOf && !i.oneOf && !i.anyOf && !i.contentSchema && _(i, !1)) {
|
|
121
|
+
let n = {
|
|
122
|
+
...i,
|
|
123
|
+
type: "string",
|
|
124
|
+
format: "binary"
|
|
125
|
+
};
|
|
126
|
+
t.properties[e] = r && x(r) ? {
|
|
127
|
+
...r,
|
|
128
|
+
items: n
|
|
129
|
+
} : n;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (!j && F?.schema !== void 0 && Object.keys(t).every((e) => [
|
|
133
|
+
"__scalar_",
|
|
134
|
+
"title",
|
|
135
|
+
"description"
|
|
136
|
+
].includes(e)) && !g(T) && _(t, !1, T)) return {
|
|
137
|
+
mimeType: D,
|
|
138
|
+
text: "@filename"
|
|
139
|
+
};
|
|
140
|
+
let n = a(t, {
|
|
141
|
+
compositionSelection: w,
|
|
115
142
|
mode: "write",
|
|
116
|
-
|
|
143
|
+
openapiVersion: l,
|
|
144
|
+
jsonSchemaDialect: C,
|
|
145
|
+
binaryAsFile: T === "multipart/form-data"
|
|
117
146
|
}, { schemaPath: ["requestBody"] });
|
|
118
|
-
if (
|
|
119
|
-
mimeType:
|
|
120
|
-
params:
|
|
147
|
+
if (n !== void 0) return j && typeof n == "object" && n ? {
|
|
148
|
+
mimeType: D,
|
|
149
|
+
params: E(n, k, void 0, T === "multipart/form-data", I)
|
|
121
150
|
} : {
|
|
122
|
-
mimeType:
|
|
123
|
-
text:
|
|
151
|
+
mimeType: D,
|
|
152
|
+
text: v(n, T, F?.schema === void 0) ?? (typeof n == "string" ? n : JSON.stringify(n))
|
|
124
153
|
};
|
|
125
154
|
}
|
|
126
155
|
};
|
|
127
|
-
|
|
128
|
-
export { S as processBody };
|
|
156
|
+
export { D as processBody };
|
|
129
157
|
|
|
130
158
|
//# sourceMappingURL=process-body.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-body.js","names":["buildFileParam","fileName","contentType","isBinarySchema","schema","getBinaryPlaceholderFileName","value","objectToFormParams","params","entries","obj","item","key","partEncoding","parentKey","encoding","isMultipart","restored","coerceLeafValueToSchemaType","resolveLeafSchema","arrayParts","serializeMultipartArray","part","hasFormStyle","explicitContentType","binaryPlaceholderFileName","styleParams","serializeFormPropertyWithEncoding","param","file","unpackProxyObject","nestedParams","processBody","_contentType","requestBody","harMimeType","formatBinaryFile","media","needsMultipartEncoding","exampleName","example","body","buildRequestBody","requestBodyCompositionSelection","encoded","serializeMultipartBody","chunk","isFormData","isXmlMediaType","xmlExample","getExampleFromBody","openapiVersion","selected","getExampleValue","getExample","explicitText","getExplicitExampleText","_example","exampleValue","getResolvedRef","mergeSiblingReferences","serializeStreamExample","mediaType","contentSchema","extractedExample","getExampleFromSchema","snapshotSchema"],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { getExampleValue, getExplicitExampleText } from '@scalar/workspace-store/helpers/get-example-value'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { serializeStreamExample } from '@scalar/workspace-store/helpers/serialize-stream-example'\nimport { snapshotSchema } from '@scalar/workspace-store/helpers/snapshot-schema'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n buildRequestBody,\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromBody,\n getExampleFromSchema,\n needsMultipartEncoding,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n serializeMultipartBody,\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<\n OperationToHarProps,\n 'contentType' | 'example' | 'requestBodyCompositionSelection' | 'openapiVersion'\n> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Builds a HAR param for an uploaded file. `fileName` is what snippet generators read to emit real\n * file handling (for example `files=` in Python or `new Blob` in fetch). `value` keeps the\n * `@filename` placeholder for consumers that only read the text value.\n */\nconst buildFileParam = (name: string, fileName: string, contentType?: string): Param => ({\n name,\n value: `@${fileName}`,\n fileName,\n ...(contentType ? { contentType } : {}),\n})\n\n/** True when the schema describes a binary file (`type: string, format: binary`). */\nconst isBinarySchema = (schema: SchemaObject | undefined): boolean =>\n !!schema && 'type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary'\n\n/**\n * Example generation turns a binary property into the `@filename` placeholder string.\n * Use the schema to tell that apart from a normal text field that happens to start with `@`.\n */\nconst getBinaryPlaceholderFileName = (value: unknown, schema: SchemaObject | undefined): string | undefined =>\n typeof value === 'string' && value.startsWith('@') && isBinarySchema(schema) ? value.slice(1) : undefined\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 if (part.value instanceof File) {\n params.push(buildFileParam(part.key, part.value.name, part.contentType ?? part.value.type))\n continue\n }\n params.push({\n name: part.key,\n value: 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 binaryPlaceholderFileName =\n isMultipart && !parentKey ? getBinaryPlaceholderFileName(value, resolveLeafSchema(schema, [key])) : undefined\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(buildFileParam(key, file.name, explicitContentType ?? (isMultipart ? file.type : undefined)))\n } else if (binaryPlaceholderFileName !== undefined) {\n /** A binary property filled in by example generation, so it is a file and not a text field. */\n params.push(buildFileParam(key, binaryPlaceholderFileName, explicitContentType))\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(buildFileParam(key, file.name, isMultipart ? file.type : undefined))\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 openapiVersion,\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 const media = requestBody.content[_contentType]\n if (media && needsMultipartEncoding(_contentType, media)) {\n const exampleName = example ?? Object.keys(media.examples ?? {})[0] ?? 'default'\n const body = buildRequestBody(\n { ...requestBody, 'x-scalar-selected-content-type': { [exampleName]: _contentType } },\n exampleName,\n requestBodyCompositionSelection,\n )\n if (body?.mode === 'multipart') {\n const encoded = serializeMultipartBody(body.value, body.contentType)\n return {\n mimeType: encoded.contentType,\n // HAR text cannot embed file bytes synchronously. Keep visible file placeholders.\n text: encoded.chunks\n .map((chunk) => {\n if (chunk instanceof File) {\n return formatBinaryFile(chunk)\n }\n return chunk instanceof Blob ? 'BINARY' : String(chunk)\n })\n .join(''),\n }\n }\n }\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 if (isXmlMediaType(_contentType)) {\n const xmlExample = getExampleFromBody(\n requestBody,\n _contentType,\n example ?? '',\n requestBodyCompositionSelection,\n openapiVersion,\n )\n return xmlExample ? { mimeType: harMimeType, text: xmlExample.value as string } : undefined\n }\n\n // Get the example value\n const selected = getExampleValue(getExample(requestBody, example, contentType))\n const explicitText = getExplicitExampleText(selected, _contentType)\n if (explicitText !== undefined) {\n return { mimeType: harMimeType, text: explicitText }\n }\n const _example = selected?.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 (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n typeof exampleValue === 'string'\n ? exampleValue\n : (serializeStreamExample(exampleValue, _contentType, false) ?? JSON.stringify(exampleValue)),\n }\n }\n\n // Try to extract examples from the schema\n const mediaType = requestBody.content[_contentType]\n const contentSchema = getResolvedRef(mediaType?.schema ?? mediaType?.itemSchema)\n if (typeof contentSchema !== 'undefined') {\n const extractedExample = getExampleFromSchema(\n snapshotSchema(contentSchema),\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n binaryAsFile: _contentType === 'multipart/form-data',\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(\n extractedExample,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n contentSchema,\n ),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n serializeStreamExample(extractedExample, _contentType, mediaType?.schema === undefined) ??\n (typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample)),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAyCA,IAAMA,KAAkB,GAAc,GAAkB,OAAiC;CACvF;CACA,OAAO,IAAIC;CACX;CACA,GAAIC,IAAc,EAAE,eAAY,IAAI,CAAC;AACvC,IAGMC,KAAkB,MACtB,CAAC,CAACC,KAAU,UAAUA,KAAUA,EAAO,SAAS,YAAY,YAAYA,KAAUA,EAAO,WAAW,UAMhGC,KAAgC,GAAgB,MACpD,OAAOC,KAAU,YAAYA,EAAM,WAAW,GAAG,KAAKH,EAAeC,CAAM,IAAIE,EAAM,MAAM,CAAC,IAAI,KAAA,GAsB5FC,KACJ,GACA,GACA,GACA,IAAc,IACd,MACY;CACZ,IAAMC,IAAkB,CAAC,GAGnBC,IAA+B,MAAM,QAAQC,CAAG,IAClDA,EAAI,QAAQ,MAAS,CAACC,EAAK,UAAU,CAAC,CA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OApBIV,KAAc,OAAOW,KAAiB,YAAYA,IAC7C;GACL,UAAUvB;GACV,QAAQ5B,EACNmD,GACA3C,GACA,KAAA,GACAkB,MAAiB,uBACjB0B,EAAezB,EAAY,QAAQD,EAAa,EAAE,QAAQ2B,CAAsB,CAClF;EACF,IAGEF,aAAwB,OACnB;GACL,UAAUvB;GACV,MAAMC,EAAiBsB,CAAY;EACrC,IAGK;GACL,UAAUvB;GACV,MACE,OAAOuB,KAAiB,WACpBA,IACCG,EAAuBH,GAAczB,GAAc,EAAK,KAAK,KAAK,UAAUyB,CAAY;EACjG;CACF;CAGA,IAAMI,IAAY5B,EAAY,QAAQD,IAChC8B,IAAgBJ,EAAeG,GAAW,UAAUA,GAAW,UAAU;CAC/E,IAAWC,MAAkB,QAAa;EACxC,IAAMC,IAAmBC,EACvBC,EAAeH,CAAa,GAC5B;GACE,sBAAsBpB;GACtB,MAAM;GACN,cAAcV,MAAiB;EACjC,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI+B,MAAqB,KAAA,GAcvB,OAbIjB,KAAc,OAAOiB,KAAqB,YAAYA,IACjD;GACL,UAAU7B;GACV,QAAQ5B,EACNyD,GACAjD,GACA,KAAA,GACAkB,MAAiB,uBACjB8B,CACF;EACF,IAGK;GACL,UAAU5B;GACV,MACE0B,EAAuBG,GAAkB/B,GAAc6B,GAAW,WAAW,KAAA,CAAS,MACrF,OAAOE,KAAqB,WAAWA,IAAmB,KAAK,UAAUA,CAAgB;EAC9F;CAEJ;AAGF"}
|
|
1
|
+
{"version":3,"file":"process-body.js","names":["buildFileParam","fileName","contentType","isBinarySchema","schema","getBinaryPlaceholderFileName","value","objectToFormParams","params","entries","obj","item","key","partEncoding","parentKey","encoding","isMultipart","restored","coerceLeafValueToSchemaType","resolveLeafSchema","arrayParts","serializeMultipartArray","part","hasFormStyle","explicitContentType","binaryPlaceholderFileName","styleParams","serializeFormPropertyWithEncoding","param","file","unpackProxyObject","nestedParams","processBody","_contentType","requestBody","harMimeType","formatBinaryFile","media","needsMultipartEncoding","exampleName","example","body","buildRequestBody","requestBodyCompositionSelection","openapiVersion","jsonSchemaDialect","encoded","serializeMultipartBody","chunk","isFormData","isXmlMediaType","xmlExample","getExampleFromBody","selected","getExampleValue","getExample","explicitText","getExplicitExampleText","_example","exampleValue","getResolvedRef","mergeSiblingReferences","serializeStreamExample","mediaType","contentSchema","exampleSchema","snapshotSchema","isObjectSchema","name","property","resolved","resolve","isArraySchema","isFileSchema","binary","getStreamFormat","extractedExample","getExampleFromSchema"],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { getStreamFormat } from '@scalar/helpers/http/is-streaming-content-type'\nimport { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { getExampleValue, getExplicitExampleText } from '@scalar/workspace-store/helpers/get-example-value'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { isFileSchema } from '@scalar/workspace-store/helpers/is-file-schema'\nimport { serializeStreamExample } from '@scalar/workspace-store/helpers/serialize-stream-example'\nimport { snapshotSchema } from '@scalar/workspace-store/helpers/snapshot-schema'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n buildRequestBody,\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromBody,\n getExampleFromSchema,\n needsMultipartEncoding,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n serializeMultipartBody,\n} from '@scalar/workspace-store/request-example'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isArraySchema, isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<\n OperationToHarProps,\n 'contentType' | 'example' | 'requestBodyCompositionSelection' | 'openapiVersion' | 'jsonSchemaDialect'\n> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Builds a HAR param for an uploaded file. `fileName` is what snippet generators read to emit real\n * file handling (for example `files=` in Python or `new Blob` in fetch). `value` keeps the\n * `@filename` placeholder for consumers that only read the text value.\n */\nconst buildFileParam = (name: string, fileName: string, contentType?: string): Param => ({\n name,\n value: `@${fileName}`,\n fileName,\n ...(contentType ? { contentType } : {}),\n})\n\n/** True when the schema describes a binary file (`type: string, format: binary`). */\nconst isBinarySchema = (schema: SchemaObject | undefined): boolean =>\n !!schema && 'type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary'\n\n/**\n * Example generation turns a binary property into the `@filename` placeholder string.\n * Use the schema to tell that apart from a normal text field that happens to start with `@`.\n */\nconst getBinaryPlaceholderFileName = (value: unknown, schema: SchemaObject | undefined): string | undefined =>\n typeof value === 'string' && value.startsWith('@') && isBinarySchema(schema) ? value.slice(1) : undefined\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 if (part.value instanceof File) {\n params.push(buildFileParam(part.key, part.value.name, part.contentType ?? part.value.type))\n continue\n }\n params.push({\n name: part.key,\n value: 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 binaryPlaceholderFileName =\n isMultipart && !parentKey ? getBinaryPlaceholderFileName(value, resolveLeafSchema(schema, [key])) : undefined\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(buildFileParam(key, file.name, explicitContentType ?? (isMultipart ? file.type : undefined)))\n } else if (binaryPlaceholderFileName !== undefined) {\n /** A binary property filled in by example generation, so it is a file and not a text field. */\n params.push(buildFileParam(key, binaryPlaceholderFileName, explicitContentType))\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(buildFileParam(key, file.name, isMultipart ? file.type : undefined))\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 openapiVersion,\n jsonSchemaDialect,\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 const media = requestBody.content[_contentType]\n if (media && needsMultipartEncoding(_contentType, media)) {\n const exampleName = example ?? Object.keys(media.examples ?? {})[0] ?? 'default'\n const body = buildRequestBody(\n { ...requestBody, 'x-scalar-selected-content-type': { [exampleName]: _contentType } },\n exampleName,\n requestBodyCompositionSelection,\n openapiVersion,\n jsonSchemaDialect,\n )\n if (body?.mode === 'multipart') {\n const encoded = serializeMultipartBody(body.value, body.contentType)\n return {\n mimeType: encoded.contentType,\n // HAR text cannot embed file bytes synchronously. Keep visible file placeholders.\n text: encoded.chunks\n .map((chunk) => {\n if (chunk instanceof File) {\n return formatBinaryFile(chunk)\n }\n return chunk instanceof Blob ? 'BINARY' : String(chunk)\n })\n .join(''),\n }\n }\n }\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 if (isXmlMediaType(_contentType)) {\n const xmlExample = getExampleFromBody(\n requestBody,\n _contentType,\n example ?? '',\n requestBodyCompositionSelection,\n openapiVersion,\n jsonSchemaDialect,\n )\n return xmlExample ? { mimeType: harMimeType, text: xmlExample.value as string } : undefined\n }\n\n // Get the example value\n const selected = getExampleValue(getExample(requestBody, example, contentType))\n const explicitText = getExplicitExampleText(selected, _contentType)\n if (explicitText !== undefined) {\n return { mimeType: harMimeType, text: explicitText }\n }\n const _example = selected?.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 (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n typeof exampleValue === 'string'\n ? exampleValue\n : (serializeStreamExample(exampleValue, _contentType, false) ?? JSON.stringify(exampleValue)),\n }\n }\n\n // Try to extract examples from the schema\n const mediaType = requestBody.content[_contentType]\n const contentSchema = getResolvedRef(mediaType?.schema ?? mediaType?.itemSchema)\n if (typeof contentSchema !== 'undefined') {\n const exampleSchema = snapshotSchema(contentSchema)\n if (_contentType === 'multipart/form-data' && isObjectSchema(exampleSchema)) {\n // Adapt upgraded upload fields only on the code example's private snapshot.\n // The generator already supports the legacy binary shape, including file arrays.\n for (const [name, property] of Object.entries(exampleSchema.properties ?? {})) {\n const resolved = resolve.schema(property)\n const file = resolved && isArraySchema(resolved) ? resolve.schema(resolved.items) : resolved\n if (\n file &&\n !('type' in file) &&\n !('properties' in file) &&\n !file.allOf &&\n !file.oneOf &&\n !file.anyOf &&\n !file.contentSchema &&\n isFileSchema(file, false)\n ) {\n const binary: SchemaObject = { ...file, type: 'string', format: 'binary' }\n exampleSchema.properties![name] =\n resolved && isArraySchema(resolved) ? { ...resolved, items: binary } : binary\n }\n }\n }\n // A migrated whole-body binary schema is empty. Do not infer files from\n // declared values, constraints, compositions, or schemas for individual stream items.\n const isEmptyBinaryBody =\n !isFormData &&\n mediaType?.schema !== undefined &&\n Object.keys(exampleSchema).every((key) => ['__scalar_', 'title', 'description'].includes(key)) &&\n !getStreamFormat(_contentType) &&\n isFileSchema(exampleSchema, false, _contentType)\n if (isEmptyBinaryBody) {\n return { mimeType: harMimeType, text: '@filename' }\n }\n const extractedExample = getExampleFromSchema(\n exampleSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n openapiVersion,\n jsonSchemaDialect,\n binaryAsFile: _contentType === 'multipart/form-data',\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(\n extractedExample,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n contentSchema,\n ),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n serializeStreamExample(extractedExample, _contentType, mediaType?.schema === undefined) ??\n (typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample)),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAMA,KAAkB,GAAc,GAAkB,OAAiC;CACvF;CACA,OAAO,IAAIC;CACX;CACA,GAAIC,IAAc,EAAE,eAAY,IAAI,CAAC;AACvC,IAGMC,KAAkB,MACtB,CAAC,CAACC,KAAU,UAAUA,KAAUA,EAAO,SAAS,YAAY,YAAYA,KAAUA,EAAO,WAAW,UAMhGC,KAAgC,GAAgB,MACpD,OAAOC,KAAU,YAAYA,EAAM,WAAW,GAAG,KAAKH,EAAeC,CAAM,IAAIE,EAAM,MAAM,CAAC,IAAI,KAAA,GAsB5FC,KACJ,GACA,GACA,GACA,IAAc,IACd,MACY;CACZ,IAAMC,IAAkB,CAAC,GAGn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ACDc,GAAW,WAAW,KAAA,KACtB,OAAO,KAAKE,CAAa,CAAC,CAAC,OAAO,MAAQ;GAAC;GAAa;GAAS;EAAa,CAAC,CAAC,SAASrD,CAAG,CAAC,KAC7F,CAAC+D,EAAgB1C,CAAY,KAC7BwC,EAAaR,GAAe,IAAOhC,CAAY,GAE/C,OAAO;GAAE,UAAUE;GAAa,MAAM;EAAY;EAEpD,IAAMyC,IAAmBC,EACvBZ,GACA;GACE,sBAAsBtB;GACtB,MAAM;GACN;GACA;GACA,cAAcV,MAAiB;EACjC,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI2C,MAAqB,KAAA,GAcvB,OAbI3B,KAAc,OAAO2B,KAAqB,YAAYA,IACjD;GACL,UAAUzC;GACV,QAAQ5B,EACNqE,GACA7D,GACA,KAAA,GACAkB,MAAiB,uBACjB+B,CACF;EACF,IAGK;GACL,UAAU7B;GACV,MACE2B,EAAuBc,GAAkB3C,GAAc8B,GAAW,WAAW,KAAA,CAAS,MACrF,OAAOa,KAAqB,WAAWA,IAAmB,KAAK,UAAUA,CAAgB;EAC9F;CAEJ;AAGF"}
|
|
@@ -19,7 +19,7 @@ type ProcessedParameters = {
|
|
|
19
19
|
*
|
|
20
20
|
* @see https://spec.openapis.org/oas/latest.html#style-values
|
|
21
21
|
*/
|
|
22
|
-
export declare const processParameters: ({ harRequest, parameters, example, defaultDisabled, openapiVersion, }: {
|
|
22
|
+
export declare const processParameters: ({ harRequest, parameters, example, defaultDisabled, openapiVersion, jsonSchemaDialect, }: {
|
|
23
23
|
harRequest: HarRequest;
|
|
24
24
|
parameters: OperationObject["parameters"];
|
|
25
25
|
/** The name of the example to use */
|
|
@@ -28,6 +28,7 @@ export declare const processParameters: ({ harRequest, parameters, example, defa
|
|
|
28
28
|
defaultDisabled: boolean;
|
|
29
29
|
/** Originating API description version. */
|
|
30
30
|
openapiVersion?: string;
|
|
31
|
+
jsonSchemaDialect?: string;
|
|
31
32
|
}) => ProcessedParameters;
|
|
32
33
|
export {};
|
|
33
34
|
//# sourceMappingURL=process-parameters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,8DAA8D,CAAA;AACpH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,wFAAwF;AACxF,qBAAa,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,KAAK,mBAAmB,GAAG;IACzB,6DAA6D;IAC7D,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,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;IAC9B,+EAA+E;IAC/E,qBAAqB,EAAE,OAAO,CAAA;CAC/B,CAAA;
|
|
1
|
+
{"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,8DAA8D,CAAA;AACpH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,wFAAwF;AACxF,qBAAa,wBAAyB,SAAQ,KAAK;CAAG;AAEtD,KAAK,mBAAmB,GAAG;IACzB,6DAA6D;IAC7D,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,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;IAC9B,+EAA+E;IAC/E,qBAAqB,EAAE,OAAO,CAAA;CAC/B,CAAA;AAuGD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,0FAO/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;IACxB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,KAAG,mBA4PH,CAAA"}
|
|
@@ -5,7 +5,7 @@ import { getCookieSerializationError as m } from "@scalar/helpers/http/get-cooki
|
|
|
5
5
|
import { assertReservedPathUrl as h, serializeReservedPathParameter as g } from "@scalar/workspace-store/helpers/encode-path-parameter";
|
|
6
6
|
import { getParameterExample as _ } from "@scalar/workspace-store/helpers/get-parameter-example";
|
|
7
7
|
import { getQuerystringParameter as v, serializeQuerystringParameter as y } from "@scalar/workspace-store/helpers/querystring-parameter";
|
|
8
|
-
|
|
8
|
+
// src/code-example/helpers/operation-to-har/process-parameters.ts
|
|
9
9
|
var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e) => e !== void 0), S = (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, C = (e) => {
|
|
10
10
|
if (e.in === "header") return {
|
|
11
11
|
style: "simple",
|
|
@@ -29,28 +29,36 @@ var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e)
|
|
|
29
29
|
style: n,
|
|
30
30
|
explode: "explode" in e && e.explode !== void 0 ? e.explode : n === "form"
|
|
31
31
|
};
|
|
32
|
-
}, w = (e, a, o) => {
|
|
33
|
-
let
|
|
34
|
-
if (
|
|
35
|
-
if (i(e,
|
|
36
|
-
if (
|
|
32
|
+
}, w = (e, a, o, s, c) => {
|
|
33
|
+
let l = _(e, a), u = l.example, d = e.in === "query" && !l.serialized && !l.mediaSerialized ? u?.["x-scalar-disabled-properties"] : void 0;
|
|
34
|
+
if (d) return n(t(l.value, e), d, i(e, u, o));
|
|
35
|
+
if (i(e, u, o)) return;
|
|
36
|
+
if (l.value !== void 0) return t(l.value, e);
|
|
37
37
|
if (!("schema" in e) || !e.schema) return;
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
let f = {
|
|
39
|
+
openapiVersion: s,
|
|
40
|
+
jsonSchemaDialect: c,
|
|
41
|
+
...e.in === "path" ? { emptyString: `{${e.name}}` } : {}
|
|
42
|
+
}, m = p(e.schema);
|
|
43
|
+
return m ? r(m, f) : void 0;
|
|
44
|
+
}, T = ({ harRequest: e, parameters: t, example: n, defaultDisabled: r, openapiVersion: p, jsonSchemaDialect: T }) => {
|
|
45
|
+
let D = [...e.headers], O = [...e.queryString], k = [...e.cookies], A = [], j = e.url, M = !1, N = [], P = [], F = (e, t, n) => {
|
|
46
|
+
S(n) ? N.push(`${encodeURIComponent(e)}=${t}`) : O.push({
|
|
43
47
|
name: e,
|
|
44
48
|
value: t
|
|
45
49
|
});
|
|
46
|
-
},
|
|
47
|
-
for (let e of
|
|
50
|
+
}, I = x(t);
|
|
51
|
+
for (let e of I) {
|
|
48
52
|
if (!e.in || !e.name) continue;
|
|
49
53
|
if (e.in === "querystring") {
|
|
50
|
-
let t = v(e, n, {
|
|
54
|
+
let t = v(e, n, {
|
|
55
|
+
defaultDisabled: r,
|
|
56
|
+
openapiVersion: p,
|
|
57
|
+
jsonSchemaDialect: T
|
|
58
|
+
});
|
|
51
59
|
if (t) {
|
|
52
|
-
let e =
|
|
53
|
-
|
|
60
|
+
let e = j.indexOf("#"), n = e === -1 ? "" : j.slice(e), r = (e === -1 ? j : j.slice(0, e)).split("?")[0], i = y(t);
|
|
61
|
+
j = `${r}${i ? `?${i}` : ""}${n}`;
|
|
54
62
|
}
|
|
55
63
|
continue;
|
|
56
64
|
}
|
|
@@ -59,18 +67,18 @@ var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e)
|
|
|
59
67
|
let n = String(t.value);
|
|
60
68
|
switch (e.in) {
|
|
61
69
|
case "path":
|
|
62
|
-
|
|
70
|
+
j = j.replaceAll(`{${e.name}}`, () => n);
|
|
63
71
|
break;
|
|
64
72
|
case "query":
|
|
65
|
-
|
|
73
|
+
N.push(n);
|
|
66
74
|
break;
|
|
67
75
|
case "header":
|
|
68
|
-
|
|
76
|
+
D.push({
|
|
69
77
|
name: e.name,
|
|
70
78
|
value: n
|
|
71
79
|
});
|
|
72
80
|
break;
|
|
73
|
-
case "cookie":
|
|
81
|
+
case "cookie": P.push(n);
|
|
74
82
|
}
|
|
75
83
|
continue;
|
|
76
84
|
}
|
|
@@ -78,78 +86,78 @@ var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e)
|
|
|
78
86
|
let n = String(t.value);
|
|
79
87
|
switch (e.in) {
|
|
80
88
|
case "query":
|
|
81
|
-
|
|
89
|
+
F(e.name, n, e);
|
|
82
90
|
break;
|
|
83
91
|
case "header":
|
|
84
|
-
|
|
92
|
+
D.push({
|
|
85
93
|
name: e.name,
|
|
86
94
|
value: n
|
|
87
95
|
});
|
|
88
96
|
break;
|
|
89
97
|
case "path":
|
|
90
|
-
|
|
98
|
+
j = j.replaceAll(`{${e.name}}`, () => encodeURIComponent(n));
|
|
91
99
|
break;
|
|
92
|
-
case "cookie":
|
|
100
|
+
case "cookie": k.push({
|
|
93
101
|
name: e.name,
|
|
94
102
|
value: n
|
|
95
103
|
});
|
|
96
104
|
}
|
|
97
105
|
continue;
|
|
98
106
|
}
|
|
99
|
-
let h = w(e, n, r);
|
|
107
|
+
let h = w(e, n, r, p, T);
|
|
100
108
|
if (h === void 0) continue;
|
|
101
109
|
let { style: x, explode: S } = C(e);
|
|
102
110
|
switch (e.in) {
|
|
103
111
|
case "path": {
|
|
104
112
|
let t = p?.startsWith("3.2.") && "schema" in e && e.allowReserved === !0;
|
|
105
|
-
|
|
113
|
+
M ||= !!t;
|
|
106
114
|
let n = t ? g(e.name, {
|
|
107
115
|
value: h,
|
|
108
116
|
style: x,
|
|
109
117
|
explode: S
|
|
110
118
|
}) : void 0;
|
|
111
|
-
|
|
119
|
+
j = n === void 0 ? E(j, e, h, x, S) : j.replaceAll(`{${e.name}}`, () => n);
|
|
112
120
|
break;
|
|
113
121
|
}
|
|
114
122
|
case "query":
|
|
115
123
|
if ("content" in e && e.content) {
|
|
116
124
|
let t = Object.keys(e.content)[0] ?? "application/json", n = a(h, t);
|
|
117
|
-
|
|
125
|
+
F(e.name, n, e);
|
|
118
126
|
break;
|
|
119
127
|
}
|
|
120
128
|
switch (x) {
|
|
121
129
|
case "form": {
|
|
122
130
|
let t = c(h, S);
|
|
123
|
-
if (Array.isArray(t)) for (let n of t)
|
|
124
|
-
else
|
|
131
|
+
if (Array.isArray(t)) for (let n of t) F(n.key || e.name, String(n.value), e);
|
|
132
|
+
else F(e.name, String(t), e);
|
|
125
133
|
break;
|
|
126
134
|
}
|
|
127
135
|
case "spaceDelimited": {
|
|
128
136
|
let t = f(h);
|
|
129
|
-
|
|
137
|
+
F(e.name, t, e);
|
|
130
138
|
break;
|
|
131
139
|
}
|
|
132
140
|
case "pipeDelimited": {
|
|
133
141
|
let t = u(h);
|
|
134
|
-
|
|
142
|
+
F(e.name, t, e);
|
|
135
143
|
break;
|
|
136
144
|
}
|
|
137
145
|
case "deepObject":
|
|
138
146
|
if (Array.isArray(h)) {
|
|
139
147
|
let t = c(h, !0);
|
|
140
|
-
if (Array.isArray(t)) for (let n of t)
|
|
141
|
-
else
|
|
148
|
+
if (Array.isArray(t)) for (let n of t) F(n.key || e.name, String(n.value), e);
|
|
149
|
+
else F(e.name, String(t), e);
|
|
142
150
|
} else {
|
|
143
151
|
let t = s(e.name, h);
|
|
144
|
-
for (let n of t)
|
|
152
|
+
for (let n of t) F(n.key, n.value, e);
|
|
145
153
|
}
|
|
146
154
|
break;
|
|
147
|
-
default:
|
|
155
|
+
default: F(e.name, String(h), e);
|
|
148
156
|
}
|
|
149
157
|
break;
|
|
150
158
|
case "header": {
|
|
151
159
|
let t = d(h, S);
|
|
152
|
-
|
|
160
|
+
D.push({
|
|
153
161
|
name: e.name,
|
|
154
162
|
value: String(t)
|
|
155
163
|
});
|
|
@@ -159,20 +167,20 @@ var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e)
|
|
|
159
167
|
let [t, n] = (p ?? "").split("."), r = t === "3" && n === "2" && !("content" in e) ? m(e, h) : void 0;
|
|
160
168
|
if (r) throw new b(r);
|
|
161
169
|
if (x === "cookie") {
|
|
162
|
-
|
|
170
|
+
A.push(...o(e.name, h, S));
|
|
163
171
|
break;
|
|
164
172
|
}
|
|
165
173
|
let i = l(h, S);
|
|
166
174
|
if (Array.isArray(i)) for (let t of i) {
|
|
167
175
|
let n = t.key || e.name, r = t.value === null ? "null" : String(t.value);
|
|
168
|
-
|
|
176
|
+
k.push({
|
|
169
177
|
name: n,
|
|
170
178
|
value: r
|
|
171
179
|
});
|
|
172
180
|
}
|
|
173
181
|
else {
|
|
174
182
|
let t = i === null ? "null" : String(i);
|
|
175
|
-
|
|
183
|
+
k.push({
|
|
176
184
|
name: e.name,
|
|
177
185
|
value: t
|
|
178
186
|
});
|
|
@@ -181,31 +189,31 @@ var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e)
|
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
}
|
|
184
|
-
if (
|
|
192
|
+
if (A.length || P.length) {
|
|
185
193
|
let e = [
|
|
186
|
-
...
|
|
187
|
-
...
|
|
188
|
-
...
|
|
189
|
-
].join("; "), t =
|
|
190
|
-
t ?
|
|
194
|
+
...k.map((e) => `${encodeURIComponent(e.name)}=${encodeURIComponent(e.value)}`),
|
|
195
|
+
...A.map((e) => `${e.name}=${e.value}`),
|
|
196
|
+
...P
|
|
197
|
+
].join("; "), t = D.find((e) => e.name.toLowerCase() === "cookie");
|
|
198
|
+
t ? D.splice(D.indexOf(t), 1, {
|
|
191
199
|
...t,
|
|
192
200
|
value: t.value ? `${t.value}; ${e}` : e
|
|
193
|
-
}) :
|
|
201
|
+
}) : D.push({
|
|
194
202
|
name: "Cookie",
|
|
195
203
|
value: e
|
|
196
204
|
});
|
|
197
205
|
}
|
|
198
|
-
if (
|
|
199
|
-
let e =
|
|
200
|
-
|
|
206
|
+
if (N.length) {
|
|
207
|
+
let e = j.indexOf("#"), t = e < 0 ? "" : j.slice(e), n = e < 0 ? j : j.slice(0, e);
|
|
208
|
+
j = `${n}${n.includes("?") ? "&" : "?"}${N.join("&")}${t}`;
|
|
201
209
|
}
|
|
202
|
-
return
|
|
203
|
-
url:
|
|
204
|
-
headers:
|
|
205
|
-
queryString:
|
|
206
|
-
cookies:
|
|
207
|
-
hasCookieStyleEntries:
|
|
208
|
-
...
|
|
210
|
+
return M && h(j), {
|
|
211
|
+
url: j,
|
|
212
|
+
headers: D,
|
|
213
|
+
queryString: O,
|
|
214
|
+
cookies: A.length || P.length ? [] : k,
|
|
215
|
+
hasCookieStyleEntries: A.length > 0 || P.length > 0,
|
|
216
|
+
...N.length ? { hasSerializedQuery: !0 } : {}
|
|
209
217
|
};
|
|
210
218
|
}, E = (t, n, r, i, a) => {
|
|
211
219
|
switch (i) {
|
|
@@ -249,7 +257,6 @@ var b = class extends Error {}, x = (e) => (e ?? []).map((e) => p(e)).filter((e)
|
|
|
249
257
|
default: return t.replace(`{${n.name}}`, String(r));
|
|
250
258
|
}
|
|
251
259
|
};
|
|
252
|
-
//#endregion
|
|
253
260
|
export { b as CookieSerializationError, T as processParameters };
|
|
254
261
|
|
|
255
262
|
//# sourceMappingURL=process-parameters.js.map
|