@scalar/api-client 3.11.0 → 3.12.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 +13 -0
- package/dist/plugins/posthog/sanitize-event-payload.d.ts.map +1 -1
- package/dist/plugins/posthog/sanitize-event-payload.js +1 -0
- package/dist/plugins/posthog/sanitize-event-payload.js.map +1 -1
- package/dist/style.css +15 -69
- package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.js.map +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js +1 -1
- package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.d.ts.map +1 -1
- package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.js +1 -2
- package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.js.map +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.js +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/RequestBlock.vue.script.js +2 -2
- package/dist/v2/blocks/request-block/RequestBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts +2 -2
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js +2 -6
- package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.js +17 -3
- package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-rows.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js +28 -17
- package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +1 -1
- package/dist/v2/components/data-table/DataTableInput.vue.d.ts +1 -1
- package/dist/v2/components/data-table/DataTableInput.vue.d.ts.map +1 -1
- package/dist/v2/constants.js +1 -1
- package/dist/v2/features/modal/helpers/create-api-client-modal.js +1 -1
- package/dist/v2/features/operation/Operation.vue.script.js +1 -1
- package/dist/v2/workspace-events.d.ts.map +1 -1
- package/dist/v2/workspace-events.js +1 -0
- package/dist/v2/workspace-events.js.map +1 -1
- package/dist/vue-styles.css +6 -48
- package/package.json +11 -22
- package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.d.ts +0 -16
- package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.js +0 -7
- package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.script.js +0 -53
- package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.script.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.d.ts +0 -26
- package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.js +0 -7
- package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.script.js +0 -33
- package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.script.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts +0 -141
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js +0 -9
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js +0 -272
- package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.d.ts +0 -9
- package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.js +0 -37
- package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts +0 -41
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.js +0 -48
- package/dist/v2/blocks/operation-code-sample/helpers/find-client.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts +0 -8
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.js +0 -70
- package/dist/v2/blocks/operation-code-sample/helpers/format-language.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts +0 -30
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js +0 -63
- package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts +0 -39
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js +0 -38
- package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts +0 -13
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js +0 -37
- package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts +0 -45
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js +0 -84
- package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.d.ts +0 -27
- package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.js +0 -41
- package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.d.ts +0 -4
- package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.js +0 -18
- package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.d.ts +0 -8
- package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.js +0 -38
- package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts +0 -72
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js +0 -114
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts +0 -13
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js +0 -196
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.d.ts +0 -24
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.js +0 -237
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.d.ts +0 -15
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.js +0 -65
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.d.ts +0 -6
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.js +0 -19
- package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.js.map +0 -1
- package/dist/v2/blocks/operation-code-sample/index.d.ts +0 -9
- package/dist/v2/blocks/operation-code-sample/index.d.ts.map +0 -1
- package/dist/v2/blocks/operation-code-sample/index.js +0 -8
- package/dist/v2/blocks/operation-code-sample/types.d.ts +0 -46
- package/dist/v2/blocks/operation-code-sample/types.d.ts.map +0 -1
- package/dist/v2/blocks/request-block/helpers/is-param-disabled.d.ts +0 -13
- package/dist/v2/blocks/request-block/helpers/is-param-disabled.d.ts.map +0 -1
- package/dist/v2/blocks/request-block/helpers/is-param-disabled.js +0 -21
- package/dist/v2/blocks/request-block/helpers/is-param-disabled.js.map +0 -1
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type Dereference } from '@scalar/workspace-store/helpers/get-resolved-ref';
|
|
2
|
-
type RefNode<Node> = Partial<Node> & {
|
|
3
|
-
$ref: string;
|
|
4
|
-
'$ref-value': Node | RefNode<Node>;
|
|
5
|
-
};
|
|
6
|
-
type NodeInput<Node> = Node | RefNode<Node>;
|
|
7
|
-
/**
|
|
8
|
-
* Recursively resolves $ref objects
|
|
9
|
-
* This type helper ensures proper typing for deeply nested ref resolution.
|
|
10
|
-
* Properties that could contain $ref objects may resolve to '[circular]' if we have a circular reference.
|
|
11
|
-
*/
|
|
12
|
-
type DeepDereference<T> = Dereference<T> extends T ? T extends readonly (infer U)[] ? DeepDereference<U>[] : T extends object ? {
|
|
13
|
-
[K in keyof T]: T[K] extends RefNode<any> ? DeepDereference<T[K]> | '[circular]' : DeepDereference<T[K]>;
|
|
14
|
-
} : T : Dereference<T> extends object ? {
|
|
15
|
-
[K in keyof Dereference<T>]: Dereference<T>[K] extends RefNode<any> ? DeepDereference<Dereference<T>[K]> | '[circular]' : DeepDereference<Dereference<T>[K]>;
|
|
16
|
-
} : Dereference<T>;
|
|
17
|
-
/**
|
|
18
|
-
* Recursively resolves all $ref objects in a data structure to their actual values.
|
|
19
|
-
* Traverses through objects, arrays, and nested structures to find and resolve
|
|
20
|
-
* any $ref references at any depth level.
|
|
21
|
-
*
|
|
22
|
-
* Handles circular references gracefully by detecting them and returning '[circular]'
|
|
23
|
-
* to prevent infinite loops.
|
|
24
|
-
*/
|
|
25
|
-
export declare const getResolvedRefDeep: <Node>(node: NodeInput<Node>) => DeepDereference<NodeInput<Node>>;
|
|
26
|
-
export {};
|
|
27
|
-
//# sourceMappingURL=get-resolved-ref-deep.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-resolved-ref-deep.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,kDAAkD,CAAA;AAGnG,KAAK,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAA;AACzF,KAAK,SAAS,CAAC,IAAI,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE3C;;;;GAIG;AACH,KAAK,eAAe,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,GAC9C,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC5B,eAAe,CAAC,CAAC,CAAC,EAAE,GACpB,CAAC,SAAS,MAAM,GACd;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GAC5G,CAAC,GACL,WAAW,CAAC,CAAC,CAAC,SAAS,MAAM,GAC3B;KACG,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,GAAG,CAAC,GAC/D,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,GACjD,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvC,GACD,WAAW,CAAC,CAAC,CAAC,CAAA;AAEpB;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,IAAI,EAAE,MAAM,SAAS,CAAC,IAAI,CAAC,KAAG,eAAe,CAAC,SAAS,CAAC,IAAI,CAAC,CA8C/F,CAAA"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
|
-
import { unpackProxyObject } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
3
|
-
import { isObject } from "@scalar/helpers/object/is-object";
|
|
4
|
-
//#region src/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.ts
|
|
5
|
-
/**
|
|
6
|
-
* Recursively resolves all $ref objects in a data structure to their actual values.
|
|
7
|
-
* Traverses through objects, arrays, and nested structures to find and resolve
|
|
8
|
-
* any $ref references at any depth level.
|
|
9
|
-
*
|
|
10
|
-
* Handles circular references gracefully by detecting them and returning '[circular]'
|
|
11
|
-
* to prevent infinite loops.
|
|
12
|
-
*/
|
|
13
|
-
var getResolvedRefDeep = (node) => {
|
|
14
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
15
|
-
const cachedResults = /* @__PURE__ */ new WeakMap();
|
|
16
|
-
const resolveNode = (current) => {
|
|
17
|
-
if (!isObject(current) && !Array.isArray(current)) return current;
|
|
18
|
-
const rawValue = unpackProxyObject(current, { depth: 1 });
|
|
19
|
-
if (cachedResults.has(rawValue)) return cachedResults.get(rawValue);
|
|
20
|
-
if (visited.has(rawValue)) return "[circular]";
|
|
21
|
-
visited.add(rawValue);
|
|
22
|
-
if ("$ref" in current) {
|
|
23
|
-
const result = resolveNode(getResolvedRef(current));
|
|
24
|
-
cachedResults.set(rawValue, result);
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
if (Array.isArray(current)) {
|
|
28
|
-
const result = current.map(resolveNode);
|
|
29
|
-
cachedResults.set(rawValue, result);
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
const result = Object.fromEntries(Object.entries(current).map(([key, value]) => [key, resolveNode(value)]));
|
|
33
|
-
cachedResults.set(rawValue, result);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
return resolveNode(node);
|
|
37
|
-
};
|
|
38
|
-
//#endregion
|
|
39
|
-
export { getResolvedRefDeep };
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=get-resolved-ref-deep.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-resolved-ref-deep.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.ts"],"sourcesContent":["import { isObject } from '@scalar/helpers/object/is-object'\nimport { type Dereference, getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\n\ntype RefNode<Node> = Partial<Node> & { $ref: string; '$ref-value': Node | RefNode<Node> }\ntype NodeInput<Node> = Node | RefNode<Node>\n\n/**\n * Recursively resolves $ref objects\n * This type helper ensures proper typing for deeply nested ref resolution.\n * Properties that could contain $ref objects may resolve to '[circular]' if we have a circular reference.\n */\ntype DeepDereference<T> = Dereference<T> extends T\n ? T extends readonly (infer U)[]\n ? DeepDereference<U>[]\n : T extends object\n ? { [K in keyof T]: T[K] extends RefNode<any> ? DeepDereference<T[K]> | '[circular]' : DeepDereference<T[K]> }\n : T\n : Dereference<T> extends object\n ? {\n [K in keyof Dereference<T>]: Dereference<T>[K] extends RefNode<any>\n ? DeepDereference<Dereference<T>[K]> | '[circular]'\n : DeepDereference<Dereference<T>[K]>\n }\n : Dereference<T>\n\n/**\n * Recursively resolves all $ref objects in a data structure to their actual values.\n * Traverses through objects, arrays, and nested structures to find and resolve\n * any $ref references at any depth level.\n *\n * Handles circular references gracefully by detecting them and returning '[circular]'\n * to prevent infinite loops.\n */\nexport const getResolvedRefDeep = <Node>(node: NodeInput<Node>): DeepDereference<NodeInput<Node>> => {\n const visited = new WeakSet<object>()\n const cachedResults = new WeakMap<object, any>()\n\n const resolveNode = (current: any): any => {\n // Only recurse into objects and arrays; return primitives as-is\n if (!isObject(current) && !Array.isArray(current)) {\n return current\n }\n\n const rawValue = unpackProxyObject(current, { depth: 1 })\n\n // We don't have to recurse into the same object again\n // This helps us having to manually remove the tracked node after we recurse into the tree\n if (cachedResults.has(rawValue)) {\n return cachedResults.get(rawValue)\n }\n\n // Break circular references\n if (visited.has(rawValue)) {\n return '[circular]'\n }\n\n // Track visited nodes\n visited.add(rawValue)\n\n if ('$ref' in current) {\n const resolved = getResolvedRef(current)\n const result = resolveNode(resolved)\n cachedResults.set(rawValue, result)\n return result\n }\n\n // For arrays\n if (Array.isArray(current)) {\n const result = current.map(resolveNode)\n cachedResults.set(rawValue, result)\n return result\n }\n\n const result = Object.fromEntries(Object.entries(current).map(([key, value]) => [key, resolveNode(value)]))\n cachedResults.set(rawValue, result)\n return result\n }\n\n return resolveNode(node)\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,IAAa,sBAA4B,SAA4D;CACnG,MAAM,0BAAU,IAAI,SAAiB;CACrC,MAAM,gCAAgB,IAAI,SAAsB;CAEhD,MAAM,eAAe,YAAsB;AAEzC,MAAI,CAAC,SAAS,QAAQ,IAAI,CAAC,MAAM,QAAQ,QAAQ,CAC/C,QAAO;EAGT,MAAM,WAAW,kBAAkB,SAAS,EAAE,OAAO,GAAG,CAAC;AAIzD,MAAI,cAAc,IAAI,SAAS,CAC7B,QAAO,cAAc,IAAI,SAAS;AAIpC,MAAI,QAAQ,IAAI,SAAS,CACvB,QAAO;AAIT,UAAQ,IAAI,SAAS;AAErB,MAAI,UAAU,SAAS;GAErB,MAAM,SAAS,YADE,eAAe,QAAQ,CACJ;AACpC,iBAAc,IAAI,UAAU,OAAO;AACnC,UAAO;;AAIT,MAAI,MAAM,QAAQ,QAAQ,EAAE;GAC1B,MAAM,SAAS,QAAQ,IAAI,YAAY;AACvC,iBAAc,IAAI,UAAU,OAAO;AACnC,UAAO;;EAGT,MAAM,SAAS,OAAO,YAAY,OAAO,QAAQ,QAAQ,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC;AAC3G,gBAAc,IAAI,UAAU,OAAO;AACnC,SAAO;;AAGT,QAAO,YAAY,KAAK"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example';
|
|
2
|
-
/** Extract secrets from security schemes */
|
|
3
|
-
export declare const getSecrets: (securitySchemes: SecuritySchemeObjectSecret[]) => string[];
|
|
4
|
-
//# sourceMappingURL=get-secrets.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-secrets.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AAGzF,4CAA4C;AAC5C,eAAO,MAAM,UAAU,GAAI,iBAAiB,0BAA0B,EAAE,KAAG,MAAM,EAqB7D,CAAA"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { encode } from "js-base64";
|
|
2
|
-
//#region src/v2/blocks/operation-code-sample/helpers/get-secrets.ts
|
|
3
|
-
/** Extract secrets from security schemes */
|
|
4
|
-
var getSecrets = (securitySchemes) => securitySchemes.flatMap((scheme) => {
|
|
5
|
-
if (scheme.type === "apiKey") return scheme["x-scalar-secret-token"];
|
|
6
|
-
if (scheme?.type === "http") return [
|
|
7
|
-
scheme["x-scalar-secret-token"],
|
|
8
|
-
scheme["x-scalar-secret-username"],
|
|
9
|
-
scheme["x-scalar-secret-password"],
|
|
10
|
-
encode(`${scheme["x-scalar-secret-username"]}:${scheme["x-scalar-secret-password"]}`)
|
|
11
|
-
];
|
|
12
|
-
if (scheme.type === "oauth2") return Object.values(scheme.flows).map((flow) => flow["x-scalar-secret-token"]);
|
|
13
|
-
return [];
|
|
14
|
-
}).filter(Boolean);
|
|
15
|
-
//#endregion
|
|
16
|
-
export { getSecrets };
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=get-secrets.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-secrets.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-secrets.ts"],"sourcesContent":["import type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport { encode } from 'js-base64'\n\n/** Extract secrets from security schemes */\nexport const getSecrets = (securitySchemes: SecuritySchemeObjectSecret[]): string[] =>\n securitySchemes\n .flatMap((scheme) => {\n if (scheme.type === 'apiKey') {\n return scheme['x-scalar-secret-token']\n }\n if (scheme?.type === 'http') {\n return [\n scheme['x-scalar-secret-token'],\n scheme['x-scalar-secret-username'],\n scheme['x-scalar-secret-password'],\n encode(`${scheme['x-scalar-secret-username']}:${scheme['x-scalar-secret-password']}`),\n ]\n }\n if (scheme.type === 'oauth2') {\n const flows = Object.values(scheme.flows)\n return flows.map((flow) => flow['x-scalar-secret-token'])\n }\n\n return []\n })\n .filter(Boolean)\n"],"mappings":";;;AAIA,IAAa,cAAc,oBACzB,gBACG,SAAS,WAAW;AACnB,KAAI,OAAO,SAAS,SAClB,QAAO,OAAO;AAEhB,KAAI,QAAQ,SAAS,OACnB,QAAO;EACL,OAAO;EACP,OAAO;EACP,OAAO;EACP,OAAO,GAAG,OAAO,4BAA4B,GAAG,OAAO,8BAA8B;EACtF;AAEH,KAAI,OAAO,SAAS,SAElB,QADc,OAAO,OAAO,OAAO,MAAM,CAC5B,KAAK,SAAS,KAAK,yBAAyB;AAG3D,QAAO,EAAE;EACT,CACD,OAAO,QAAQ"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error';
|
|
2
|
-
import { type ClientId, type TargetId } from '@scalar/snippetz';
|
|
3
|
-
import type { Request as HarRequest } from 'har-format';
|
|
4
|
-
/**
|
|
5
|
-
* Returns a code example for given operation
|
|
6
|
-
*/
|
|
7
|
-
export declare const getSnippet: <T extends TargetId>(target: T | "javascript", client: ClientId<T>, harRequest: HarRequest) => ErrorResponse<string>;
|
|
8
|
-
//# sourceMappingURL=get-snippet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-snippet.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-snippet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAC3E,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAY,MAAM,kBAAkB,CAAA;AACzE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAKvD;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,QAAQ,EAC3C,QAAQ,CAAC,GAAG,YAAY,EACxB,QAAQ,QAAQ,CAAC,CAAC,CAAC,EACnB,YAAY,UAAU,KACrB,aAAa,CAAC,MAAM,CAyCtB,CAAA"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { snippetz } from "@scalar/snippetz";
|
|
2
|
-
//#region src/v2/blocks/operation-code-sample/helpers/get-snippet.ts
|
|
3
|
-
/** Key used to hack around the invalid urls */
|
|
4
|
-
var INVALID_URLS_PREFIX = "ws://replace.me";
|
|
5
|
-
/**
|
|
6
|
-
* Returns a code example for given operation
|
|
7
|
-
*/
|
|
8
|
-
var getSnippet = (target, client, harRequest) => {
|
|
9
|
-
try {
|
|
10
|
-
if (!harRequest.url) return [/* @__PURE__ */ new Error("Please enter a URL to see a code snippet"), null];
|
|
11
|
-
const separator = harRequest.url.startsWith("/") ? "" : "/";
|
|
12
|
-
try {
|
|
13
|
-
new URL(harRequest.url);
|
|
14
|
-
} catch {
|
|
15
|
-
harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`;
|
|
16
|
-
}
|
|
17
|
-
if (harRequest.postData?.mimeType === "application/json") try {
|
|
18
|
-
JSON.parse(harRequest.postData.text || "{}");
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error("[getSnippet] Invalid JSON body", error);
|
|
21
|
-
return [/* @__PURE__ */ new Error("Invalid JSON body"), null];
|
|
22
|
-
}
|
|
23
|
-
const snippetzTargetKey = target.replace("javascript", "js");
|
|
24
|
-
if (snippetz().hasPlugin(snippetzTargetKey, client)) {
|
|
25
|
-
const payload = snippetz().print(snippetzTargetKey, client, harRequest);
|
|
26
|
-
if (!payload) return [/* @__PURE__ */ new Error("Error generating snippet"), null];
|
|
27
|
-
return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, "")];
|
|
28
|
-
}
|
|
29
|
-
} catch (error) {
|
|
30
|
-
console.error("[getSnippet] Error generating snippet", error);
|
|
31
|
-
return [/* @__PURE__ */ new Error("Error generating snippet"), null];
|
|
32
|
-
}
|
|
33
|
-
return [/* @__PURE__ */ new Error("No snippet found"), null];
|
|
34
|
-
};
|
|
35
|
-
//#endregion
|
|
36
|
-
export { getSnippet };
|
|
37
|
-
|
|
38
|
-
//# sourceMappingURL=get-snippet.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-snippet.js","names":[],"sources":["../../../../../src/v2/blocks/operation-code-sample/helpers/get-snippet.ts"],"sourcesContent":["import type { ErrorResponse } from '@scalar/helpers/errors/normalize-error'\nimport { type ClientId, type TargetId, snippetz } from '@scalar/snippetz'\nimport type { Request as HarRequest } from 'har-format'\n\n/** Key used to hack around the invalid urls */\nconst INVALID_URLS_PREFIX = 'ws://replace.me'\n\n/**\n * Returns a code example for given operation\n */\nexport const getSnippet = <T extends TargetId>(\n target: T | 'javascript',\n client: ClientId<T>,\n harRequest: HarRequest,\n): ErrorResponse<string> => {\n try {\n if (!harRequest.url) {\n return [new Error('Please enter a URL to see a code snippet'), null]\n }\n\n const separator = harRequest.url.startsWith('/') ? '' : '/'\n\n // Hack to get around invalid URLS until we update the snippets lib\n try {\n new URL(harRequest.url)\n } catch {\n harRequest.url = `${INVALID_URLS_PREFIX}${separator}${harRequest.url}`\n }\n\n // Ensure we have valid JSON\n if (harRequest.postData?.mimeType === 'application/json') {\n try {\n JSON.parse(harRequest.postData.text || '{}')\n } catch (error) {\n console.error('[getSnippet] Invalid JSON body', error)\n return [new Error('Invalid JSON body'), null]\n }\n }\n // TODO: Fix this, use js (instead of javascript) everywhere\n const snippetzTargetKey = target.replace('javascript', 'js') as TargetId\n\n if (snippetz().hasPlugin(snippetzTargetKey, client)) {\n const payload = snippetz().print(snippetzTargetKey, client as ClientId<TargetId>, harRequest)\n if (!payload) {\n return [new Error('Error generating snippet'), null]\n }\n\n return [null, payload.replace(`${INVALID_URLS_PREFIX}${separator}`, '')]\n }\n } catch (error) {\n console.error('[getSnippet] Error generating snippet', error)\n return [new Error('Error generating snippet'), null]\n }\n\n return [new Error('No snippet found'), null]\n}\n"],"mappings":";;;AAKA,IAAM,sBAAsB;;;;AAK5B,IAAa,cACX,QACA,QACA,eAC0B;AAC1B,KAAI;AACF,MAAI,CAAC,WAAW,IACd,QAAO,iBAAC,IAAI,MAAM,2CAA2C,EAAE,KAAK;EAGtE,MAAM,YAAY,WAAW,IAAI,WAAW,IAAI,GAAG,KAAK;AAGxD,MAAI;AACF,OAAI,IAAI,WAAW,IAAI;UACjB;AACN,cAAW,MAAM,GAAG,sBAAsB,YAAY,WAAW;;AAInE,MAAI,WAAW,UAAU,aAAa,mBACpC,KAAI;AACF,QAAK,MAAM,WAAW,SAAS,QAAQ,KAAK;WACrC,OAAO;AACd,WAAQ,MAAM,kCAAkC,MAAM;AACtD,UAAO,iBAAC,IAAI,MAAM,oBAAoB,EAAE,KAAK;;EAIjD,MAAM,oBAAoB,OAAO,QAAQ,cAAc,KAAK;AAE5D,MAAI,UAAU,CAAC,UAAU,mBAAmB,OAAO,EAAE;GACnD,MAAM,UAAU,UAAU,CAAC,MAAM,mBAAmB,QAA8B,WAAW;AAC7F,OAAI,CAAC,QACH,QAAO,iBAAC,IAAI,MAAM,2BAA2B,EAAE,KAAK;AAGtD,UAAO,CAAC,MAAM,QAAQ,QAAQ,GAAG,sBAAsB,aAAa,GAAG,CAAC;;UAEnE,OAAO;AACd,UAAQ,MAAM,yCAAyC,MAAM;AAC7D,SAAO,iBAAC,IAAI,MAAM,2BAA2B,EAAE,KAAK;;AAGtD,QAAO,iBAAC,IAAI,MAAM,mBAAmB,EAAE,KAAK"}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import type { HttpMethod } from '@scalar/helpers/http/http-methods';
|
|
2
|
-
import { type SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example';
|
|
3
|
-
import type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies';
|
|
4
|
-
import type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
5
|
-
import type { Request as HarRequest } from 'har-format';
|
|
6
|
-
export type OperationToHarProps = {
|
|
7
|
-
/** OpenAPI Operation object */
|
|
8
|
-
operation: OperationObject;
|
|
9
|
-
/** HTTP method of the operation */
|
|
10
|
-
method: HttpMethod;
|
|
11
|
-
/** Path of the operation */
|
|
12
|
-
path: string;
|
|
13
|
-
/**
|
|
14
|
-
* Name of the currently selected operation example
|
|
15
|
-
*
|
|
16
|
-
* Applies to both the body and the parameters
|
|
17
|
-
*/
|
|
18
|
-
example?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Content type of the operation
|
|
21
|
-
*
|
|
22
|
-
* Applies to both the body and the parameters (if applicable)
|
|
23
|
-
* @defaults to the first content type in the MediaTypeObject
|
|
24
|
-
*/
|
|
25
|
-
contentType?: string;
|
|
26
|
-
/** OpenAPI Server object */
|
|
27
|
-
server?: ServerObject | null;
|
|
28
|
-
/** OpenAPI SecurityScheme objects which are applicable to the operation */
|
|
29
|
-
securitySchemes?: SecuritySchemeObjectSecret[];
|
|
30
|
-
/** Workspace + document cookies */
|
|
31
|
-
globalCookies?: XScalarCookie[];
|
|
32
|
-
/**
|
|
33
|
-
* Whether to include default headers (e.g., Accept, Content-Type) automatically.
|
|
34
|
-
* If false, default headers will be omitted from the HAR request.
|
|
35
|
-
* @default true
|
|
36
|
-
*/
|
|
37
|
-
includeDefaultHeaders?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Selected oneOf/anyOf variants for nested request body example generation
|
|
40
|
-
* (e.g. from the schema dropdowns in the API reference).
|
|
41
|
-
*/
|
|
42
|
-
requestBodyCompositionSelection?: Record<string, number>;
|
|
43
|
-
/**
|
|
44
|
-
* Whether to disable parameters by default.
|
|
45
|
-
* @default false
|
|
46
|
-
*/
|
|
47
|
-
defaultDisabledParameters?: boolean;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.
|
|
51
|
-
*
|
|
52
|
-
* This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,
|
|
53
|
-
* which can be used to generate code snippets for various programming languages and HTTP clients.
|
|
54
|
-
*
|
|
55
|
-
* The conversion handles:
|
|
56
|
-
* - Server URL processing and path parameter substitution
|
|
57
|
-
* - Query parameter formatting based on OpenAPI parameter styles
|
|
58
|
-
* - Request body processing with content type handling
|
|
59
|
-
* - Security scheme integration (API keys, etc.)
|
|
60
|
-
*
|
|
61
|
-
* The resulting HarRequest object follows the HAR specification and includes:
|
|
62
|
-
* - HTTP method and URL
|
|
63
|
-
* - Headers and query parameters
|
|
64
|
-
* - Request body (if present)
|
|
65
|
-
* - Cookie information
|
|
66
|
-
* - Size calculations for headers and body
|
|
67
|
-
*
|
|
68
|
-
* @see https://w3c.github.io/web-performance/specs/HAR/Overview.html
|
|
69
|
-
* @see https://spec.openapis.org/oas/v3.1.0#operation-object
|
|
70
|
-
*/
|
|
71
|
-
export declare const operationToHar: ({ includeDefaultHeaders, operation, contentType, method, path, server, example, securitySchemes, globalCookies, requestBodyCompositionSelection, defaultDisabledParameters, }: OperationToHarProps) => HarRequest;
|
|
72
|
-
//# sourceMappingURL=operation-to-har.d.ts.map
|
package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-to-har.d.ts","sourceRoot":"","sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAEnE,OAAO,EACL,KAAK,0BAA0B,EAIhC,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,8DAA8D,CAAA;AACjH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AASvD,MAAM,MAAM,mBAAmB,GAAG;IAChC,+BAA+B;IAC/B,SAAS,EAAE,eAAe,CAAA;IAC1B,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAA;IAClB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IAC5B,2EAA2E;IAC3E,eAAe,CAAC,EAAE,0BAA0B,EAAE,CAAA;IAC9C,mCAAmC;IACnC,aAAa,CAAC,EAAE,aAAa,EAAE,CAAA;IAC/B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B;;;OAGG;IACH,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxD;;;OAGG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,GAAI,+KAY5B,mBAAmB,KAAG,UAwGxB,CAAA"}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { APP_VERSION } from "../../../../constants.js";
|
|
2
|
-
import { processBody } from "./process-body.js";
|
|
3
|
-
import { processParameters } from "./process-parameters.js";
|
|
4
|
-
import { processSecuritySchemes } from "./process-security-schemes.js";
|
|
5
|
-
import { processServerUrl } from "./process-server-url.js";
|
|
6
|
-
import { filterGlobalCookie, getDefaultHeaders, restoreConventionalDefaultHeaderNames } from "@scalar/workspace-store/request-example";
|
|
7
|
-
import { isElectron } from "@scalar/helpers/general/is-electron";
|
|
8
|
-
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
9
|
-
//#region src/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.ts
|
|
10
|
-
/**
|
|
11
|
-
* Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.
|
|
12
|
-
*
|
|
13
|
-
* This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,
|
|
14
|
-
* which can be used to generate code snippets for various programming languages and HTTP clients.
|
|
15
|
-
*
|
|
16
|
-
* The conversion handles:
|
|
17
|
-
* - Server URL processing and path parameter substitution
|
|
18
|
-
* - Query parameter formatting based on OpenAPI parameter styles
|
|
19
|
-
* - Request body processing with content type handling
|
|
20
|
-
* - Security scheme integration (API keys, etc.)
|
|
21
|
-
*
|
|
22
|
-
* The resulting HarRequest object follows the HAR specification and includes:
|
|
23
|
-
* - HTTP method and URL
|
|
24
|
-
* - Headers and query parameters
|
|
25
|
-
* - Request body (if present)
|
|
26
|
-
* - Cookie information
|
|
27
|
-
* - Size calculations for headers and body
|
|
28
|
-
*
|
|
29
|
-
* @see https://w3c.github.io/web-performance/specs/HAR/Overview.html
|
|
30
|
-
* @see https://spec.openapis.org/oas/v3.1.0#operation-object
|
|
31
|
-
*/
|
|
32
|
-
var operationToHar = ({ includeDefaultHeaders = false, operation, contentType, method, path, server = null, example, securitySchemes, globalCookies, requestBodyCompositionSelection, defaultDisabledParameters = false }) => {
|
|
33
|
-
const defaultHeadersWithConventionalNames = restoreConventionalDefaultHeaderNames(includeDefaultHeaders ? getDefaultHeaders({
|
|
34
|
-
method,
|
|
35
|
-
operation,
|
|
36
|
-
exampleName: example ?? "default",
|
|
37
|
-
hideDisabledHeaders: true,
|
|
38
|
-
hideOverriddenHeaders: true,
|
|
39
|
-
options: {
|
|
40
|
-
isElectron: isElectron(),
|
|
41
|
-
appVersion: APP_VERSION
|
|
42
|
-
}
|
|
43
|
-
}) : {});
|
|
44
|
-
const disabledGlobalCookies = operation["x-scalar-disable-parameters"]?.["global-cookies"]?.[example ?? "default"] ?? {};
|
|
45
|
-
const harRequest = {
|
|
46
|
-
method,
|
|
47
|
-
url: processServerUrl(server, path),
|
|
48
|
-
headers: Object.entries(defaultHeadersWithConventionalNames).map(([name, value]) => ({
|
|
49
|
-
name,
|
|
50
|
-
value
|
|
51
|
-
})),
|
|
52
|
-
queryString: [],
|
|
53
|
-
postData: void 0,
|
|
54
|
-
httpVersion: "HTTP/1.1",
|
|
55
|
-
cookies: [],
|
|
56
|
-
headersSize: -1,
|
|
57
|
-
bodySize: -1
|
|
58
|
-
};
|
|
59
|
-
if (operation.parameters) {
|
|
60
|
-
const { url, headers, queryString, cookies } = processParameters({
|
|
61
|
-
harRequest,
|
|
62
|
-
parameters: operation.parameters,
|
|
63
|
-
example,
|
|
64
|
-
defaultDisabled: defaultDisabledParameters
|
|
65
|
-
});
|
|
66
|
-
const filteredGlobalCookies = globalCookies?.filter((cookie) => filterGlobalCookie({
|
|
67
|
-
cookie,
|
|
68
|
-
url,
|
|
69
|
-
disabledGlobalCookies
|
|
70
|
-
}))?.map((cookie) => ({
|
|
71
|
-
name: cookie.name,
|
|
72
|
-
value: cookie.value
|
|
73
|
-
})) ?? [];
|
|
74
|
-
harRequest.url = url;
|
|
75
|
-
harRequest.headers = headers;
|
|
76
|
-
harRequest.queryString = queryString;
|
|
77
|
-
harRequest.cookies = [...filteredGlobalCookies, ...cookies];
|
|
78
|
-
}
|
|
79
|
-
const body = getResolvedRef(operation.requestBody);
|
|
80
|
-
if (body?.content) {
|
|
81
|
-
const postData = processBody({
|
|
82
|
-
requestBody: body,
|
|
83
|
-
contentType,
|
|
84
|
-
example,
|
|
85
|
-
requestBodyCompositionSelection
|
|
86
|
-
});
|
|
87
|
-
if (postData) {
|
|
88
|
-
harRequest.postData = postData;
|
|
89
|
-
harRequest.bodySize = postData.text?.length ?? -1;
|
|
90
|
-
if (postData.mimeType) {
|
|
91
|
-
const existingContentTypeHeader = harRequest.headers.find((header) => header.name.toLowerCase() === "content-type");
|
|
92
|
-
if (existingContentTypeHeader && !existingContentTypeHeader.value) existingContentTypeHeader.value = postData.mimeType;
|
|
93
|
-
else if (!existingContentTypeHeader) harRequest.headers.push({
|
|
94
|
-
name: "Content-Type",
|
|
95
|
-
value: postData.mimeType
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (securitySchemes) {
|
|
101
|
-
const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes);
|
|
102
|
-
harRequest.headers.push(...headers);
|
|
103
|
-
harRequest.queryString.push(...queryString);
|
|
104
|
-
harRequest.cookies.push(...cookies);
|
|
105
|
-
}
|
|
106
|
-
let headersSize = 0;
|
|
107
|
-
for (const h of harRequest.headers) headersSize += (h.name?.length ?? 0) + 2 + (h.value?.length ?? 0) + 2;
|
|
108
|
-
harRequest.headersSize = headersSize;
|
|
109
|
-
return harRequest;
|
|
110
|
-
};
|
|
111
|
-
//#endregion
|
|
112
|
-
export { operationToHar };
|
|
113
|
-
|
|
114
|
-
//# sourceMappingURL=operation-to-har.js.map
|
package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation-to-har.js","names":[],"sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.ts"],"sourcesContent":["import { isElectron } from '@scalar/helpers/general/is-electron'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n type SecuritySchemeObjectSecret,\n filterGlobalCookie,\n getDefaultHeaders,\n restoreConventionalDefaultHeaderNames,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { APP_VERSION } from '@/v2/constants'\n\nimport { processBody } from './process-body'\nimport { processParameters } from './process-parameters'\nimport { processSecuritySchemes } from './process-security-schemes'\nimport { processServerUrl } from './process-server-url'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: OperationObject\n /** HTTP method of the operation */\n method: HttpMethod\n /** Path of the operation */\n path: string\n /**\n * Name of the currently selected operation example\n *\n * Applies to both the body and the parameters\n */\n example?: string\n /**\n * Content type of the operation\n *\n * Applies to both the body and the parameters (if applicable)\n * @defaults to the first content type in the MediaTypeObject\n */\n contentType?: string\n /** OpenAPI Server object */\n server?: ServerObject | null\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /** Workspace + document cookies */\n globalCookies?: XScalarCookie[]\n /**\n * Whether to include default headers (e.g., Accept, Content-Type) automatically.\n * If false, default headers will be omitted from the HAR request.\n * @default true\n */\n includeDefaultHeaders?: boolean\n /**\n * Selected oneOf/anyOf variants for nested request body example generation\n * (e.g. from the schema dropdowns in the API reference).\n */\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Whether to disable parameters by default.\n * @default false\n */\n defaultDisabledParameters?: boolean\n}\n\n/**\n * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.\n *\n * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,\n * which can be used to generate code snippets for various programming languages and HTTP clients.\n *\n * The conversion handles:\n * - Server URL processing and path parameter substitution\n * - Query parameter formatting based on OpenAPI parameter styles\n * - Request body processing with content type handling\n * - Security scheme integration (API keys, etc.)\n *\n * The resulting HarRequest object follows the HAR specification and includes:\n * - HTTP method and URL\n * - Headers and query parameters\n * - Request body (if present)\n * - Cookie information\n * - Size calculations for headers and body\n *\n * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html\n * @see https://spec.openapis.org/oas/v3.1.0#operation-object\n */\nexport const operationToHar = ({\n includeDefaultHeaders = false,\n operation,\n contentType,\n method,\n path,\n server = null,\n example,\n securitySchemes,\n globalCookies,\n requestBodyCompositionSelection,\n defaultDisabledParameters = false,\n}: OperationToHarProps): HarRequest => {\n const defaultHeaders = includeDefaultHeaders\n ? getDefaultHeaders({\n method,\n operation,\n exampleName: example ?? 'default',\n hideDisabledHeaders: true,\n hideOverriddenHeaders: true,\n options: { isElectron: isElectron(), appVersion: APP_VERSION },\n })\n : {}\n const defaultHeadersWithConventionalNames = restoreConventionalDefaultHeaderNames(defaultHeaders)\n\n const disabledGlobalCookies =\n operation['x-scalar-disable-parameters']?.['global-cookies']?.[example ?? 'default'] ?? {}\n\n const serverUrl = processServerUrl(server, path)\n\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: serverUrl,\n headers: Object.entries(defaultHeadersWithConventionalNames).map(([name, value]) => ({ name, value })),\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n // Handle parameters\n if (operation.parameters) {\n const { url, headers, queryString, cookies } = processParameters({\n harRequest,\n parameters: operation.parameters,\n example,\n defaultDisabled: defaultDisabledParameters,\n })\n\n // Correctly filter the global cookies by the processed url\n const filteredGlobalCookies =\n globalCookies\n ?.filter((cookie) => filterGlobalCookie({ cookie, url, disabledGlobalCookies }))\n ?.map((cookie) => ({ name: cookie.name, value: cookie.value })) ?? []\n\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n harRequest.cookies = [...filteredGlobalCookies, ...cookies]\n }\n\n const body = getResolvedRef(operation.requestBody)\n\n // Handle request body\n if (body?.content) {\n const postData = processBody({\n requestBody: body,\n contentType,\n example,\n requestBodyCompositionSelection,\n })\n\n if (postData) {\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\n\n // Add or update Content-Type header\n if (postData.mimeType) {\n const existingContentTypeHeader = harRequest.headers.find(\n (header) => header.name.toLowerCase() === 'content-type',\n )\n // Update existing header if it has an empty value\n if (existingContentTypeHeader && !existingContentTypeHeader.value) {\n existingContentTypeHeader.value = postData.mimeType\n }\n // Add new header if none exists\n else if (!existingContentTypeHeader) {\n harRequest.headers.push({\n name: 'Content-Type',\n value: postData.mimeType,\n })\n }\n }\n }\n }\n\n // Handle security schemes\n if (securitySchemes) {\n const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes)\n harRequest.headers.push(...headers)\n harRequest.queryString.push(...queryString)\n harRequest.cookies.push(...cookies)\n }\n\n // Calculate headers size without allocating a large joined string\n let headersSize = 0\n for (const h of harRequest.headers) {\n // name + \": \" + value + \"\\r\\n\"\n headersSize += (h.name?.length ?? 0) + 2 + (h.value?.length ?? 0) + 2\n }\n harRequest.headersSize = headersSize\n\n return harRequest\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,IAAa,kBAAkB,EAC7B,wBAAwB,OACxB,WACA,aACA,QACA,MACA,SAAS,MACT,SACA,iBACA,eACA,iCACA,4BAA4B,YACS;CAWrC,MAAM,sCAAsC,sCAVrB,wBACnB,kBAAkB;EAChB;EACA;EACA,aAAa,WAAW;EACxB,qBAAqB;EACrB,uBAAuB;EACvB,SAAS;GAAE,YAAY,YAAY;GAAE,YAAY;GAAa;EAC/D,CAAC,GACF,EAAE,CAC2F;CAEjG,MAAM,wBACJ,UAAU,iCAAiC,oBAAoB,WAAW,cAAc,EAAE;CAK5F,MAAM,aAAyB;EAC7B;EACA,KALgB,iBAAiB,QAAQ,KAAK;EAM9C,SAAS,OAAO,QAAQ,oCAAoC,CAAC,KAAK,CAAC,MAAM,YAAY;GAAE;GAAM;GAAO,EAAE;EACtG,aAAa,EAAE;EACf,UAAU,KAAA;EACV,aAAa;EACb,SAAS,EAAE;EACX,aAAa;EACb,UAAU;EACX;AAGD,KAAI,UAAU,YAAY;EACxB,MAAM,EAAE,KAAK,SAAS,aAAa,YAAY,kBAAkB;GAC/D;GACA,YAAY,UAAU;GACtB;GACA,iBAAiB;GAClB,CAAC;EAGF,MAAM,wBACJ,eACI,QAAQ,WAAW,mBAAmB;GAAE;GAAQ;GAAK;GAAuB,CAAC,CAAC,EAC9E,KAAK,YAAY;GAAE,MAAM,OAAO;GAAM,OAAO,OAAO;GAAO,EAAE,IAAI,EAAE;AAEzE,aAAW,MAAM;AACjB,aAAW,UAAU;AACrB,aAAW,cAAc;AACzB,aAAW,UAAU,CAAC,GAAG,uBAAuB,GAAG,QAAQ;;CAG7D,MAAM,OAAO,eAAe,UAAU,YAAY;AAGlD,KAAI,MAAM,SAAS;EACjB,MAAM,WAAW,YAAY;GAC3B,aAAa;GACb;GACA;GACA;GACD,CAAC;AAEF,MAAI,UAAU;AACZ,cAAW,WAAW;AACtB,cAAW,WAAW,SAAS,MAAM,UAAU;AAG/C,OAAI,SAAS,UAAU;IACrB,MAAM,4BAA4B,WAAW,QAAQ,MAClD,WAAW,OAAO,KAAK,aAAa,KAAK,eAC3C;AAED,QAAI,6BAA6B,CAAC,0BAA0B,MAC1D,2BAA0B,QAAQ,SAAS;aAGpC,CAAC,0BACR,YAAW,QAAQ,KAAK;KACtB,MAAM;KACN,OAAO,SAAS;KACjB,CAAC;;;;AAOV,KAAI,iBAAiB;EACnB,MAAM,EAAE,SAAS,aAAa,YAAY,uBAAuB,gBAAgB;AACjF,aAAW,QAAQ,KAAK,GAAG,QAAQ;AACnC,aAAW,YAAY,KAAK,GAAG,YAAY;AAC3C,aAAW,QAAQ,KAAK,GAAG,QAAQ;;CAIrC,IAAI,cAAc;AAClB,MAAK,MAAM,KAAK,WAAW,QAEzB,iBAAgB,EAAE,MAAM,UAAU,KAAK,KAAK,EAAE,OAAO,UAAU,KAAK;AAEtE,YAAW,cAAc;AAEzB,QAAO"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { RequestBodyObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
|
|
2
|
-
import type { PostData } from 'har-format';
|
|
3
|
-
import type { OperationToHarProps } from './operation-to-har.js';
|
|
4
|
-
type ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example' | 'requestBodyCompositionSelection'> & {
|
|
5
|
-
requestBody: RequestBodyObject;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Processes the request body and returns the processed data
|
|
9
|
-
* Returns undefined if no example is found
|
|
10
|
-
*/
|
|
11
|
-
export declare const processBody: ({ requestBody, contentType, example, requestBodyCompositionSelection, }: ProcessBodyProps) => PostData | undefined;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=process-body.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AAErE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,SAAS,GAAG,iCAAiC,CAAC,GAAG;IACjH,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AAyJD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yEAKzB,gBAAgB,KAAG,QAAQ,GAAG,SAyFhC,CAAA"}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { getResolvedRefDeep } from "../get-resolved-ref-deep.js";
|
|
2
|
-
import { getExample, getExampleFromSchema, serializeFormPropertyWithEncoding } from "@scalar/workspace-store/request-example";
|
|
3
|
-
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
4
|
-
import { json2xml } from "@scalar/helpers/file/json2xml";
|
|
5
|
-
import { unpackProxyObject } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
6
|
-
//#region src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.ts
|
|
7
|
-
/**
|
|
8
|
-
* Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`
|
|
9
|
-
* and `application/x-www-form-urlencoded` requests.
|
|
10
|
-
*
|
|
11
|
-
* Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed
|
|
12
|
-
* by an optional Encoding entry. When `style` / `explode` / `allowReserved` is
|
|
13
|
-
* set, the value is serialized RFC6570-style and `contentType` is ignored.
|
|
14
|
-
* When only `contentType` is set, the property becomes a single part with that
|
|
15
|
-
* type. Otherwise spec defaults apply (object → `application/json` for multipart,
|
|
16
|
-
* primitives → `text/plain`).
|
|
17
|
-
*
|
|
18
|
-
* @param obj - The form-data payload, either an object keyed by property name
|
|
19
|
-
* or a HAR-style `{ name, value, isDisabled }[]` array.
|
|
20
|
-
* @param encoding - The `encoding` map from the Media Type Object, if any.
|
|
21
|
-
* Used only at the top level (`parentKey` undefined).
|
|
22
|
-
* @param parentKey - When set, we are flattening a nested object inside another
|
|
23
|
-
* property; encoding is ignored and keys are joined with `.` (legacy default).
|
|
24
|
-
* @param isMultipart - True for `multipart/form-data`. Gates the spec defaults
|
|
25
|
-
* for object/array properties that should become a single `application/json`
|
|
26
|
-
* part. Urlencoded bodies skip those branches and fall through to flattening.
|
|
27
|
-
*/
|
|
28
|
-
var objectToFormParams = (obj, encoding, parentKey, isMultipart = false) => {
|
|
29
|
-
const params = [];
|
|
30
|
-
/** Ensure we do not include disabled items */
|
|
31
|
-
const entries = Array.isArray(obj) ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value]) : Object.entries(obj);
|
|
32
|
-
for (const [key, value] of entries) {
|
|
33
|
-
if (value === void 0 || value === null) continue;
|
|
34
|
-
const partEncoding = parentKey ? void 0 : encoding?.[key];
|
|
35
|
-
/**
|
|
36
|
-
* Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the
|
|
37
|
-
* encoding entry, contentType (implicit or explicit) is ignored and the value is
|
|
38
|
-
* serialized as if it were a query-style parameter.
|
|
39
|
-
*/
|
|
40
|
-
const hasFormStyle = partEncoding && (partEncoding.style !== void 0 || partEncoding.explode !== void 0 || partEncoding.allowReserved !== void 0);
|
|
41
|
-
/**
|
|
42
|
-
* Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body
|
|
43
|
-
* media type is not a multipart. For `application/x-www-form-urlencoded` we still
|
|
44
|
-
* honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only
|
|
45
|
-
* entry has no effect — values fall through to the dotted-key flattening default.
|
|
46
|
-
*/
|
|
47
|
-
const explicitContentType = hasFormStyle || !isMultipart ? void 0 : partEncoding?.contentType;
|
|
48
|
-
/**
|
|
49
|
-
* When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style
|
|
50
|
-
* (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`
|
|
51
|
-
* for the per-style rules; it returns null for primitives, Files, and arrays of Files, which
|
|
52
|
-
* then fall through to the dedicated branches below. HAR represents multipart and urlencoded
|
|
53
|
-
* the same way via `PostData.params`, so the resulting parts work for both.
|
|
54
|
-
*/
|
|
55
|
-
const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding);
|
|
56
|
-
if (styleParams) for (const param of styleParams) params.push({
|
|
57
|
-
name: param.key,
|
|
58
|
-
value: param.value
|
|
59
|
-
});
|
|
60
|
-
else if (value instanceof File) {
|
|
61
|
-
/**
|
|
62
|
-
* File values render as `@filename` references, the conventional cURL syntax for an
|
|
63
|
-
* attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).
|
|
64
|
-
*/
|
|
65
|
-
const file = unpackProxyObject(value);
|
|
66
|
-
params.push({
|
|
67
|
-
name: key,
|
|
68
|
-
value: `@${file.name}`,
|
|
69
|
-
...explicitContentType ? { contentType: explicitContentType } : {}
|
|
70
|
-
});
|
|
71
|
-
} else if (explicitContentType && typeof value === "object")
|
|
72
|
-
/**
|
|
73
|
-
* Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a
|
|
74
|
-
* complex value overrides the default and emits a single part containing the value
|
|
75
|
-
* JSON-stringified into that media type. Only reachable when style/explode/allowReserved
|
|
76
|
-
* are unset (otherwise contentType is ignored — see the style branch above).
|
|
77
|
-
*/
|
|
78
|
-
params.push({
|
|
79
|
-
name: key,
|
|
80
|
-
value: JSON.stringify(unpackProxyObject(value)),
|
|
81
|
-
contentType: explicitContentType
|
|
82
|
-
});
|
|
83
|
-
else if (isMultipart && !parentKey && !hasFormStyle && typeof value === "object" && !Array.isArray(value))
|
|
84
|
-
/**
|
|
85
|
-
* Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)
|
|
86
|
-
* defaults to a single part encoded as application/json, rather than being flattened
|
|
87
|
-
* into multiple parts with dotted keys.
|
|
88
|
-
*/
|
|
89
|
-
params.push({
|
|
90
|
-
name: key,
|
|
91
|
-
value: JSON.stringify(unpackProxyObject(value)),
|
|
92
|
-
contentType: "application/json"
|
|
93
|
-
});
|
|
94
|
-
else if (Array.isArray(value)) for (const item of value) if (item instanceof File) {
|
|
95
|
-
const file = unpackProxyObject(item);
|
|
96
|
-
params.push({
|
|
97
|
-
name: key,
|
|
98
|
-
value: `@${file.name}`
|
|
99
|
-
});
|
|
100
|
-
} else if (isMultipart && !parentKey && !hasFormStyle && typeof item === "object" && item !== null)
|
|
101
|
-
/**
|
|
102
|
-
* Per OpenAPI 3.x: a top-level multipart array of complex items defaults each part
|
|
103
|
-
* to application/json, instead of flattening object items into dotted keys.
|
|
104
|
-
*/
|
|
105
|
-
params.push({
|
|
106
|
-
name: key,
|
|
107
|
-
value: JSON.stringify(unpackProxyObject(item)),
|
|
108
|
-
contentType: "application/json"
|
|
109
|
-
});
|
|
110
|
-
else params.push({
|
|
111
|
-
name: key,
|
|
112
|
-
value: String(item)
|
|
113
|
-
});
|
|
114
|
-
else if (typeof value === "object") {
|
|
115
|
-
/**
|
|
116
|
-
* Legacy fallback: flatten nested objects into dotted-key parts. Reached when the
|
|
117
|
-
* multipart JSON-default branches above don't apply — i.e. either inside a recursive
|
|
118
|
-
* call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an
|
|
119
|
-
* explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as
|
|
120
|
-
* the urlencoded default (inner keys become top-level params); we keep dotted keys for
|
|
121
|
-
* backwards compatibility with consumers that already parse this shape.
|
|
122
|
-
*/
|
|
123
|
-
const nestedParams = objectToFormParams(value, void 0, key);
|
|
124
|
-
for (const param of nestedParams) params.push({
|
|
125
|
-
name: `${key}.${param.name}`,
|
|
126
|
-
value: param.value
|
|
127
|
-
});
|
|
128
|
-
} else params.push({
|
|
129
|
-
name: key,
|
|
130
|
-
value: String(value),
|
|
131
|
-
...explicitContentType ? { contentType: explicitContentType } : {}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
return params;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* Processes the request body and returns the processed data
|
|
138
|
-
* Returns undefined if no example is found
|
|
139
|
-
*/
|
|
140
|
-
var processBody = ({ requestBody, contentType, example, requestBodyCompositionSelection }) => {
|
|
141
|
-
const _contentType = contentType || Object.keys(requestBody.content)[0] || "";
|
|
142
|
-
/** Empty when "Other" is selected so snippets do not inject `Content-Type: other`. */
|
|
143
|
-
const harMimeType = _contentType === "other" ? "" : _contentType;
|
|
144
|
-
const formatBinaryFile = (file) => {
|
|
145
|
-
return `@${unpackProxyObject(file).name || "filename"}`;
|
|
146
|
-
};
|
|
147
|
-
const encoding = requestBody.content[_contentType]?.encoding;
|
|
148
|
-
const isFormData = _contentType === "multipart/form-data" || _contentType === "application/x-www-form-urlencoded";
|
|
149
|
-
const isXml = _contentType === "application/xml";
|
|
150
|
-
const _example = getExample(requestBody, example, contentType)?.value;
|
|
151
|
-
if (typeof _example !== "undefined") {
|
|
152
|
-
const exampleValue = _example !== null && typeof _example === "object" ? unpackProxyObject(_example) : _example;
|
|
153
|
-
if (isFormData && typeof exampleValue === "object" && exampleValue !== null) return {
|
|
154
|
-
mimeType: harMimeType,
|
|
155
|
-
params: objectToFormParams(exampleValue, encoding, void 0, _contentType === "multipart/form-data")
|
|
156
|
-
};
|
|
157
|
-
if (isXml && typeof exampleValue === "object" && exampleValue !== null) return {
|
|
158
|
-
mimeType: harMimeType,
|
|
159
|
-
text: json2xml(exampleValue)
|
|
160
|
-
};
|
|
161
|
-
if (exampleValue instanceof File) return {
|
|
162
|
-
mimeType: harMimeType,
|
|
163
|
-
text: formatBinaryFile(exampleValue)
|
|
164
|
-
};
|
|
165
|
-
return {
|
|
166
|
-
mimeType: harMimeType,
|
|
167
|
-
text: typeof exampleValue === "string" ? exampleValue : JSON.stringify(exampleValue)
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
const contentSchema = getResolvedRef(requestBody.content[_contentType]?.schema);
|
|
171
|
-
if (typeof contentSchema !== "undefined") {
|
|
172
|
-
const extractedExample = getExampleFromSchema(getResolvedRefDeep(contentSchema), {
|
|
173
|
-
compositionSelection: requestBodyCompositionSelection,
|
|
174
|
-
mode: "write",
|
|
175
|
-
xml: isXml
|
|
176
|
-
}, { schemaPath: ["requestBody"] });
|
|
177
|
-
if (extractedExample !== void 0) {
|
|
178
|
-
if (isFormData && typeof extractedExample === "object" && extractedExample !== null) return {
|
|
179
|
-
mimeType: harMimeType,
|
|
180
|
-
params: objectToFormParams(extractedExample, encoding, void 0, _contentType === "multipart/form-data")
|
|
181
|
-
};
|
|
182
|
-
if (isXml && typeof extractedExample === "object" && extractedExample !== null) return {
|
|
183
|
-
mimeType: harMimeType,
|
|
184
|
-
text: json2xml(extractedExample)
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
mimeType: harMimeType,
|
|
188
|
-
text: typeof extractedExample === "string" ? extractedExample : JSON.stringify(extractedExample)
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
//#endregion
|
|
194
|
-
export { processBody };
|
|
195
|
-
|
|
196
|
-
//# sourceMappingURL=process-body.js.map
|