@scalar/api-client 3.11.0 → 3.13.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.
Files changed (142) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/plugins/posthog/sanitize-event-payload.d.ts.map +1 -1
  3. package/dist/plugins/posthog/sanitize-event-payload.js +1 -0
  4. package/dist/plugins/posthog/sanitize-event-payload.js.map +1 -1
  5. package/dist/style.css +15 -69
  6. package/dist/v2/blocks/operation-block/OperationBlock.vue.d.ts.map +1 -1
  7. package/dist/v2/blocks/operation-block/OperationBlock.vue.js.map +1 -1
  8. package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js +1 -1
  9. package/dist/v2/blocks/operation-block/OperationBlock.vue.script.js.map +1 -1
  10. package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.d.ts.map +1 -1
  11. package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.js +1 -2
  12. package/dist/v2/blocks/operation-block/helpers/validate-path-parameters.js.map +1 -1
  13. package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts +1 -1
  14. package/dist/v2/blocks/request-block/RequestBlock.vue.d.ts.map +1 -1
  15. package/dist/v2/blocks/request-block/RequestBlock.vue.js +1 -1
  16. package/dist/v2/blocks/request-block/RequestBlock.vue.js.map +1 -1
  17. package/dist/v2/blocks/request-block/RequestBlock.vue.script.js +2 -2
  18. package/dist/v2/blocks/request-block/RequestBlock.vue.script.js.map +1 -1
  19. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts +2 -2
  20. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.d.ts.map +1 -1
  21. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.js.map +1 -1
  22. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js +2 -6
  23. package/dist/v2/blocks/request-block/components/RequestCodeSnippet.vue.script.js.map +1 -1
  24. package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.d.ts.map +1 -1
  25. package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.js +17 -3
  26. package/dist/v2/blocks/request-block/helpers/create-parameter-handlers.js.map +1 -1
  27. package/dist/v2/blocks/request-block/helpers/create-parameter-rows.d.ts.map +1 -1
  28. package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js +28 -17
  29. package/dist/v2/blocks/request-block/helpers/create-parameter-rows.js.map +1 -1
  30. package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js +1 -1
  31. package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.script.js.map +1 -1
  32. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts +3 -0
  33. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.d.ts.map +1 -1
  34. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.js.map +1 -1
  35. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js +8 -4
  36. package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue.script.js.map +1 -1
  37. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts +27 -1
  38. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts.map +1 -1
  39. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +30 -5
  40. package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js.map +1 -1
  41. package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.d.ts.map +1 -1
  42. package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js +1 -1
  43. package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js.map +1 -1
  44. package/dist/v2/components/data-table/DataTableInput.vue.d.ts +1 -1
  45. package/dist/v2/components/data-table/DataTableInput.vue.d.ts.map +1 -1
  46. package/dist/v2/constants.js +1 -1
  47. package/dist/v2/features/modal/helpers/create-api-client-modal.js +1 -1
  48. package/dist/v2/features/operation/Operation.vue.script.js +1 -1
  49. package/dist/v2/types/options.d.ts +7 -0
  50. package/dist/v2/types/options.d.ts.map +1 -1
  51. package/dist/v2/workspace-events.d.ts.map +1 -1
  52. package/dist/v2/workspace-events.js +1 -0
  53. package/dist/v2/workspace-events.js.map +1 -1
  54. package/dist/vue-styles.css +6 -48
  55. package/package.json +11 -22
  56. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.d.ts +0 -16
  57. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.d.ts.map +0 -1
  58. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.js +0 -7
  59. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.js.map +0 -1
  60. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.script.js +0 -53
  61. package/dist/v2/blocks/operation-code-sample/components/ExamplePicker.vue.script.js.map +0 -1
  62. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.d.ts +0 -26
  63. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.d.ts.map +0 -1
  64. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.js +0 -7
  65. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.js.map +0 -1
  66. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.script.js +0 -33
  67. package/dist/v2/blocks/operation-code-sample/components/HttpMethod.vue.script.js.map +0 -1
  68. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts +0 -141
  69. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.d.ts.map +0 -1
  70. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js +0 -9
  71. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.js.map +0 -1
  72. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js +0 -272
  73. package/dist/v2/blocks/operation-code-sample/components/OperationCodeSample.vue.script.js.map +0 -1
  74. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.d.ts +0 -9
  75. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.d.ts.map +0 -1
  76. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.js +0 -37
  77. package/dist/v2/blocks/operation-code-sample/helpers/filter-clients-by-query.js.map +0 -1
  78. package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts +0 -41
  79. package/dist/v2/blocks/operation-code-sample/helpers/find-client.d.ts.map +0 -1
  80. package/dist/v2/blocks/operation-code-sample/helpers/find-client.js +0 -48
  81. package/dist/v2/blocks/operation-code-sample/helpers/find-client.js.map +0 -1
  82. package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts +0 -8
  83. package/dist/v2/blocks/operation-code-sample/helpers/format-language.d.ts.map +0 -1
  84. package/dist/v2/blocks/operation-code-sample/helpers/format-language.js +0 -70
  85. package/dist/v2/blocks/operation-code-sample/helpers/format-language.js.map +0 -1
  86. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts +0 -30
  87. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.d.ts.map +0 -1
  88. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js +0 -63
  89. package/dist/v2/blocks/operation-code-sample/helpers/generate-client-options.js.map +0 -1
  90. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts +0 -39
  91. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.d.ts.map +0 -1
  92. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js +0 -38
  93. package/dist/v2/blocks/operation-code-sample/helpers/generate-code-snippet.js.map +0 -1
  94. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts +0 -13
  95. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.d.ts.map +0 -1
  96. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js +0 -37
  97. package/dist/v2/blocks/operation-code-sample/helpers/get-clients.js.map +0 -1
  98. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts +0 -45
  99. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.d.ts.map +0 -1
  100. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js +0 -84
  101. package/dist/v2/blocks/operation-code-sample/helpers/get-custom-code-samples.js.map +0 -1
  102. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.d.ts +0 -27
  103. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.d.ts.map +0 -1
  104. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.js +0 -41
  105. package/dist/v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep.js.map +0 -1
  106. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.d.ts +0 -4
  107. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.d.ts.map +0 -1
  108. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.js +0 -18
  109. package/dist/v2/blocks/operation-code-sample/helpers/get-secrets.js.map +0 -1
  110. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.d.ts +0 -8
  111. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.d.ts.map +0 -1
  112. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.js +0 -38
  113. package/dist/v2/blocks/operation-code-sample/helpers/get-snippet.js.map +0 -1
  114. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts +0 -72
  115. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.d.ts.map +0 -1
  116. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js +0 -114
  117. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/operation-to-har.js.map +0 -1
  118. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts +0 -13
  119. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.d.ts.map +0 -1
  120. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js +0 -196
  121. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.js.map +0 -1
  122. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.d.ts +0 -24
  123. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.d.ts.map +0 -1
  124. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.js +0 -237
  125. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.js.map +0 -1
  126. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.d.ts +0 -15
  127. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.d.ts.map +0 -1
  128. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.js +0 -65
  129. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-security-schemes.js.map +0 -1
  130. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.d.ts +0 -6
  131. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.d.ts.map +0 -1
  132. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.js +0 -19
  133. package/dist/v2/blocks/operation-code-sample/helpers/operation-to-har/process-server-url.js.map +0 -1
  134. package/dist/v2/blocks/operation-code-sample/index.d.ts +0 -9
  135. package/dist/v2/blocks/operation-code-sample/index.d.ts.map +0 -1
  136. package/dist/v2/blocks/operation-code-sample/index.js +0 -8
  137. package/dist/v2/blocks/operation-code-sample/types.d.ts +0 -46
  138. package/dist/v2/blocks/operation-code-sample/types.d.ts.map +0 -1
  139. package/dist/v2/blocks/request-block/helpers/is-param-disabled.d.ts +0 -13
  140. package/dist/v2/blocks/request-block/helpers/is-param-disabled.d.ts.map +0 -1
  141. package/dist/v2/blocks/request-block/helpers/is-param-disabled.js +0 -21
  142. package/dist/v2/blocks/request-block/helpers/is-param-disabled.js.map +0 -1
@@ -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
@@ -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
@@ -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
@@ -1 +0,0 @@
1
- {"version":3,"file":"process-body.js","names":[],"sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { json2xml } from '@scalar/helpers/file/json2xml'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExample,\n getExampleFromSchema,\n serializeFormPropertyWithEncoding,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document'\nimport { getResolvedRefDeep } from '@v2/blocks/operation-code-sample/helpers/get-resolved-ref-deep'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'example' | 'requestBodyCompositionSelection'> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * When only `contentType` is set, the property becomes a single part with that\n * type. Otherwise spec defaults apply (object → `application/json` for multipart,\n * primitives → `text/plain`).\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object/array properties that should become a single `application/json`\n * part. Urlencoded bodies skip those branches and fall through to flattening.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push({\n name: key,\n value: `@${file.name}`,\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push({ name: key, value: `@${file.name}` })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof item === 'object' && item !== null) {\n /**\n * Per OpenAPI 3.x: a top-level multipart array of complex items defaults each part\n * to application/json, instead of flattening object items into dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(item)),\n contentType: 'application/json',\n })\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n const isXml = _contentType === 'application/xml'\n\n // Get the example value\n const _example = getExample(requestBody, example, contentType)?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(exampleValue, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(exampleValue),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof exampleValue === 'string' ? exampleValue : JSON.stringify(exampleValue),\n }\n }\n\n // Try to extract examples from the schema\n const contentSchema = getResolvedRef(requestBody.content[_contentType]?.schema)\n if (typeof contentSchema !== 'undefined') {\n const resolvedContentSchema = getResolvedRefDeep(contentSchema) as SchemaObject\n const extractedExample = getExampleFromSchema(\n resolvedContentSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n xml: isXml,\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(extractedExample, encoding, undefined, _contentType === 'multipart/form-data'),\n }\n }\n\n if (isXml && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n text: json2xml(extractedExample),\n }\n }\n\n return {\n mimeType: harMimeType,\n text: typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":"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"}
@@ -1,24 +0,0 @@
1
- import type { OperationObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
2
- import type { Request as HarRequest } from 'har-format';
3
- type ProcessedParameters = {
4
- url: string;
5
- headers: HarRequest['headers'];
6
- queryString: HarRequest['queryString'];
7
- cookies: HarRequest['cookies'];
8
- };
9
- /**
10
- * Process OpenAPI parameters and return the updated properties.
11
- * Handles path, query, and header parameters with various styles and explode options.
12
- *
13
- * @see https://spec.openapis.org/oas/latest.html#style-values
14
- */
15
- export declare const processParameters: ({ harRequest, parameters, example, defaultDisabled, }: {
16
- harRequest: HarRequest;
17
- parameters: OperationObject["parameters"];
18
- /** The name of the example to use */
19
- example?: string | undefined;
20
- /** Whether to disable parameters by default. */
21
- defaultDisabled: boolean;
22
- }) => ProcessedParameters;
23
- export {};
24
- //# sourceMappingURL=process-parameters.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../../../../src/v2/blocks/operation-code-sample/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,8DAA8D,CAAA;AACpH,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAIvD,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;IACtC,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;CAC/B,CAAA;AA2FD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,uDAK/B;IACD,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,CAAA;IACzC,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,gDAAgD;IAChD,eAAe,EAAE,OAAO,CAAA;CACzB,KAAG,mBAqIH,CAAA"}