@scalar/oas-utils 0.4.4 → 0.4.6

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 (47) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/entities/spec/operation.d.ts +10 -10
  3. package/dist/entities/spec/parameters.d.ts +2 -2
  4. package/dist/entities/spec/request-examples.d.ts +8 -8
  5. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  6. package/dist/entities/spec/request-examples.js +1 -1
  7. package/dist/entities/spec/request-examples.js.map +2 -2
  8. package/dist/entities/spec/requests.d.ts +20 -20
  9. package/dist/helpers/operation-to-har/index.d.ts +2 -0
  10. package/dist/helpers/operation-to-har/index.d.ts.map +1 -0
  11. package/dist/helpers/operation-to-har/index.js +5 -0
  12. package/dist/helpers/operation-to-har/index.js.map +7 -0
  13. package/dist/helpers/operation-to-har/operation-to-har.d.ts +49 -0
  14. package/dist/helpers/operation-to-har/operation-to-har.d.ts.map +1 -0
  15. package/dist/helpers/operation-to-har/operation-to-har.js +52 -0
  16. package/dist/helpers/operation-to-har/operation-to-har.js.map +7 -0
  17. package/dist/helpers/operation-to-har/process-body.d.ts +9 -0
  18. package/dist/helpers/operation-to-har/process-body.d.ts.map +1 -0
  19. package/dist/helpers/operation-to-har/process-body.js +12 -0
  20. package/dist/helpers/operation-to-har/process-body.js.map +7 -0
  21. package/dist/helpers/operation-to-har/process-parameters.d.ts +16 -0
  22. package/dist/helpers/operation-to-har/process-parameters.d.ts.map +1 -0
  23. package/dist/helpers/operation-to-har/process-parameters.js +161 -0
  24. package/dist/helpers/operation-to-har/process-parameters.js.map +7 -0
  25. package/dist/helpers/operation-to-har/process-security-schemes.d.ts +13 -0
  26. package/dist/helpers/operation-to-har/process-security-schemes.d.ts.map +1 -0
  27. package/dist/helpers/operation-to-har/process-security-schemes.js +68 -0
  28. package/dist/helpers/operation-to-har/process-security-schemes.js.map +7 -0
  29. package/dist/helpers/operation-to-har/process-server-url.d.ts +6 -0
  30. package/dist/helpers/operation-to-har/process-server-url.d.ts.map +1 -0
  31. package/dist/helpers/operation-to-har/process-server-url.js +27 -0
  32. package/dist/helpers/operation-to-har/process-server-url.js.map +7 -0
  33. package/dist/spec-getters/get-example-from-schema.d.ts.map +1 -1
  34. package/dist/spec-getters/get-example-from-schema.js +3 -1
  35. package/dist/spec-getters/get-example-from-schema.js.map +2 -2
  36. package/dist/spec-getters/get-parameters-from-operation.d.ts +3 -2
  37. package/dist/spec-getters/get-parameters-from-operation.d.ts.map +1 -1
  38. package/dist/spec-getters/get-parameters-from-operation.js +3 -3
  39. package/dist/spec-getters/get-parameters-from-operation.js.map +2 -2
  40. package/dist/spec-getters/get-request-body-from-operation.d.ts +1 -1
  41. package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
  42. package/dist/spec-getters/get-request-body-from-operation.js +12 -2
  43. package/dist/spec-getters/get-request-body-from-operation.js.map +2 -2
  44. package/dist/transforms/import-spec.d.ts.map +1 -1
  45. package/dist/transforms/import-spec.js +0 -14
  46. package/dist/transforms/import-spec.js.map +2 -2
  47. package/package.json +14 -8
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { operationToHar } from "./operation-to-har.js";
2
+ export {
3
+ operationToHar
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/operation-to-har/index.ts"],
4
+ "sourcesContent": ["export { operationToHar } from './operation-to-har'\n"],
5
+ "mappings": "AAAA,SAAS,sBAAsB;",
6
+ "names": []
7
+ }
@@ -0,0 +1,49 @@
1
+ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
2
+ import type { HttpMethod } from '@scalar/helpers/http/http-methods';
3
+ import type { Request as HarRequest } from 'har-format';
4
+ export type OperationToHarProps = {
5
+ /** OpenAPI Operation object */
6
+ operation: OpenAPIV3_1.OperationObject;
7
+ /** HTTP method of the operation */
8
+ method: HttpMethod;
9
+ /**
10
+ * Content type of the request
11
+ *
12
+ * @defaults to the first content type in the operation.requestBody.content
13
+ */
14
+ contentType?: string;
15
+ /** Path of the operation */
16
+ path: string;
17
+ /** OpenAPI Server object */
18
+ server?: OpenAPIV3_1.ServerObject;
19
+ /** OpenAPI SecurityScheme objects which are applicable to the operation */
20
+ securitySchemes?: OpenAPIV3_1.SecuritySchemeObject[];
21
+ /**
22
+ * requestBody.content[contentType].example to use for the request, it should be pre-selected and discriminated
23
+ */
24
+ example?: unknown;
25
+ };
26
+ /**
27
+ * Converts an OpenAPI Operation to a HarRequest format for generating HTTP request snippets.
28
+ *
29
+ * This function transforms OpenAPI 3.1 operation objects into HAR (HTTP Archive) format requests,
30
+ * which can be used to generate code snippets for various programming languages and HTTP clients.
31
+ *
32
+ * The conversion handles:
33
+ * - Server URL processing and path parameter substitution
34
+ * - Query parameter formatting based on OpenAPI parameter styles
35
+ * - Request body processing with content type handling
36
+ * - Security scheme integration (API keys, etc.)
37
+ *
38
+ * The resulting HarRequest object follows the HAR specification and includes:
39
+ * - HTTP method and URL
40
+ * - Headers and query parameters
41
+ * - Request body (if present)
42
+ * - Cookie information
43
+ * - Size calculations for headers and body
44
+ *
45
+ * @see https://w3c.github.io/web-performance/specs/HAR/Overview.html
46
+ * @see https://spec.openapis.org/oas/v3.1.0#operation-object
47
+ */
48
+ export declare const operationToHar: ({ operation, contentType, method, path, server, securitySchemes, example, }: OperationToHarProps) => HarRequest;
49
+ //# sourceMappingURL=operation-to-har.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation-to-har.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/operation-to-har.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAOvD,MAAM,MAAM,mBAAmB,GAAG;IAChC,+BAA+B;IAC/B,SAAS,EAAE,WAAW,CAAC,eAAe,CAAA;IACtC,mCAAmC;IACnC,MAAM,EAAE,UAAU,CAAA;IAClB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,4BAA4B;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAC,YAAY,CAAA;IACjC,2EAA2E;IAC3E,eAAe,CAAC,EAAE,WAAW,CAAC,oBAAoB,EAAE,CAAA;IACpD;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,gFAQxB,mBAAmB,KAAG,UA+CxB,CAAA"}
@@ -0,0 +1,52 @@
1
+ import { processServerUrl } from "./process-server-url.js";
2
+ import { processParameters } from "./process-parameters.js";
3
+ import { processBody } from "./process-body.js";
4
+ import { processSecuritySchemes } from "./process-security-schemes.js";
5
+ const operationToHar = ({
6
+ operation,
7
+ contentType,
8
+ method,
9
+ path,
10
+ server,
11
+ securitySchemes,
12
+ example
13
+ }) => {
14
+ const harRequest = {
15
+ method,
16
+ url: path,
17
+ headers: [],
18
+ queryString: [],
19
+ postData: void 0,
20
+ httpVersion: "HTTP/1.1",
21
+ cookies: [],
22
+ headersSize: -1,
23
+ bodySize: -1
24
+ };
25
+ if (server?.url) {
26
+ harRequest.url = processServerUrl(server, path);
27
+ }
28
+ if (operation.parameters) {
29
+ const { url, headers, queryString } = processParameters(harRequest, operation.parameters, example);
30
+ harRequest.url = url;
31
+ harRequest.headers = headers;
32
+ harRequest.queryString = queryString;
33
+ }
34
+ if (operation.requestBody?.content && example) {
35
+ const postData = processBody({ operation, contentType, example });
36
+ harRequest.postData = postData;
37
+ harRequest.bodySize = postData.text?.length ?? -1;
38
+ }
39
+ if (securitySchemes) {
40
+ const { headers, queryString, cookies } = processSecuritySchemes(securitySchemes);
41
+ harRequest.headers.push(...headers);
42
+ harRequest.queryString.push(...queryString);
43
+ harRequest.cookies.push(...cookies);
44
+ }
45
+ const headerText = harRequest.headers.map((h) => `${h.name}: ${h.value}`).join("\r\n");
46
+ harRequest.headersSize = headerText.length;
47
+ return harRequest;
48
+ };
49
+ export {
50
+ operationToHar
51
+ };
52
+ //# sourceMappingURL=operation-to-har.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/operation-to-har/operation-to-har.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { Request as HarRequest } from 'har-format'\n\nimport { processServerUrl } from './process-server-url'\nimport { processParameters } from './process-parameters'\nimport { processBody } from './process-body'\nimport { processSecuritySchemes } from './process-security-schemes'\n\nexport type OperationToHarProps = {\n /** OpenAPI Operation object */\n operation: OpenAPIV3_1.OperationObject\n /** HTTP method of the operation */\n method: HttpMethod\n /**\n * Content type of the request\n *\n * @defaults to the first content type in the operation.requestBody.content\n */\n contentType?: string\n /** Path of the operation */\n path: string\n /** OpenAPI Server object */\n server?: OpenAPIV3_1.ServerObject\n /** OpenAPI SecurityScheme objects which are applicable to the operation */\n securitySchemes?: OpenAPIV3_1.SecuritySchemeObject[]\n /**\n * requestBody.content[contentType].example to use for the request, it should be pre-selected and discriminated\n */\n example?: unknown\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 operation,\n contentType,\n method,\n path,\n server,\n securitySchemes,\n example,\n}: OperationToHarProps): HarRequest => {\n // Initialize the HAR request with basic properties\n const harRequest: HarRequest = {\n method,\n url: path,\n headers: [],\n queryString: [],\n postData: undefined,\n httpVersion: 'HTTP/1.1',\n cookies: [],\n headersSize: -1,\n bodySize: -1,\n }\n\n // Server URL\n if (server?.url) {\n harRequest.url = processServerUrl(server, path)\n }\n\n // Handle parameters\n if (operation.parameters) {\n const { url, headers, queryString } = processParameters(harRequest, operation.parameters, example)\n harRequest.url = url\n harRequest.headers = headers\n harRequest.queryString = queryString\n }\n\n // Handle request body\n if (operation.requestBody?.content && example) {\n const postData = processBody({ operation, contentType, example })\n harRequest.postData = postData\n harRequest.bodySize = postData.text?.length ?? -1\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\n const headerText = harRequest.headers.map((h) => `${h.name}: ${h.value}`).join('\\r\\n')\n harRequest.headersSize = headerText.length\n\n return harRequest\n}\n"],
5
+ "mappings": "AAIA,SAAS,wBAAwB;AACjC,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AA+ChC,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAuC;AAErC,QAAM,aAAyB;AAAA,IAC7B;AAAA,IACA,KAAK;AAAA,IACL,SAAS,CAAC;AAAA,IACV,aAAa,CAAC;AAAA,IACd,UAAU;AAAA,IACV,aAAa;AAAA,IACb,SAAS,CAAC;AAAA,IACV,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAGA,MAAI,QAAQ,KAAK;AACf,eAAW,MAAM,iBAAiB,QAAQ,IAAI;AAAA,EAChD;AAGA,MAAI,UAAU,YAAY;AACxB,UAAM,EAAE,KAAK,SAAS,YAAY,IAAI,kBAAkB,YAAY,UAAU,YAAY,OAAO;AACjG,eAAW,MAAM;AACjB,eAAW,UAAU;AACrB,eAAW,cAAc;AAAA,EAC3B;AAGA,MAAI,UAAU,aAAa,WAAW,SAAS;AAC7C,UAAM,WAAW,YAAY,EAAE,WAAW,aAAa,QAAQ,CAAC;AAChE,eAAW,WAAW;AACtB,eAAW,WAAW,SAAS,MAAM,UAAU;AAAA,EACjD;AAGA,MAAI,iBAAiB;AACnB,UAAM,EAAE,SAAS,aAAa,QAAQ,IAAI,uBAAuB,eAAe;AAChF,eAAW,QAAQ,KAAK,GAAG,OAAO;AAClC,eAAW,YAAY,KAAK,GAAG,WAAW;AAC1C,eAAW,QAAQ,KAAK,GAAG,OAAO;AAAA,EACpC;AAGA,QAAM,aAAa,WAAW,QAAQ,IAAI,CAAC,MAAM,GAAG,EAAE,IAAI,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,MAAM;AACrF,aAAW,cAAc,WAAW;AAEpC,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ import type { OperationToHarProps } from '../../helpers/operation-to-har/operation-to-har.js';
2
+ import type { PostData } from 'har-format';
3
+ type ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'operation'> & Required<Pick<OperationToHarProps, 'example'>>;
4
+ /**
5
+ * Processes the request body and returns the processed data
6
+ */
7
+ export declare const processBody: ({ operation, contentType, example }: ProcessBodyProps) => PostData;
8
+ export {};
9
+ //# sourceMappingURL=process-body.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6CAA6C,CAAA;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,KAAK,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,EAAE,aAAa,GAAG,WAAW,CAAC,GAC5E,QAAQ,CAAC,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,CAAC,CAAA;AAEhD;;GAEG;AACH,eAAO,MAAM,WAAW,wCAAyC,gBAAgB,KAAG,QAQnF,CAAA"}
@@ -0,0 +1,12 @@
1
+ const processBody = ({ operation, contentType, example }) => {
2
+ const _contentType = contentType || Object.keys(operation.requestBody?.content || {})[0];
3
+ const text = JSON.stringify(example);
4
+ return {
5
+ mimeType: _contentType,
6
+ text
7
+ };
8
+ };
9
+ export {
10
+ processBody
11
+ };
12
+ //# sourceMappingURL=process-body.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/operation-to-har/process-body.ts"],
4
+ "sourcesContent": ["import type { OperationToHarProps } from '@/helpers/operation-to-har/operation-to-har'\nimport type { PostData } from 'har-format'\n\ntype ProcessBodyProps = Pick<OperationToHarProps, 'contentType' | 'operation'> &\n Required<Pick<OperationToHarProps, 'example'>>\n\n/**\n * Processes the request body and returns the processed data\n */\nexport const processBody = ({ operation, contentType, example }: ProcessBodyProps): PostData => {\n const _contentType = contentType || Object.keys(operation.requestBody?.content || {})[0]\n const text = JSON.stringify(example)\n\n return {\n mimeType: _contentType,\n text,\n }\n}\n"],
5
+ "mappings": "AASO,MAAM,cAAc,CAAC,EAAE,WAAW,aAAa,QAAQ,MAAkC;AAC9F,QAAM,eAAe,eAAe,OAAO,KAAK,UAAU,aAAa,WAAW,CAAC,CAAC,EAAE,CAAC;AACvF,QAAM,OAAO,KAAK,UAAU,OAAO;AAEnC,SAAO;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,16 @@
1
+ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
2
+ import type { Request as HarRequest } from 'har-format';
3
+ type ProcessedParameters = {
4
+ url: string;
5
+ headers: HarRequest['headers'];
6
+ queryString: HarRequest['queryString'];
7
+ };
8
+ /**
9
+ * Process OpenAPI parameters and return the updated properties.
10
+ * Handles path, query, and header parameters with various styles and explode options.
11
+ *
12
+ * @see https://spec.openapis.org/oas/latest.html#style-values
13
+ */
14
+ export declare const processParameters: (harRequest: HarRequest, parameters: OpenAPIV3_1.ParameterObject[], example?: unknown) => ProcessedParameters;
15
+ export {};
16
+ //# sourceMappingURL=process-parameters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-parameters.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-parameters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,KAAK,mBAAmB,GAAG;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;CACvC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAChB,UAAU,cACV,WAAW,CAAC,eAAe,EAAE,YAC/B,OAAO,KAChB,mBAyHF,CAAA"}
@@ -0,0 +1,161 @@
1
+ const processParameters = (harRequest, parameters, example) => {
2
+ const newHeaders = [...harRequest.headers];
3
+ const newQueryString = [...harRequest.queryString];
4
+ let newUrl = harRequest.url;
5
+ for (const param of parameters) {
6
+ if (!param.in || !param.name) {
7
+ continue;
8
+ }
9
+ const paramValue = example && typeof example === "object" ? example[param.name] : void 0;
10
+ if (paramValue === void 0) {
11
+ continue;
12
+ }
13
+ const style = param.style || "simple";
14
+ const explode = param.explode ?? false;
15
+ switch (param.in) {
16
+ case "path": {
17
+ newUrl = processPathParameters(newUrl, param, paramValue, style, explode);
18
+ break;
19
+ }
20
+ case "query": {
21
+ switch (style) {
22
+ case "form": {
23
+ if (explode) {
24
+ if (Array.isArray(paramValue)) {
25
+ for (const value of paramValue) {
26
+ newQueryString.push({ name: param.name, value: String(value) });
27
+ }
28
+ } else if (typeof paramValue === "object" && paramValue !== null) {
29
+ for (const [key, value] of Object.entries(paramValue)) {
30
+ newQueryString.push({ name: key, value: String(value) });
31
+ }
32
+ } else {
33
+ newQueryString.push({ name: param.name, value: String(paramValue) });
34
+ }
35
+ } else {
36
+ if (Array.isArray(paramValue)) {
37
+ newQueryString.push({ name: param.name, value: paramValue.join(",") });
38
+ } else if (typeof paramValue === "object" && paramValue !== null) {
39
+ const values = Object.entries(paramValue).map(([k, v]) => `${k},${v}`).join(",");
40
+ newQueryString.push({ name: param.name, value: values });
41
+ } else {
42
+ newQueryString.push({ name: param.name, value: String(paramValue) });
43
+ }
44
+ }
45
+ break;
46
+ }
47
+ case "spaceDelimited": {
48
+ if (Array.isArray(paramValue)) {
49
+ newQueryString.push({ name: param.name, value: paramValue.join(" ") });
50
+ } else if (typeof paramValue === "object" && paramValue !== null) {
51
+ const values = Object.entries(paramValue).map(([k, v]) => `${k} ${v}`).join(" ");
52
+ newQueryString.push({ name: param.name, value: values });
53
+ }
54
+ break;
55
+ }
56
+ case "pipeDelimited": {
57
+ if (Array.isArray(paramValue)) {
58
+ newQueryString.push({ name: param.name, value: paramValue.join("|") });
59
+ } else if (typeof paramValue === "object" && paramValue !== null) {
60
+ const values = Object.entries(paramValue).flat().join("|");
61
+ newQueryString.push({ name: param.name, value: values });
62
+ }
63
+ break;
64
+ }
65
+ case "deepObject": {
66
+ if (explode && typeof paramValue === "object" && paramValue !== null) {
67
+ for (const [key, value] of Object.entries(paramValue)) {
68
+ newQueryString.push({ name: `${param.name}[${key}]`, value: String(value) });
69
+ }
70
+ }
71
+ break;
72
+ }
73
+ // Default to form style
74
+ default:
75
+ newQueryString.push({ name: param.name, value: String(paramValue) });
76
+ }
77
+ break;
78
+ }
79
+ case "header":
80
+ newHeaders.push({ name: param.name, value: String(paramValue) });
81
+ break;
82
+ }
83
+ }
84
+ return {
85
+ url: newUrl,
86
+ headers: newHeaders,
87
+ queryString: newQueryString
88
+ };
89
+ };
90
+ const processPathParameters = (url, param, paramValue, style, explode) => {
91
+ switch (style) {
92
+ case "matrix": {
93
+ if (explode) {
94
+ if (Array.isArray(paramValue)) {
95
+ const values = paramValue.map((v) => `${param.name}=${v}`).join(";");
96
+ return url.replace(`{;${param.name}}`, `;${values}`);
97
+ }
98
+ if (typeof paramValue === "object" && paramValue !== null) {
99
+ const values = Object.entries(paramValue).map(([k, v]) => `${k}=${v}`).join(";");
100
+ return url.replace(`{;${param.name}}`, `;${values}`);
101
+ }
102
+ return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`);
103
+ }
104
+ if (Array.isArray(paramValue)) {
105
+ return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue.join(",")}`);
106
+ }
107
+ if (typeof paramValue === "object" && paramValue !== null) {
108
+ const values = Object.entries(paramValue).map(([k, v]) => `${k},${v}`).join(",");
109
+ return url.replace(`{;${param.name}}`, `;${param.name}=${values}`);
110
+ }
111
+ return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`);
112
+ }
113
+ case "label": {
114
+ if (explode) {
115
+ if (Array.isArray(paramValue)) {
116
+ return url.replace(`{.${param.name}}`, `.${paramValue.join(".")}`);
117
+ }
118
+ if (typeof paramValue === "object" && paramValue !== null) {
119
+ const values = Object.entries(paramValue).map(([k, v]) => `${k}=${v}`).join(".");
120
+ return url.replace(`{.${param.name}}`, `.${values}`);
121
+ }
122
+ return url.replace(`{.${param.name}}`, `.${paramValue}`);
123
+ }
124
+ if (Array.isArray(paramValue)) {
125
+ return url.replace(`{.${param.name}}`, `.${paramValue.join(",")}`);
126
+ }
127
+ if (typeof paramValue === "object" && paramValue !== null) {
128
+ const values = Object.entries(paramValue).map(([k, v]) => `${k},${v}`).join(",");
129
+ return url.replace(`{.${param.name}}`, `.${values}`);
130
+ }
131
+ return url.replace(`{.${param.name}}`, `.${paramValue}`);
132
+ }
133
+ case "simple": {
134
+ if (explode) {
135
+ if (Array.isArray(paramValue)) {
136
+ return url.replace(`{${param.name}}`, paramValue.join(","));
137
+ }
138
+ if (typeof paramValue === "object" && paramValue !== null) {
139
+ const values = Object.entries(paramValue).map(([k, v]) => `${k}=${v}`).join(",");
140
+ return url.replace(`{${param.name}}`, values);
141
+ }
142
+ return url.replace(`{${param.name}}`, String(paramValue));
143
+ }
144
+ if (Array.isArray(paramValue)) {
145
+ return url.replace(`{${param.name}}`, paramValue.join(","));
146
+ }
147
+ if (typeof paramValue === "object" && paramValue !== null) {
148
+ const values = Object.entries(paramValue).map(([k, v]) => `${k},${v}`).join(",");
149
+ return url.replace(`{${param.name}}`, values);
150
+ }
151
+ return url.replace(`{${param.name}}`, String(paramValue));
152
+ }
153
+ // Default to simple style
154
+ default:
155
+ return url.replace(`{${param.name}}`, String(paramValue));
156
+ }
157
+ };
158
+ export {
159
+ processParameters
160
+ };
161
+ //# sourceMappingURL=process-parameters.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/operation-to-har/process-parameters.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { Request as HarRequest } from 'har-format'\n\ntype ProcessedParameters = {\n url: string\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n}\n\n/**\n * Process OpenAPI parameters and return the updated properties.\n * Handles path, query, and header parameters with various styles and explode options.\n *\n * @see https://spec.openapis.org/oas/latest.html#style-values\n */\nexport const processParameters = (\n harRequest: HarRequest,\n parameters: OpenAPIV3_1.ParameterObject[],\n example?: unknown,\n): ProcessedParameters => {\n // Create copies of the arrays to avoid modifying the input\n const newHeaders = [...harRequest.headers]\n const newQueryString = [...harRequest.queryString]\n let newUrl = harRequest.url\n\n for (const param of parameters) {\n if (!param.in || !param.name) {\n continue\n }\n\n const paramValue =\n example && typeof example === 'object' ? (example as Record<string, unknown>)[param.name] : undefined\n\n if (paramValue === undefined) {\n continue\n }\n\n const style = param.style || 'simple'\n const explode = param.explode ?? false\n\n switch (param.in) {\n case 'path': {\n newUrl = processPathParameters(newUrl, param, paramValue, style, explode)\n break\n }\n case 'query': {\n // Handle query parameters\n switch (style) {\n case 'form': {\n if (explode) {\n // Form explode array: color=blue&color=black&color=brown\n if (Array.isArray(paramValue)) {\n for (const value of paramValue as unknown[]) {\n newQueryString.push({ name: param.name, value: String(value) })\n }\n }\n // Form explode object: R=100&G=200&B=150\n else if (typeof paramValue === 'object' && paramValue !== null) {\n for (const [key, value] of Object.entries(paramValue as Record<string, unknown>)) {\n newQueryString.push({ name: key, value: String(value) })\n }\n }\n // Form explode primitive: color=blue\n else {\n newQueryString.push({ name: param.name, value: String(paramValue) })\n }\n } else {\n // Form no explode array: color=blue,black,brown\n if (Array.isArray(paramValue)) {\n newQueryString.push({ name: param.name, value: (paramValue as unknown[]).join(',') })\n }\n // Form no explode object: color=R,100,G,200,B,150\n else if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n newQueryString.push({ name: param.name, value: values })\n }\n // Form no explode primitive: color=blue\n else {\n newQueryString.push({ name: param.name, value: String(paramValue) })\n }\n }\n break\n }\n case 'spaceDelimited': {\n // SpaceDelimited array: color=blue black brown\n if (Array.isArray(paramValue)) {\n newQueryString.push({ name: param.name, value: (paramValue as unknown[]).join(' ') })\n }\n // SpaceDelimited object: color=R 100 G 200 B 150\n else if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k} ${v}`)\n .join(' ')\n newQueryString.push({ name: param.name, value: values })\n }\n break\n }\n case 'pipeDelimited': {\n // PipeDelimited array: color=blue|black|brown\n if (Array.isArray(paramValue)) {\n newQueryString.push({ name: param.name, value: (paramValue as unknown[]).join('|') })\n }\n // PipeDelimited object: color=R|100|G|200|B|150\n else if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .flat()\n .join('|')\n newQueryString.push({ name: param.name, value: values })\n }\n break\n }\n case 'deepObject': {\n // DeepObject: color[R]=100&color[G]=200&color[B]=150\n if (explode && typeof paramValue === 'object' && paramValue !== null) {\n for (const [key, value] of Object.entries(paramValue as Record<string, unknown>)) {\n newQueryString.push({ name: `${param.name}[${key}]`, value: String(value) })\n }\n }\n break\n }\n\n // Default to form style\n default:\n newQueryString.push({ name: param.name, value: String(paramValue) })\n }\n break\n }\n case 'header':\n newHeaders.push({ name: param.name, value: String(paramValue) })\n break\n }\n }\n\n return {\n url: newUrl,\n headers: newHeaders,\n queryString: newQueryString,\n }\n}\n\n/**\n * Process path parameters according to OpenAPI specification.\n * Handles matrix, label, and simple styles with explode options.\n *\n * @param url - The URL to process\n * @param param - The parameter object\n * @param paramValue - The value of the parameter\n * @param style - The style of the parameter (matrix, label, simple)\n * @param explode - Whether to explode the parameter\n * @returns The updated URL with processed path parameters\n */\nconst processPathParameters = (\n url: string,\n param: OpenAPIV3_1.ParameterObject,\n paramValue: unknown,\n style: string,\n explode: boolean,\n): string => {\n switch (style) {\n case 'matrix': {\n if (explode) {\n // Matrix explode array: ;color=blue;color=black;color=brown\n if (Array.isArray(paramValue)) {\n const values = (paramValue as unknown[]).map((v) => `${param.name}=${v}`).join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode object: ;R=100;G=200;B=150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k}=${v}`)\n .join(';')\n return url.replace(`{;${param.name}}`, `;${values}`)\n }\n\n // Matrix explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n\n // Matrix no explode array: ;color=blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{;${param.name}}`, `;${param.name}=${(paramValue as unknown[]).join(',')}`)\n }\n\n // Matrix no explode object: ;color=R,100,G,200,B,150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n return url.replace(`{;${param.name}}`, `;${param.name}=${values}`)\n }\n\n // Matrix no explode primitive: ;color=blue\n return url.replace(`{;${param.name}}`, `;${param.name}=${paramValue}`)\n }\n case 'label': {\n if (explode) {\n // Label explode array: .blue.black.brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${(paramValue as unknown[]).join('.')}`)\n }\n\n // Label explode object: .R=100.G=200.B=150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k}=${v}`)\n .join('.')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n // Label no explode array: .blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{.${param.name}}`, `.${(paramValue as unknown[]).join(',')}`)\n }\n\n // Label no explode object: .R,100,G,200,B,150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n\n return url.replace(`{.${param.name}}`, `.${values}`)\n }\n\n // Label no explode primitive: .blue\n return url.replace(`{.${param.name}}`, `.${paramValue}`)\n }\n\n case 'simple': {\n if (explode) {\n // Simple explode array: blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{${param.name}}`, (paramValue as unknown[]).join(','))\n }\n\n // Simple explode object: R=100,G=200,B=150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k}=${v}`)\n .join(',')\n\n return url.replace(`{${param.name}}`, values)\n }\n\n // Simple explode primitive: blue\n return url.replace(`{${param.name}}`, String(paramValue))\n }\n // Simple no explode array: blue,black,brown\n if (Array.isArray(paramValue)) {\n return url.replace(`{${param.name}}`, (paramValue as unknown[]).join(','))\n }\n\n // Simple no explode object: R,100,G,200,B,150\n if (typeof paramValue === 'object' && paramValue !== null) {\n const values = Object.entries(paramValue as Record<string, unknown>)\n .map(([k, v]) => `${k},${v}`)\n .join(',')\n\n return url.replace(`{${param.name}}`, values)\n }\n\n // Simple no explode primitive: blue\n return url.replace(`{${param.name}}`, String(paramValue))\n }\n\n // Default to simple style\n default:\n return url.replace(`{${param.name}}`, String(paramValue))\n }\n}\n"],
5
+ "mappings": "AAeO,MAAM,oBAAoB,CAC/B,YACA,YACA,YACwB;AAExB,QAAM,aAAa,CAAC,GAAG,WAAW,OAAO;AACzC,QAAM,iBAAiB,CAAC,GAAG,WAAW,WAAW;AACjD,MAAI,SAAS,WAAW;AAExB,aAAW,SAAS,YAAY;AAC9B,QAAI,CAAC,MAAM,MAAM,CAAC,MAAM,MAAM;AAC5B;AAAA,IACF;AAEA,UAAM,aACJ,WAAW,OAAO,YAAY,WAAY,QAAoC,MAAM,IAAI,IAAI;AAE9F,QAAI,eAAe,QAAW;AAC5B;AAAA,IACF;AAEA,UAAM,QAAQ,MAAM,SAAS;AAC7B,UAAM,UAAU,MAAM,WAAW;AAEjC,YAAQ,MAAM,IAAI;AAAA,MAChB,KAAK,QAAQ;AACX,iBAAS,sBAAsB,QAAQ,OAAO,YAAY,OAAO,OAAO;AACxE;AAAA,MACF;AAAA,MACA,KAAK,SAAS;AAEZ,gBAAQ,OAAO;AAAA,UACb,KAAK,QAAQ;AACX,gBAAI,SAAS;AAEX,kBAAI,MAAM,QAAQ,UAAU,GAAG;AA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AA,MAC1D;AAEA,UAAI,MAAM,QAAQ,UAAU,GAAG;AAC7B,eAAO,IAAI,QAAQ,IAAI,MAAM,IAAI,KAAM,WAAyB,KAAK,GAAG,CAAC;AAAA,MAC3E;AAGA,UAAI,OAAO,eAAe,YAAY,eAAe,MAAM;AACzD,cAAM,SAAS,OAAO,QAAQ,UAAqC,EAChE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,EAC3B,KAAK,GAAG;AAEX,eAAO,IAAI,QAAQ,IAAI,MAAM,IAAI,KAAK,MAAM;AAAA,MAC9C;AAGA,aAAO,IAAI,QAAQ,IAAI,MAAM,IAAI,KAAK,OAAO,UAAU,CAAC;AAAA,IAC1D;AAAA;AAAA,IAGA;AACE,aAAO,IAAI,QAAQ,IAAI,MAAM,IAAI,KAAK,OAAO,UAAU,CAAC;AAAA,EAC5D;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,13 @@
1
+ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
2
+ import type { Request as HarRequest } from 'har-format';
3
+ type ProcessedSecuritySchemesReturn = {
4
+ headers: HarRequest['headers'];
5
+ queryString: HarRequest['queryString'];
6
+ cookies: HarRequest['cookies'];
7
+ };
8
+ /**
9
+ * Process security schemes into whichever parameters they are applicable to
10
+ */
11
+ export declare const processSecuritySchemes: (securitySchemes: OpenAPIV3_1.SecuritySchemeObject[]) => ProcessedSecuritySchemesReturn;
12
+ export {};
13
+ //# sourceMappingURL=process-security-schemes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-security-schemes.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-security-schemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvD,KAAK,8BAA8B,GAAG;IACpC,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;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,oBAChB,WAAW,CAAC,oBAAoB,EAAE,KAClD,8BA4EF,CAAA"}
@@ -0,0 +1,68 @@
1
+ const processSecuritySchemes = (securitySchemes) => {
2
+ const result = {
3
+ headers: [],
4
+ queryString: [],
5
+ cookies: []
6
+ };
7
+ for (const scheme of securitySchemes) {
8
+ if (scheme.type === "apiKey") {
9
+ const value = scheme["x-scalar-secret-token"];
10
+ if (!value || !scheme.name) {
11
+ continue;
12
+ }
13
+ const param = { name: scheme.name, value };
14
+ switch (scheme.in) {
15
+ case "header":
16
+ result.headers.push(param);
17
+ break;
18
+ case "query":
19
+ result.queryString.push(param);
20
+ break;
21
+ case "cookie":
22
+ result.cookies.push(param);
23
+ break;
24
+ }
25
+ continue;
26
+ }
27
+ if (scheme.type === "http") {
28
+ if (scheme.scheme === "basic") {
29
+ const username = scheme["x-scalar-secret-username"];
30
+ const password = scheme["x-scalar-secret-password"];
31
+ if (!username && !password) {
32
+ continue;
33
+ }
34
+ const auth = Buffer.from(`${username}:${password}`).toString("base64");
35
+ result.headers.push({
36
+ name: "Authorization",
37
+ value: `Basic ${auth}`
38
+ });
39
+ } else if (scheme.scheme === "bearer") {
40
+ const token = scheme["x-scalar-secret-token"];
41
+ if (!token) {
42
+ continue;
43
+ }
44
+ result.headers.push({
45
+ name: "Authorization",
46
+ value: `Bearer ${token}`
47
+ });
48
+ }
49
+ continue;
50
+ }
51
+ if (scheme.type === "oauth2" && scheme.flows) {
52
+ const flow = Object.values(scheme.flows).find((f) => f["x-scalar-secret-token"]);
53
+ const token = flow?.["x-scalar-secret-token"];
54
+ if (!token) {
55
+ continue;
56
+ }
57
+ result.headers.push({
58
+ name: "Authorization",
59
+ value: `Bearer ${token}`
60
+ });
61
+ }
62
+ }
63
+ return result;
64
+ };
65
+ export {
66
+ processSecuritySchemes
67
+ };
68
+ //# sourceMappingURL=process-security-schemes.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/operation-to-har/process-security-schemes.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { Request as HarRequest } from 'har-format'\n\ntype ProcessedSecuritySchemesReturn = {\n headers: HarRequest['headers']\n queryString: HarRequest['queryString']\n cookies: HarRequest['cookies']\n}\n\n/**\n * Process security schemes into whichever parameters they are applicable to\n */\nexport const processSecuritySchemes = (\n securitySchemes: OpenAPIV3_1.SecuritySchemeObject[],\n): ProcessedSecuritySchemesReturn => {\n const result: ProcessedSecuritySchemesReturn = {\n headers: [],\n queryString: [],\n cookies: [],\n }\n\n for (const scheme of securitySchemes) {\n // Handle apiKey type\n if (scheme.type === 'apiKey') {\n const value = scheme['x-scalar-secret-token']\n if (!value || !scheme.name) {\n continue\n }\n\n const param = { name: scheme.name, value }\n\n switch (scheme.in) {\n case 'header':\n result.headers.push(param as HarRequest['headers'][0])\n break\n case 'query':\n result.queryString.push(param as HarRequest['queryString'][0])\n break\n case 'cookie':\n result.cookies.push(param as HarRequest['cookies'][0])\n break\n }\n continue\n }\n\n // Handle http type\n if (scheme.type === 'http') {\n if (scheme.scheme === 'basic') {\n const username = scheme['x-scalar-secret-username']\n const password = scheme['x-scalar-secret-password']\n if (!username && !password) {\n continue\n }\n\n const auth = Buffer.from(`${username}:${password}`).toString('base64')\n result.headers.push({\n name: 'Authorization',\n value: `Basic ${auth}`,\n })\n } else if (scheme.scheme === 'bearer') {\n const token = scheme['x-scalar-secret-token']\n if (!token) {\n continue\n }\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n continue\n }\n\n // Handle oauth2 type\n if (scheme.type === 'oauth2' && scheme.flows) {\n // Find the first flow with a token\n const flow = Object.values(scheme.flows).find((f) => f['x-scalar-secret-token'])\n const token = flow?.['x-scalar-secret-token']\n if (!token) {\n continue\n }\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n }\n\n return result\n}\n"],
5
+ "mappings": "AAYO,MAAM,yBAAyB,CACpC,oBACmC;AACnC,QAAM,SAAyC;AAAA,IAC7C,SAAS,CAAC;AAAA,IACV,aAAa,CAAC;AAAA,IACd,SAAS,CAAC;AAAA,EACZ;AAEA,aAAW,UAAU,iBAAiB;AAEpC,QAAI,OAAO,SAAS,UAAU;AAC5B,YAAM,QAAQ,OAAO,uBAAuB;AAC5C,UAAI,CAAC,SAAS,CAAC,OAAO,MAAM;AAC1B;AAAA,MACF;AAEA,YAAM,QAAQ,EAAE,MAAM,OAAO,MAAM,MAAM;AAEzC,cAAQ,OAAO,IAAI;AAAA,QACjB,KAAK;AACH,iBAAO,QAAQ,KAAK,KAAiC;AACrD;AAAA,QACF,KAAK;AACH,iBAAO,YAAY,KAAK,KAAqC;AAC7D;AAAA,QACF,KAAK;AACH,iBAAO,QAAQ,KAAK,KAAiC;AACrD;AAAA,MACJ;AACA;AAAA,IACF;AAGA,QAAI,OAAO,SAAS,QAAQ;AAC1B,UAAI,OAAO,WAAW,SAAS;AAC7B,cAAM,WAAW,OAAO,0BAA0B;AAClD,cAAM,WAAW,OAAO,0BAA0B;AAClD,YAAI,CAAC,YAAY,CAAC,UAAU;AAC1B;AAAA,QACF;AAEA,cAAM,OAAO,OAAO,KAAK,GAAG,QAAQ,IAAI,QAAQ,EAAE,EAAE,SAAS,QAAQ;AACrE,eAAO,QAAQ,KAAK;AAAA,UAClB,MAAM;AAAA,UACN,OAAO,SAAS,IAAI;AAAA,QACtB,CAAC;AAAA,MACH,WAAW,OAAO,WAAW,UAAU;AACrC,cAAM,QAAQ,OAAO,uBAAuB;AAC5C,YAAI,CAAC,OAAO;AACV;AAAA,QACF;AAEA,eAAO,QAAQ,KAAK;AAAA,UAClB,MAAM;AAAA,UACN,OAAO,UAAU,KAAK;AAAA,QACxB,CAAC;AAAA,MACH;AACA;AAAA,IACF;AAGA,QAAI,OAAO,SAAS,YAAY,OAAO,OAAO;AAE5C,YAAM,OAAO,OAAO,OAAO,OAAO,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,uBAAuB,CAAC;AAC/E,YAAM,QAAQ,OAAO,uBAAuB;AAC5C,UAAI,CAAC,OAAO;AACV;AAAA,MACF;AAEA,aAAO,QAAQ,KAAK;AAAA,QAClB,MAAM;AAAA,QACN,OAAO,UAAU,KAAK;AAAA,MACxB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
2
+ /**
3
+ * Processes a server URL by replacing variables with their default values and merging with the path
4
+ */
5
+ export declare const processServerUrl: (server: OpenAPIV3_1.ServerObject, path: string) => string;
6
+ //# sourceMappingURL=process-server-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-server-url.d.ts","sourceRoot":"","sources":["../../../src/helpers/operation-to-har/process-server-url.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGxD;;GAEG;AACH,eAAO,MAAM,gBAAgB,WAAY,WAAW,CAAC,YAAY,QAAQ,MAAM,KAAG,MA4BjF,CAAA"}
@@ -0,0 +1,27 @@
1
+ import { mergeUrls } from "@scalar/helpers/url/merge-urls";
2
+ import { replaceVariables } from "@scalar/helpers/regex/replace-variables";
3
+ const processServerUrl = (server, path) => {
4
+ if (!server.url) {
5
+ return path;
6
+ }
7
+ const serverUrl = server.url;
8
+ if (server.variables) {
9
+ const variables = Object.entries(server.variables);
10
+ const defaultValues = variables.reduce(
11
+ (defaults, [variableName, variableConfig]) => {
12
+ if (variableConfig.default !== void 0) {
13
+ defaults[variableName] = variableConfig.default;
14
+ }
15
+ return defaults;
16
+ },
17
+ {}
18
+ );
19
+ const serverUrlWithVars = replaceVariables(serverUrl, defaultValues);
20
+ return mergeUrls(serverUrlWithVars, path);
21
+ }
22
+ return mergeUrls(serverUrl, path);
23
+ };
24
+ export {
25
+ processServerUrl
26
+ };
27
+ //# sourceMappingURL=process-server-url.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/helpers/operation-to-har/process-server-url.ts"],
4
+ "sourcesContent": ["import { mergeUrls } from '@scalar/helpers/url/merge-urls'\nimport type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport { replaceVariables } from '@scalar/helpers/regex/replace-variables'\n\n/**\n * Processes a server URL by replacing variables with their default values and merging with the path\n */\nexport const processServerUrl = (server: OpenAPIV3_1.ServerObject, path: string): string => {\n if (!server.url) {\n return path\n }\n const serverUrl = server.url\n\n // Replace server variables with their default values\n if (server.variables) {\n const variables = Object.entries(server.variables)\n\n // Extract default values from server variables\n const defaultValues = variables.reduce(\n (defaults, [variableName, variableConfig]) => {\n if (variableConfig.default !== undefined) {\n defaults[variableName] = variableConfig.default\n }\n return defaults\n },\n {} as Record<string, string | number>,\n )\n\n // Replace variables in the server URL with their default values\n const serverUrlWithVars = replaceVariables(serverUrl, defaultValues)\n\n return mergeUrls(serverUrlWithVars, path)\n }\n\n return mergeUrls(serverUrl, path)\n}\n"],
5
+ "mappings": "AAAA,SAAS,iBAAiB;AAE1B,SAAS,wBAAwB;AAK1B,MAAM,mBAAmB,CAAC,QAAkC,SAAyB;AAC1F,MAAI,CAAC,OAAO,KAAK;AACf,WAAO;AAAA,EACT;AACA,QAAM,YAAY,OAAO;AAGzB,MAAI,OAAO,WAAW;AACpB,UAAM,YAAY,OAAO,QAAQ,OAAO,SAAS;AAGjD,UAAM,gBAAgB,UAAU;AAAA,MAC9B,CAAC,UAAU,CAAC,cAAc,cAAc,MAAM;AAC5C,YAAI,eAAe,YAAY,QAAW;AACxC,mBAAS,YAAY,IAAI,eAAe;AAAA,QAC1C;AACA,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAGA,UAAM,oBAAoB,iBAAiB,WAAW,aAAa;AAEnE,WAAO,UAAU,mBAAmB,IAAI;AAAA,EAC1C;AAEA,SAAO,UAAU,WAAW,IAAI;AAClC;",
6
+ "names": []
7
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"AA8DA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,GAqRF,CAAA"}
1
+ {"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"AA8DA;;GAEG;AACH,eAAO,MAAM,oBAAoB,WACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YACjB;IACR;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B;;;OAGG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,UACM,MAAM,iBACE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAC3B,MAAM,KACZ,GA0RF,CAAA"}
@@ -174,7 +174,9 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
174
174
  return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
175
175
  }
176
176
  }
177
- if (schema.items?.type) {
177
+ const isObject = schema.items?.type === "object" || schema.items?.properties !== void 0;
178
+ const isArray = schema.items?.type === "array" || schema.items?.items !== void 0;
179
+ if (schema.items?.type || isObject || isArray) {
178
180
  const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
179
181
  return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
180
182
  }