@scalar/oas-utils 0.4.18 → 0.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +54 -0
- package/dist/entities/spec/request-examples.d.ts +55 -55
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js.map +2 -2
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +2 -0
- package/dist/helpers/index.js.map +2 -2
- package/dist/helpers/operation-to-har/operation-to-har.d.ts +1 -2
- package/dist/helpers/operation-to-har/operation-to-har.d.ts.map +1 -1
- package/dist/helpers/operation-to-har/operation-to-har.js +4 -3
- package/dist/helpers/operation-to-har/operation-to-har.js.map +2 -2
- package/dist/helpers/operation-to-har/process-body.d.ts +5 -2
- package/dist/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/helpers/operation-to-har/process-body.js +4 -5
- package/dist/helpers/operation-to-har/process-body.js.map +2 -2
- package/dist/helpers/operation-to-har/process-parameters.d.ts +2 -4
- package/dist/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
- package/dist/helpers/operation-to-har/process-parameters.js +3 -8
- package/dist/helpers/operation-to-har/process-parameters.js.map +2 -2
- package/dist/helpers/operation-to-har/process-security-schemes.js +1 -1
- package/dist/helpers/operation-to-har/process-security-schemes.js.map +2 -2
- package/dist/helpers/servers.d.ts +24 -0
- package/dist/helpers/servers.d.ts.map +1 -0
- package/dist/helpers/servers.js +97 -0
- package/dist/helpers/servers.js.map +7 -0
- package/dist/spec-getters/get-example-from-schema.d.ts +3 -2
- package/dist/spec-getters/get-example-from-schema.d.ts.map +1 -1
- package/dist/spec-getters/get-example-from-schema.js +55 -39
- package/dist/spec-getters/get-example-from-schema.js.map +2 -2
- package/dist/spec-getters/get-parameters-from-operation.d.ts.map +1 -1
- package/dist/spec-getters/get-parameters-from-operation.js +4 -1
- package/dist/spec-getters/get-parameters-from-operation.js.map +2 -2
- package/dist/spec-getters/get-request-body-from-operation.d.ts.map +1 -1
- package/dist/spec-getters/get-request-body-from-operation.js +5 -4
- package/dist/spec-getters/get-request-body-from-operation.js.map +2 -2
- package/dist/transforms/import-spec.d.ts +0 -4
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +2 -69
- package/dist/transforms/import-spec.js.map +2 -2
- package/dist/transforms/index.d.ts +1 -1
- package/dist/transforms/index.d.ts.map +1 -1
- package/dist/transforms/index.js +0 -2
- package/dist/transforms/index.js.map +2 -2
- package/package.json +10 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/operation-to-har/process-security-schemes.ts"],
|
|
4
|
-
"sourcesContent": ["import type { SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/security-scheme'\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 *\n * TODO: we probably want to be able to disable YOUR_SECRET_TOKEN placeholder text + or allow it to be customzied\n */\nexport const processSecuritySchemes = (securitySchemes: SecuritySchemeObject[]): 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 =
|
|
5
|
-
"mappings": "AAcO,MAAM,yBAAyB,CAAC,oBAA4E;AACjH,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,
|
|
4
|
+
"sourcesContent": ["import type { SecuritySchemeObject } from '@scalar/workspace-store/schemas/v3.1/strict/security-scheme'\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 *\n * TODO: we probably want to be able to disable YOUR_SECRET_TOKEN placeholder text + or allow it to be customzied\n */\nexport const processSecuritySchemes = (securitySchemes: SecuritySchemeObject[]): ProcessedSecuritySchemesReturn => {\n const result: ProcessedSecuritySchemesReturn = {\n headers: [],\n queryString: [],\n cookies: [],\n }\n\n for (const scheme of securitySchemes) {\n // Handle apiKey type\n if (scheme.type === 'apiKey') {\n const value = scheme['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n if (!scheme.name) {\n continue\n }\n\n const param = { name: scheme.name, value }\n\n switch (scheme.in) {\n case 'header':\n result.headers.push(param)\n break\n case 'query':\n result.queryString.push(param)\n break\n case 'cookie':\n result.cookies.push(param)\n break\n }\n continue\n }\n\n // Handle http type\n if (scheme.type === 'http') {\n if (scheme.scheme === 'basic') {\n const username = scheme['x-scalar-secret-username'] || ''\n const password = scheme['x-scalar-secret-password'] || ''\n\n const value = `${username}:${password}`\n const auth = value === ':' ? 'username:password' : btoa(value)\n\n result.headers.push({\n name: 'Authorization',\n value: `Basic ${auth}`,\n })\n } else if (scheme.scheme === 'bearer') {\n const token = scheme['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n continue\n }\n\n // Handle oauth2 type\n if (scheme.type === 'oauth2' && scheme.flows) {\n const flows = Object.values(scheme.flows)\n\n // Find the first flow with a token\n const flow = flows.find((f) => f['x-scalar-secret-token'])\n const token = flow?.['x-scalar-secret-token'] || 'YOUR_SECRET_TOKEN'\n\n result.headers.push({\n name: 'Authorization',\n value: `Bearer ${token}`,\n })\n }\n }\n\n return result\n}\n"],
|
|
5
|
+
"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D,YAAM,QAAQ,OAAO,uBAAuB,KAAK;AAEjD,aAAO,QAAQ,KAAK;AAAA,QAClB,MAAM;AAAA,QACN,OAAO,UAAU,KAAK;AAAA,MACxB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Server } from '../entities/spec/server.js';
|
|
2
|
+
import type { ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/server';
|
|
3
|
+
/**
|
|
4
|
+
* Server processing options containing base URLs for resolving relative server URLs.
|
|
5
|
+
*/
|
|
6
|
+
type ServerProcessingOptions = {
|
|
7
|
+
baseServerURL?: string;
|
|
8
|
+
documentUrl?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Retrieves and processes servers from an OpenAPI document.
|
|
12
|
+
*
|
|
13
|
+
* This function handles several scenarios:
|
|
14
|
+
* 1. No servers provided - creates a default server from document URL or fallback
|
|
15
|
+
* 2. Invalid server configurations - filters them out with warnings
|
|
16
|
+
* 3. Relative URLs - resolves them to absolute URLs using available base URLs
|
|
17
|
+
*
|
|
18
|
+
* @param servers - Array of OpenAPI server objects from the document
|
|
19
|
+
* @param options - Configuration options for server processing
|
|
20
|
+
* @returns Array of validated Server entities
|
|
21
|
+
*/
|
|
22
|
+
export declare function getServersFromDocument(servers: ServerObject[] | undefined, options?: ServerProcessingOptions): Server[];
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=servers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../../src/helpers/servers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,wBAAwB,CAAA;AAGlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAA;AAEtF;;GAEG;AACH,KAAK,uBAAuB,GAAG;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,YAAY,EAAE,GAAG,SAAS,EACnC,OAAO,GAAE,uBAA4B,GACpC,MAAM,EAAE,CAsBV"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { serverSchema } from "../entities/spec/server.js";
|
|
2
|
+
import { isDefined } from "@scalar/helpers/array/is-defined";
|
|
3
|
+
import { combineUrlAndPath } from "@scalar/helpers/url/merge-urls";
|
|
4
|
+
function getServersFromDocument(servers, options = {}) {
|
|
5
|
+
if (!servers?.length) {
|
|
6
|
+
const fallbackServer = createFallbackServer(options);
|
|
7
|
+
return fallbackServer ? [fallbackServer] : [];
|
|
8
|
+
}
|
|
9
|
+
if (!Array.isArray(servers)) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const validServers = servers.map((server) => processServerObject(server, options)).filter(isDefined);
|
|
13
|
+
if (validServers.length === 0) {
|
|
14
|
+
const fallbackServer = createFallbackServer(options);
|
|
15
|
+
return fallbackServer ? [fallbackServer] : [];
|
|
16
|
+
}
|
|
17
|
+
return validServers;
|
|
18
|
+
}
|
|
19
|
+
function extractBaseUrlFromDocumentUrl(documentUrl) {
|
|
20
|
+
try {
|
|
21
|
+
const url = new URL(documentUrl);
|
|
22
|
+
const port = url.port ? `:${url.port}` : "";
|
|
23
|
+
return `${url.protocol}//${url.hostname}${port}`;
|
|
24
|
+
} catch {
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function getFallbackUrl() {
|
|
29
|
+
if (typeof window === "undefined" || typeof window?.location?.origin !== "string") {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
return window.location.origin;
|
|
33
|
+
}
|
|
34
|
+
function createServerFromUrl(url, context) {
|
|
35
|
+
try {
|
|
36
|
+
return serverSchema.parse({ url });
|
|
37
|
+
} catch {
|
|
38
|
+
console.warn(`Failed to create server from ${context}:`, url);
|
|
39
|
+
return void 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function createDefaultServerFromDocumentUrl(documentUrl) {
|
|
43
|
+
const baseUrl = extractBaseUrlFromDocumentUrl(documentUrl);
|
|
44
|
+
if (!baseUrl) {
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
return createServerFromUrl(baseUrl, "document URL");
|
|
48
|
+
}
|
|
49
|
+
function createDefaultServerFromFallback() {
|
|
50
|
+
const fallbackUrl = getFallbackUrl();
|
|
51
|
+
if (!fallbackUrl) {
|
|
52
|
+
return void 0;
|
|
53
|
+
}
|
|
54
|
+
return createServerFromUrl(fallbackUrl, "fallback URL");
|
|
55
|
+
}
|
|
56
|
+
function resolveRelativeServerUrl(serverUrl, options) {
|
|
57
|
+
const { baseServerURL, documentUrl } = options;
|
|
58
|
+
if (baseServerURL) {
|
|
59
|
+
return combineUrlAndPath(baseServerURL, serverUrl);
|
|
60
|
+
}
|
|
61
|
+
if (documentUrl) {
|
|
62
|
+
const baseUrl = extractBaseUrlFromDocumentUrl(documentUrl);
|
|
63
|
+
if (baseUrl) {
|
|
64
|
+
return combineUrlAndPath(baseUrl, serverUrl);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const fallbackUrl = getFallbackUrl();
|
|
68
|
+
if (fallbackUrl) {
|
|
69
|
+
return combineUrlAndPath(fallbackUrl, serverUrl);
|
|
70
|
+
}
|
|
71
|
+
return serverUrl;
|
|
72
|
+
}
|
|
73
|
+
function processServerObject(server, options) {
|
|
74
|
+
try {
|
|
75
|
+
const parsedServer = serverSchema.parse(server);
|
|
76
|
+
if (parsedServer.url?.startsWith("/")) {
|
|
77
|
+
parsedServer.url = resolveRelativeServerUrl(parsedServer.url, options);
|
|
78
|
+
}
|
|
79
|
+
return parsedServer;
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.warn("Invalid server configuration:", server, "Error:", error);
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function createFallbackServer(options) {
|
|
86
|
+
if (options.documentUrl) {
|
|
87
|
+
const defaultServer = createDefaultServerFromDocumentUrl(options.documentUrl);
|
|
88
|
+
if (defaultServer) {
|
|
89
|
+
return defaultServer;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return createDefaultServerFromFallback();
|
|
93
|
+
}
|
|
94
|
+
export {
|
|
95
|
+
getServersFromDocument
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=servers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/helpers/servers.ts"],
|
|
4
|
+
"sourcesContent": ["import { type Server, serverSchema } from '@/entities/spec/server'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport { combineUrlAndPath } from '@scalar/helpers/url/merge-urls'\nimport type { ServerObject } from '@scalar/workspace-store/schemas/v3.1/strict/server'\n\n/**\n * Server processing options containing base URLs for resolving relative server URLs.\n */\ntype ServerProcessingOptions = {\n baseServerURL?: string\n documentUrl?: string\n}\n\n/**\n * Retrieves and processes servers from an OpenAPI document.\n *\n * This function handles several scenarios:\n * 1. No servers provided - creates a default server from document URL or fallback\n * 2. Invalid server configurations - filters them out with warnings\n * 3. Relative URLs - resolves them to absolute URLs using available base URLs\n *\n * @param servers - Array of OpenAPI server objects from the document\n * @param options - Configuration options for server processing\n * @returns Array of validated Server entities\n */\nexport function getServersFromDocument(\n servers: ServerObject[] | undefined,\n options: ServerProcessingOptions = {},\n): Server[] {\n // Handle case where no servers are provided\n if (!servers?.length) {\n const fallbackServer = createFallbackServer(options)\n return fallbackServer ? [fallbackServer] : []\n }\n\n // Handle invalid server array\n if (!Array.isArray(servers)) {\n return []\n }\n\n // Process each server and filter out invalid ones\n const validServers = servers.map((server) => processServerObject(server, options)).filter(isDefined)\n\n // If all servers were invalid, provide a fallback\n if (validServers.length === 0) {\n const fallbackServer = createFallbackServer(options)\n return fallbackServer ? [fallbackServer] : []\n }\n\n return validServers\n}\n\n/**\n * Extracts the base URL (protocol + hostname) from a document URL.\n * Returns undefined if the URL is invalid.\n */\nfunction extractBaseUrlFromDocumentUrl(documentUrl: string): string | undefined {\n try {\n const url = new URL(documentUrl)\n const port = url.port ? `:${url.port}` : ''\n return `${url.protocol}//${url.hostname}${port}`\n } catch {\n return undefined\n }\n}\n\n/**\n * Gets the fallback URL from window.location.origin if available.\n */\nfunction getFallbackUrl(): string | undefined {\n if (typeof window === 'undefined' || typeof window?.location?.origin !== 'string') {\n return undefined\n }\n return window.location.origin\n}\n\n/**\n * Creates a server object from a URL string, with error handling.\n */\nfunction createServerFromUrl(url: string, context: string): Server | undefined {\n try {\n return serverSchema.parse({ url })\n } catch {\n console.warn(`Failed to create server from ${context}:`, url)\n return undefined\n }\n}\n\n/**\n * Creates a default server using the document URL as the base.\n */\nfunction createDefaultServerFromDocumentUrl(documentUrl: string): Server | undefined {\n const baseUrl = extractBaseUrlFromDocumentUrl(documentUrl)\n if (!baseUrl) {\n return undefined\n }\n\n return createServerFromUrl(baseUrl, 'document URL')\n}\n\n/**\n * Creates a default server using the fallback URL (window.location.origin).\n */\nfunction createDefaultServerFromFallback(): Server | undefined {\n const fallbackUrl = getFallbackUrl()\n if (!fallbackUrl) {\n return undefined\n }\n\n return createServerFromUrl(fallbackUrl, 'fallback URL')\n}\n\n/**\n * Resolves a relative server URL to an absolute URL using available base URLs.\n * Uses a priority system: baseServerURL > documentUrl > fallbackUrl.\n */\nfunction resolveRelativeServerUrl(serverUrl: string, options: ServerProcessingOptions): string {\n const { baseServerURL, documentUrl } = options\n\n // Priority 1: Use provided base server URL\n if (baseServerURL) {\n return combineUrlAndPath(baseServerURL, serverUrl)\n }\n\n // Priority 2: Extract base URL from document URL\n if (documentUrl) {\n const baseUrl = extractBaseUrlFromDocumentUrl(documentUrl)\n if (baseUrl) {\n return combineUrlAndPath(baseUrl, serverUrl)\n }\n }\n\n // Priority 3: Use fallback URL (window.location.origin)\n const fallbackUrl = getFallbackUrl()\n if (fallbackUrl) {\n return combineUrlAndPath(fallbackUrl, serverUrl)\n }\n\n // If no base URL is available, return the original URL\n return serverUrl\n}\n\n/**\n * Processes a single server object, handling validation and URL resolution.\n */\nfunction processServerObject(server: ServerObject, options: ServerProcessingOptions): Server | undefined {\n try {\n const parsedServer = serverSchema.parse(server)\n\n // Resolve relative URLs to absolute URLs\n if (parsedServer.url?.startsWith('/')) {\n parsedServer.url = resolveRelativeServerUrl(parsedServer.url, options)\n }\n\n return parsedServer\n } catch (error) {\n console.warn('Invalid server configuration:', server, 'Error:', error)\n return undefined\n }\n}\n\n/**\n * Creates a fallback server when no valid servers are available.\n * Uses document URL first, then fallback URL.\n */\nfunction createFallbackServer(options: ServerProcessingOptions): Server | undefined {\n // Priority 1: Try to create default server from document URL\n if (options.documentUrl) {\n const defaultServer = createDefaultServerFromDocumentUrl(options.documentUrl)\n\n if (defaultServer) {\n return defaultServer\n }\n }\n\n // Priority 2: Try to create default server from fallback URL\n return createDefaultServerFromFallback()\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAsB,oBAAoB;AAC1C,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAuB3B,SAAS,uBACd,SACA,UAAmC,CAAC,GAC1B;AAEV,MAAI,CAAC,SAAS,QAAQ;AACpB,UAAM,iBAAiB,qBAAqB,OAAO;AACnD,WAAO,iBAAiB,CAAC,cAAc,IAAI,CAAC;AAAA,EAC9C;AAGA,MAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;AAC3B,WAAO,CAAC;AAAA,EACV;AAGA,QAAM,eAAe,QAAQ,IAAI,CAAC,WAAW,oBAAoB,QAAQ,OAAO,CAAC,EAAE,OAAO,SAAS;AAGnG,MAAI,aAAa,WAAW,GAAG;AAC7B,UAAM,iBAAiB,qBAAqB,OAAO;AACnD,WAAO,iBAAiB,CAAC,cAAc,I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;AAKA,SAAS,oBAAoB,QAAsB,SAAsD;AACvG,MAAI;AACF,UAAM,eAAe,aAAa,MAAM,MAAM;AAG9C,QAAI,aAAa,KAAK,WAAW,GAAG,GAAG;AACrC,mBAAa,MAAM,yBAAyB,aAAa,KAAK,OAAO;AAAA,IACvE;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,KAAK,iCAAiC,QAAQ,UAAU,KAAK;AACrE,WAAO;AAAA,EACT;AACF;AAMA,SAAS,qBAAqB,SAAsD;AAElF,MAAI,QAAQ,aAAa;AACvB,UAAM,gBAAgB,mCAAmC,QAAQ,WAAW;AAE5E,QAAI,eAAe;AACjB,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO,gCAAgC;AACzC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import type { SchemaObject } from '@scalar/workspace-store/schemas/v3.1/strict/schema';
|
|
1
2
|
/**
|
|
2
3
|
* This function takes an OpenAPI schema and generates an example from it
|
|
3
4
|
*/
|
|
4
|
-
export declare const getExampleFromSchema: (
|
|
5
|
+
export declare const getExampleFromSchema: (_schema: SchemaObject, options?: {
|
|
5
6
|
/**
|
|
6
7
|
* The fallback string for empty string values.
|
|
7
8
|
* @default ''
|
|
@@ -26,5 +27,5 @@ export declare const getExampleFromSchema: (schema: Record<string, any>, options
|
|
|
26
27
|
* @default false
|
|
27
28
|
*/
|
|
28
29
|
omitEmptyAndOptionalProperties?: boolean;
|
|
29
|
-
}, level?: number, parentSchema?:
|
|
30
|
+
}, level?: number, parentSchema?: SchemaObject, name?: string) => any;
|
|
30
31
|
//# sourceMappingURL=get-example-from-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-example-from-schema.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-example-from-schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oDAAoD,CAAA;AAkEtF;;GAEG;AACH,eAAO,MAAM,oBAAoB,YACtB,YAAY,YACX;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,YAAY,SACpB,MAAM,KACZ,GAyTF,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { isDefined } from "@scalar/helpers/array/is-defined";
|
|
2
|
+
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
1
3
|
const MAX_LEVELS_DEEP = 5;
|
|
2
4
|
const MAX_PROPERTIES = 10;
|
|
3
5
|
const DEFAULT_ADDITIONAL_PROPERTIES_NAME = "propertyName*";
|
|
@@ -36,7 +38,7 @@ function guessFromFormat(schema, makeUpRandomData = false, fallback = "") {
|
|
|
36
38
|
if (schema.format === "binary") {
|
|
37
39
|
return new File([""], "filename");
|
|
38
40
|
}
|
|
39
|
-
return makeUpRandomData ? genericExampleValues[schema.format] ?? fallback : "";
|
|
41
|
+
return makeUpRandomData ? genericExampleValues[schema.format ?? ""] ?? fallback : "";
|
|
40
42
|
}
|
|
41
43
|
const resultCache = /* @__PURE__ */ new WeakMap();
|
|
42
44
|
function cache(schema, result) {
|
|
@@ -46,7 +48,8 @@ function cache(schema, result) {
|
|
|
46
48
|
resultCache.set(schema, result);
|
|
47
49
|
return result;
|
|
48
50
|
}
|
|
49
|
-
const getExampleFromSchema = (
|
|
51
|
+
const getExampleFromSchema = (_schema, options, level = 0, parentSchema, name) => {
|
|
52
|
+
const schema = getResolvedRef(_schema);
|
|
50
53
|
if (resultCache.has(schema)) {
|
|
51
54
|
return resultCache.get(schema);
|
|
52
55
|
}
|
|
@@ -82,12 +85,19 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
82
85
|
if (schema.default !== void 0) {
|
|
83
86
|
return cache(schema, schema.default);
|
|
84
87
|
}
|
|
88
|
+
if (schema.const !== void 0) {
|
|
89
|
+
return cache(schema, schema.const);
|
|
90
|
+
}
|
|
85
91
|
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
|
86
92
|
return cache(schema, schema.enum[0]);
|
|
87
93
|
}
|
|
88
94
|
const isObjectOrArray = schema.type === "object" || schema.type === "array" || !!schema.allOf?.at?.(0) || !!schema.anyOf?.at?.(0) || !!schema.oneOf?.at?.(0);
|
|
89
95
|
if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {
|
|
90
|
-
const isRequired =
|
|
96
|
+
const isRequired = (
|
|
97
|
+
// @ts-expect-error - I suppose old schema used to allow `required: true` remove when moving to new store
|
|
98
|
+
schema.required === true || // @ts-expect-error - I suppose old schema used to allow `required: true` remove when moving to new store
|
|
99
|
+
parentSchema?.required === true || parentSchema?.required?.includes(name ?? schema.title ?? "")
|
|
100
|
+
);
|
|
91
101
|
if (!isRequired) {
|
|
92
102
|
return void 0;
|
|
93
103
|
}
|
|
@@ -102,8 +112,11 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
102
112
|
response["..."] = "[Additional Properties Truncated]";
|
|
103
113
|
break;
|
|
104
114
|
}
|
|
105
|
-
const property = schema.properties[propertyName];
|
|
106
|
-
const propertyXmlTagName = options?.xml ? property
|
|
115
|
+
const property = getResolvedRef(schema.properties[propertyName]);
|
|
116
|
+
const propertyXmlTagName = options?.xml ? property?.xml?.name : void 0;
|
|
117
|
+
if (!property) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
107
120
|
const value = getExampleFromSchema(property, options, level + 1, schema, propertyName);
|
|
108
121
|
if (typeof value !== "undefined") {
|
|
109
122
|
response[propertyXmlTagName ?? propertyName] = value;
|
|
@@ -115,7 +128,10 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
115
128
|
if (schema.patternProperties !== void 0) {
|
|
116
129
|
for (const pattern in schema.patternProperties) {
|
|
117
130
|
if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
|
|
118
|
-
const property = schema.patternProperties[pattern];
|
|
131
|
+
const property = getResolvedRef(schema.patternProperties[pattern]);
|
|
132
|
+
if (!property) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
119
135
|
const exampleKey = pattern;
|
|
120
136
|
response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey);
|
|
121
137
|
}
|
|
@@ -127,59 +143,59 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
127
143
|
schema.additionalProperties === true || // or an empty object {}
|
|
128
144
|
typeof schema.additionalProperties === "object" && !Object.keys(schema.additionalProperties).length
|
|
129
145
|
);
|
|
130
|
-
const
|
|
146
|
+
const additionalProperties = getResolvedRef(schema.additionalProperties);
|
|
147
|
+
const additionalPropertiesName = typeof additionalProperties === "object" && additionalProperties["x-additionalPropertiesName"] && typeof additionalProperties["x-additionalPropertiesName"] === "string" && additionalProperties["x-additionalPropertiesName"].trim().length > 0 ? `${additionalProperties["x-additionalPropertiesName"].trim()}*` : DEFAULT_ADDITIONAL_PROPERTIES_NAME;
|
|
131
148
|
if (anyTypeIsValid) {
|
|
132
149
|
response[additionalPropertiesName] = "anything";
|
|
133
|
-
} else if (
|
|
134
|
-
response[additionalPropertiesName] = getExampleFromSchema(
|
|
150
|
+
} else if (typeof additionalProperties === "object") {
|
|
151
|
+
response[additionalPropertiesName] = getExampleFromSchema(additionalProperties, options, level + 1);
|
|
135
152
|
}
|
|
136
153
|
}
|
|
137
|
-
if (schema.anyOf
|
|
138
|
-
Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1));
|
|
139
|
-
} else if (schema.oneOf !== void 0) {
|
|
140
|
-
Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1));
|
|
141
|
-
} else if (schema.allOf
|
|
154
|
+
if (schema.anyOf?.[0]) {
|
|
155
|
+
Object.assign(response, getExampleFromSchema(getResolvedRef(schema.anyOf[0]), options, level + 1));
|
|
156
|
+
} else if (schema.oneOf?.[0] !== void 0) {
|
|
157
|
+
Object.assign(response, getExampleFromSchema(getResolvedRef(schema.oneOf[0]), options, level + 1));
|
|
158
|
+
} else if (schema.allOf?.[0]) {
|
|
142
159
|
Object.assign(
|
|
143
160
|
response,
|
|
144
|
-
...schema.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema))
|
|
161
|
+
...schema.allOf.filter(isDefined).map((item) => getExampleFromSchema(getResolvedRef(item), options, level + 1, schema))
|
|
145
162
|
);
|
|
146
163
|
}
|
|
147
164
|
return cache(schema, response);
|
|
148
165
|
}
|
|
149
166
|
if (schema.type === "array" || schema.items !== void 0) {
|
|
150
|
-
const
|
|
167
|
+
const items = getResolvedRef(schema.items);
|
|
168
|
+
const itemsXmlTagName = items?.xml?.name;
|
|
151
169
|
const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
|
|
152
170
|
if (schema.example !== void 0) {
|
|
153
171
|
return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
|
|
154
172
|
}
|
|
155
|
-
if (
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
schema
|
|
163
|
-
);
|
|
173
|
+
if (items) {
|
|
174
|
+
if (items.allOf) {
|
|
175
|
+
const allOf = items.allOf.filter(isDefined);
|
|
176
|
+
const firstItem = getResolvedRef(allOf[0]);
|
|
177
|
+
if (firstItem?.type === "object") {
|
|
178
|
+
const combined = { type: "object", allOf };
|
|
179
|
+
const mergedExample = getExampleFromSchema(combined, options, level + 1, schema);
|
|
164
180
|
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
|
|
165
181
|
}
|
|
166
|
-
const examples =
|
|
182
|
+
const examples = allOf.map((item) => getExampleFromSchema(getResolvedRef(item), options, level + 1, schema)).filter(isDefined);
|
|
167
183
|
return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
|
|
168
184
|
}
|
|
169
185
|
const rules = ["anyOf", "oneOf"];
|
|
170
186
|
for (const rule of rules) {
|
|
171
|
-
if (!
|
|
187
|
+
if (!items[rule]) {
|
|
172
188
|
continue;
|
|
173
189
|
}
|
|
174
|
-
const schemas =
|
|
175
|
-
const exampleFromRule = schemas.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter(
|
|
190
|
+
const schemas = items[rule].slice(0, 1);
|
|
191
|
+
const exampleFromRule = schemas.map((item) => getExampleFromSchema(getResolvedRef(item), options, level + 1, schema)).filter(isDefined);
|
|
176
192
|
return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
|
|
177
193
|
}
|
|
178
194
|
}
|
|
179
|
-
const isObject =
|
|
180
|
-
const isArray =
|
|
181
|
-
if (
|
|
182
|
-
const exampleFromSchema = getExampleFromSchema(
|
|
195
|
+
const isObject = items?.type === "object" || items?.properties !== void 0;
|
|
196
|
+
const isArray = items?.type === "array" || items?.items !== void 0;
|
|
197
|
+
if (items?.type || isObject || isArray) {
|
|
198
|
+
const exampleFromSchema = getExampleFromSchema(items, options, level + 1);
|
|
183
199
|
return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
|
|
184
200
|
}
|
|
185
201
|
return [];
|
|
@@ -187,16 +203,16 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
187
203
|
const exampleValues = {
|
|
188
204
|
string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),
|
|
189
205
|
boolean: true,
|
|
190
|
-
integer: schema.
|
|
191
|
-
number: schema.
|
|
206
|
+
integer: schema.minimum ?? 1,
|
|
207
|
+
number: schema.minimum ?? 1,
|
|
192
208
|
array: []
|
|
193
209
|
};
|
|
194
|
-
if (schema.type
|
|
210
|
+
if (schema.type && !Array.isArray(schema.type) && exampleValues[schema.type] !== void 0) {
|
|
195
211
|
return cache(schema, exampleValues[schema.type]);
|
|
196
212
|
}
|
|
197
213
|
const discriminateSchema = schema.oneOf || schema.anyOf;
|
|
198
214
|
if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
|
|
199
|
-
const firstNonNullItem = discriminateSchema.find((item) => item.type !== "null");
|
|
215
|
+
const firstNonNullItem = discriminateSchema.map((item) => getResolvedRef(item)).find((item) => item.type !== "null");
|
|
200
216
|
if (firstNonNullItem) {
|
|
201
217
|
return getExampleFromSchema(firstNonNullItem, options, level + 1);
|
|
202
218
|
}
|
|
@@ -205,7 +221,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
205
221
|
if (Array.isArray(schema.allOf)) {
|
|
206
222
|
let example = null;
|
|
207
223
|
schema.allOf.forEach((allOfItem) => {
|
|
208
|
-
const newExample = getExampleFromSchema(allOfItem, options, level + 1);
|
|
224
|
+
const newExample = getExampleFromSchema(getResolvedRef(allOfItem), options, level + 1);
|
|
209
225
|
example = typeof newExample === "object" && typeof example === "object" ? {
|
|
210
226
|
...example ?? {},
|
|
211
227
|
...newExample
|
|
@@ -217,7 +233,7 @@ const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) =>
|
|
|
217
233
|
if (schema.type.includes("null")) {
|
|
218
234
|
return null;
|
|
219
235
|
}
|
|
220
|
-
const exampleValue = exampleValues[schema.type[0]];
|
|
236
|
+
const exampleValue = exampleValues[schema.type[0] ?? ""];
|
|
221
237
|
if (exampleValue !== void 0) {
|
|
222
238
|
return cache(schema, exampleValue);
|
|
223
239
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spec-getters/get-example-from-schema.ts"],
|
|
4
|
-
"sourcesContent": ["const MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\n/** The default name for additional properties. */\nconst DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'propertyName*'\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, makeUpRandomData: boolean = false, fallback: string = '') {\n if (schema.format === 'binary') {\n return new File([''], 'filename')\n }\n return makeUpRandomData ? (genericExampleValues[schema.format] ?? fallback) : ''\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it's a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don't want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it's defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there's an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there's one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there's one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n // Get the custom name for additional properties if available\n const additionalPropertiesName =\n typeof schema.additionalProperties === 'object' &&\n schema.additionalProperties['x-additionalPropertiesName'] &&\n typeof schema.additionalProperties['x-additionalPropertiesName'] === 'string' &&\n schema.additionalProperties['x-additionalPropertiesName'].trim().length > 0\n ? `${schema.additionalProperties['x-additionalPropertiesName'].trim()}*`\n : DEFAULT_ADDITIONAL_PROPERTIES_NAME\n\n if (anyTypeIsValid) {\n response[additionalPropertiesName] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response[additionalPropertiesName] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n // if it has type: 'object', or properties, it's an object\n const isObject = schema.items?.type === 'object' || schema.items?.properties !== undefined\n // if it has type: 'array', or items, it's an array\n const isArray = schema.items?.type === 'array' || schema.items?.items !== undefined\n\n if (schema.items?.type || isObject || isArray) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Find the first non-null type in the oneOf/anyOf array\n const firstNonNullItem = discriminateSchema.find((item) => item.type !== 'null')\n\n if (firstNonNullItem) {\n // Return an example for the first non-null item\n return getExampleFromSchema(firstNonNullItem, options, level + 1)\n }\n\n // If all items are null, return null\n return null\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
|
|
5
|
-
"mappings": "AAAA,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAGvB,MAAM,qCAAqC;AAE3C,MAAM,uBAA+C;AAAA;AAAA,EAEnD,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA;AAAA,EAEpC,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAC7C,SAAS;AAAA,EACT,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,gBAAgB;AAAA,EAChB,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,iBAAiB;AAAA;AAAA,EAEjB,OAAO;AAAA,EACP,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,SAAS;AAAA;AAAA,EAET,yBAAyB;AAAA;AAAA;AAAA,EAGzB,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC,EAAG,MAAM,GAAG,EAAE,CAAC;AAAA;AAAA,EAE5D,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,aAAa;AACf;AAKA,SAAS,gBAAgB,
|
|
4
|
+
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport type { SchemaObject } from '@scalar/workspace-store/schemas/v3.1/strict/schema'\n\nconst MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\n/** The default name for additional properties. */\nconst DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'propertyName*'\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: SchemaObject, makeUpRandomData: boolean = false, fallback: string = '') {\n if (schema.format === 'binary') {\n return new File([''], 'filename')\n }\n return makeUpRandomData ? (genericExampleValues[schema.format ?? ''] ?? fallback) : ''\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: SchemaObject, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n _schema: SchemaObject,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: SchemaObject,\n name?: string,\n): any => {\n const schema = getResolvedRef(_schema)\n\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it's a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don't want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it's defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there's an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there's one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there's one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // Use a const value, if there's one\n if (schema.const !== undefined) {\n return cache(schema, schema.const)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n // @ts-expect-error - I suppose old schema used to allow `required: true` remove when moving to new store\n schema.required === true ||\n // @ts-expect-error - I suppose old schema used to allow `required: true` remove when moving to new store\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.title ?? '')\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = getResolvedRef(schema.properties[propertyName])\n const propertyXmlTagName = options?.xml ? property?.xml?.name : undefined\n if (!property) {\n continue\n }\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = getResolvedRef(schema.patternProperties[pattern])\n if (!property) {\n continue\n }\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n const additionalProperties = getResolvedRef(schema.additionalProperties)\n\n // Get the custom name for additional properties if available\n const additionalPropertiesName =\n typeof additionalProperties === 'object' &&\n additionalProperties['x-additionalPropertiesName'] &&\n typeof additionalProperties['x-additionalPropertiesName'] === 'string' &&\n additionalProperties['x-additionalPropertiesName'].trim().length > 0\n ? `${additionalProperties['x-additionalPropertiesName'].trim()}*`\n : DEFAULT_ADDITIONAL_PROPERTIES_NAME\n\n if (anyTypeIsValid) {\n response[additionalPropertiesName] = 'anything'\n } else if (typeof additionalProperties === 'object') {\n response[additionalPropertiesName] = getExampleFromSchema(additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf?.[0]) {\n Object.assign(response, getExampleFromSchema(getResolvedRef(schema.anyOf[0]), options, level + 1))\n } else if (schema.oneOf?.[0] !== undefined) {\n Object.assign(response, getExampleFromSchema(getResolvedRef(schema.oneOf[0]), options, level + 1))\n } else if (schema.allOf?.[0]) {\n Object.assign(\n response,\n ...schema.allOf\n .filter(isDefined)\n .map((item) => getExampleFromSchema(getResolvedRef(item), options, level + 1, schema)),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const items = getResolvedRef(schema.items)\n const itemsXmlTagName = items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (items) {\n // First handle allOf separately since it needs special handling\n if (items.allOf) {\n const allOf = items.allOf.filter(isDefined)\n const firstItem = getResolvedRef(allOf[0])\n\n // IfirstItemem is an object type, merge all schemas\n if (firstItem?.type === 'object') {\n const combined = { type: 'object', allOf } as SchemaObject\n\n const mergedExample = getExampleFromSchema(combined, options, level + 1, schema)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = allOf\n .map((item) => getExampleFromSchema(getResolvedRef(item), options, level + 1, schema))\n .filter(isDefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf'] as const\n for (const rule of rules) {\n if (!items[rule]) {\n continue\n }\n\n const schemas = items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item) => getExampleFromSchema(getResolvedRef(item), options, level + 1, schema))\n .filter(isDefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n // if it has type: 'object', or properties, it's an object\n const isObject = items?.type === 'object' || items?.properties !== undefined\n // if it has type: 'array', or items, it's an array\n const isArray = items?.type === 'array' || items?.items !== undefined\n\n if (items?.type || isObject || isArray) {\n const exampleFromSchema = getExampleFromSchema(items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: guessFromFormat(schema, makeUpRandomData, options?.emptyString),\n boolean: true,\n integer: schema.minimum ?? 1,\n number: schema.minimum ?? 1,\n array: [],\n }\n if (schema.type && !Array.isArray(schema.type) && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Find the first non-null type in the oneOf/anyOf array\n const firstNonNullItem = discriminateSchema.map((item) => getResolvedRef(item)).find((item) => item.type !== 'null')\n\n if (firstNonNullItem) {\n // Return an example for the first non-null item\n return getExampleFromSchema(firstNonNullItem, options, level + 1)\n }\n\n // If all items are null, return null\n return null\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(getResolvedRef(allOfItem), options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0] ?? '']\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAG/B,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAGvB,MAAM,qCAAqC;AAE3C,MAAM,uBAA+C;AAAA;AAAA,EAEnD,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA;AAAA,EAEpC,SAAQ,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE,CAAC;AAAA,EAC7C,SAAS;AAAA,EACT,YAAY;AAAA;AAAA,EAEZ,aAAa;AAAA;AAAA,EAEb,gBAAgB;AAAA,EAChB,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AACvD,QAAI,iBAAiB,QAAW;AAC9B,aAAO,MAAM,QAAQ,YAAY;AAAA,IACnC;AAAA,EACF;AAMA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-parameters-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-parameters-from-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGhD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,mBAAmB,EAAE,SAAS,CAAC,YAAY,CAAM,EACjD,cAAc,EAAE,WAAW,CAAC,eAAe,EAAE,YAAK,EAClD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc;;;;;;
|
|
1
|
+
{"version":3,"file":"get-parameters-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-parameters-from-operation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGhD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,mBAAmB,EAAE,SAAS,CAAC,YAAY,CAAM,EACjD,cAAc,EAAE,WAAW,CAAC,eAAe,EAAE,YAAK,EAClD,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,EACnE,YAAY,GAAE,OAAc;;;;;;IAmC7B"}
|
|
@@ -4,7 +4,10 @@ function getParametersFromOperation(operationParameters = [], pathParameters = [
|
|
|
4
4
|
const params = parameters.filter((parameter) => parameter.in === where).filter((parameter) => requiredOnly && parameter.required || !requiredOnly).map((parameter) => ({
|
|
5
5
|
name: parameter.name ?? "Unknown Parameter",
|
|
6
6
|
description: parameter.description ?? null,
|
|
7
|
-
value: parameter.example ? parameter.example : parameter.schema ?
|
|
7
|
+
value: parameter.example ? parameter.example : parameter.schema ? (
|
|
8
|
+
// @ts-expect-error not on the new store yet
|
|
9
|
+
getExampleFromSchema(parameter.schema, { mode: "write" })
|
|
10
|
+
) : "",
|
|
8
11
|
required: parameter.required ?? false,
|
|
9
12
|
enabled: parameter.required ?? false
|
|
10
13
|
}));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spec-getters/get-parameters-from-operation.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { Operation } from '@/entities/spec'\nimport { getExampleFromSchema } from './get-example-from-schema'\n\n/**\n * Get the query parameters from an operation.\n *\n * Example: [ { name: 'foobar', value: '' } ]\n *\n * - OpenAPI 3.x: Possible values are \"query\", \"header\", \"path\" or \"cookie\".\n */\nexport function getParametersFromOperation(\n operationParameters: Operation['parameters'] = [],\n pathParameters: OpenAPIV3_1.ParameterObject[] = [],\n where: 'query' | 'header' | 'path' | 'cookie' | 'formData' | 'body',\n requiredOnly: boolean = true,\n) {\n const parameters = [...(pathParameters || []), ...(operationParameters || [])]\n\n const params = parameters\n // query, path, header, cookie?\n .filter((parameter) => parameter.in === where)\n // don't add optional parameters\n .filter((parameter) => (requiredOnly && parameter.required) || !requiredOnly)\n // transform them\n .map((parameter) => ({\n name: parameter.name ?? 'Unknown Parameter',\n description: parameter.description ?? null,\n value: parameter.example\n ? parameter.example\n : parameter.schema\n ? getExampleFromSchema(parameter.schema, { mode: 'write' })\n : '',\n required: parameter.required ?? false,\n enabled: parameter.required ?? false,\n }))\n\n return params.sort((a, b) => {\n // Move a up if a is required and b is not\n if (a.required && !b.required) {\n return -1\n }\n // Move b up if b is required and a is not\n if (!a.required && b.required) {\n return 1\n }\n // Keep original order if both have the same required status\n return 0\n })\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,4BAA4B;AAS9B,SAAS,2BACd,sBAA+C,CAAC,GAChD,iBAAgD,CAAC,GACjD,OACA,eAAwB,MACxB;AACA,QAAM,aAAa,CAAC,GAAI,kBAAkB,CAAC,GAAI,GAAI,uBAAuB,CAAC,CAAE;AAE7E,QAAM,SAAS,WAEZ,OAAO,CAAC,cAAc,UAAU,OAAO,KAAK,EAE5C,OAAO,CAAC,cAAe,gBAAgB,UAAU,YAAa,CAAC,YAAY,EAE3E,IAAI,CAAC,eAAe;AAAA,IACnB,MAAM,UAAU,QAAQ;AAAA,IACxB,aAAa,UAAU,eAAe;AAAA,IACtC,OAAO,UAAU,UACb,UAAU,UACV,UAAU,
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\n\nimport type { Operation } from '@/entities/spec'\nimport { getExampleFromSchema } from './get-example-from-schema'\n\n/**\n * Get the query parameters from an operation.\n *\n * Example: [ { name: 'foobar', value: '' } ]\n *\n * - OpenAPI 3.x: Possible values are \"query\", \"header\", \"path\" or \"cookie\".\n */\nexport function getParametersFromOperation(\n operationParameters: Operation['parameters'] = [],\n pathParameters: OpenAPIV3_1.ParameterObject[] = [],\n where: 'query' | 'header' | 'path' | 'cookie' | 'formData' | 'body',\n requiredOnly: boolean = true,\n) {\n const parameters = [...(pathParameters || []), ...(operationParameters || [])]\n\n const params = parameters\n // query, path, header, cookie?\n .filter((parameter) => parameter.in === where)\n // don't add optional parameters\n .filter((parameter) => (requiredOnly && parameter.required) || !requiredOnly)\n // transform them\n .map((parameter) => ({\n name: parameter.name ?? 'Unknown Parameter',\n description: parameter.description ?? null,\n value: parameter.example\n ? parameter.example\n : parameter.schema\n ? // @ts-expect-error not on the new store yet\n getExampleFromSchema(parameter.schema, { mode: 'write' })\n : '',\n required: parameter.required ?? false,\n enabled: parameter.required ?? false,\n }))\n\n return params.sort((a, b) => {\n // Move a up if a is required and b is not\n if (a.required && !b.required) {\n return -1\n }\n // Move b up if b is required and a is not\n if (!a.required && b.required) {\n return 1\n }\n // Keep original order if both have the same required status\n return 0\n })\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,4BAA4B;AAS9B,SAAS,2BACd,sBAA+C,CAAC,GAChD,iBAAgD,CAAC,GACjD,OACA,eAAwB,MACxB;AACA,QAAM,aAAa,CAAC,GAAI,kBAAkB,CAAC,GAAI,GAAI,uBAAuB,CAAC,CAAE;AAE7E,QAAM,SAAS,WAEZ,OAAO,CAAC,cAAc,UAAU,OAAO,KAAK,EAE5C,OAAO,CAAC,cAAe,gBAAgB,UAAU,YAAa,CAAC,YAAY,EAE3E,IAAI,CAAC,eAAe;AAAA,IACnB,MAAM,UAAU,QAAQ;AAAA,IACxB,aAAa,UAAU,eAAe;AAAA,IACtC,OAAO,UAAU,UACb,UAAU,UACV,UAAU;AAAA;AAAA,MAER,qBAAqB,UAAU,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAAA,QACxD;AAAA,IACN,UAAU,UAAU,YAAY;AAAA,IAChC,SAAS,UAAU,YAAY;AAAA,EACjC,EAAE;AAEJ,SAAO,OAAO,KAAK,CAAC,GAAG,MAAM;AAE3B,QAAI,EAAE,YAAY,CAAC,EAAE,UAAU;AAC7B,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,EAAE,YAAY,EAAE,UAAU;AAC7B,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"get-request-body-from-operation.d.ts","sourceRoot":"","sources":["../../src/spec-getters/get-request-body-from-operation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AA6ChD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,aAAa,GAAG,YAAY,CAAC,EACxD,kBAAkB,CAAC,EAAE,MAAM,GAAG,MAAM,EACpC,8BAA8B,CAAC,EAAE,OAAO,GACvC;IACD,QAAQ,EAAE,WAAW,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KACtB,EAAE,CAAA;CACJ,GAAG,IAAI,CA2KP"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { json2xml } from "@scalar/helpers/file/json2xml";
|
|
2
|
+
import { getResolvedRef } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
2
3
|
import { normalizeMimeTypeObject } from "../helpers/normalize-mime-type-object.js";
|
|
3
4
|
import { prettyPrintJson } from "../helpers/pretty-print-json.js";
|
|
4
5
|
import { getExampleFromSchema } from "./get-example-from-schema.js";
|
|
@@ -79,7 +80,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
|
|
|
79
80
|
const requestBodyObject = content?.[mimeType];
|
|
80
81
|
const example = requestBodyObject?.example ? requestBodyObject?.example : void 0;
|
|
81
82
|
if (isJsonLike) {
|
|
82
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(requestBodyObject?.schema, {
|
|
83
|
+
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
83
84
|
mode: "write",
|
|
84
85
|
omitEmptyAndOptionalProperties: omitEmptyAndOptionalProperties ?? false
|
|
85
86
|
}) : null;
|
|
@@ -90,7 +91,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
|
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
if (mimeType === "application/xml") {
|
|
93
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(requestBodyObject?.schema, {
|
|
94
|
+
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
94
95
|
xml: true,
|
|
95
96
|
mode: "write"
|
|
96
97
|
}) : null;
|
|
@@ -106,7 +107,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
|
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
109
|
if (mimeType === "text/plain") {
|
|
109
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(requestBodyObject?.schema, {
|
|
110
|
+
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
110
111
|
xml: true,
|
|
111
112
|
mode: "write"
|
|
112
113
|
}) : null;
|
|
@@ -116,7 +117,7 @@ function getRequestBodyFromOperation(operation, selectedExampleKey, omitEmptyAnd
|
|
|
116
117
|
};
|
|
117
118
|
}
|
|
118
119
|
if (mimeType === "multipart/form-data" || mimeType === "application/x-www-form-urlencoded") {
|
|
119
|
-
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(requestBodyObject?.schema, {
|
|
120
|
+
const exampleFromSchema = requestBodyObject?.schema ? getExampleFromSchema(getResolvedRef(requestBodyObject?.schema), {
|
|
120
121
|
xml: true,
|
|
121
122
|
mode: "write"
|
|
122
123
|
}) : null;
|