@scalar/oas-utils 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/dist/entities/spec/operation.d.ts +2 -3
- package/dist/entities/spec/operation.d.ts.map +1 -1
- package/dist/entities/spec/parameters.d.ts +4 -4
- package/dist/entities/spec/request-examples.d.ts.map +1 -1
- package/dist/entities/spec/request-examples.js +7 -0
- package/dist/entities/spec/request-examples.js.map +2 -2
- package/dist/entities/spec/requests.d.ts +5 -6
- package/dist/entities/spec/requests.d.ts.map +1 -1
- package/dist/entities/spec/requests.js +1 -1
- package/dist/entities/spec/requests.js.map +2 -2
- package/dist/helpers/should-ignore-entity.d.ts +4 -4
- package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
- package/dist/helpers/should-ignore-entity.js +1 -3
- package/dist/helpers/should-ignore-entity.js.map +2 -2
- package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
- package/dist/migrations/v-2.5.0/migration.js +5 -1
- package/dist/migrations/v-2.5.0/migration.js.map +2 -2
- package/dist/spec-getters/get-example-from-schema.d.ts +2 -0
- package/dist/spec-getters/get-example-from-schema.d.ts.map +1 -1
- package/dist/spec-getters/get-example-from-schema.js.map +2 -2
- package/dist/transforms/import-spec.js +1 -1
- package/dist/transforms/import-spec.js.map +2 -2
- package/package.json +13 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#7121](https://github.com/scalar/scalar/pull/7121) [`9661e81`](https://github.com/scalar/scalar/commit/9661e81907d1a9b74ba30f270f2d6c8e49834cd5) Thanks [@marcalexiei](https://github.com/marcalexiei)! - feat(oas-utils): make `dereference` synchronous
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#7143](https://github.com/scalar/scalar/pull/7143) [`81b0a7a`](https://github.com/scalar/scalar/commit/81b0a7a4245619f03161eae639dc5834b77432b6) Thanks [@amritk](https://github.com/amritk)! - fix: remove ignored parameters
|
|
12
|
+
|
|
13
|
+
- [#7133](https://github.com/scalar/scalar/pull/7133) [`0319b8a`](https://github.com/scalar/scalar/commit/0319b8a8652a50667776b2e9fd27c3e15b34f765) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix: account for text type content
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`eb022f2`](https://github.com/scalar/scalar/commit/eb022f2c8f93c84a04c0093fefe8a1e05d6ec80d), [`913607c`](https://github.com/scalar/scalar/commit/913607c7d67236f08f5369408f304440c6c42b22), [`17817ad`](https://github.com/scalar/scalar/commit/17817addbca916c8d625a03335ae58be3a1c4e4b), [`c22fc4e`](https://github.com/scalar/scalar/commit/c22fc4e5acb49d648014a6100c724a5b33c59cde), [`2239843`](https://github.com/scalar/scalar/commit/2239843150ed16d1ca35b0b1f8e90cd3e35be7ce), [`6ec8c29`](https://github.com/scalar/scalar/commit/6ec8c299d912111b029e8058979d00968b70691a), [`c162bb6`](https://github.com/scalar/scalar/commit/c162bb64b86e698427c1fce36f6d8a2b789e094a), [`b64265b`](https://github.com/scalar/scalar/commit/b64265b3e8b447a4d1c6dafaca8135ef69545d98), [`6ca835e`](https://github.com/scalar/scalar/commit/6ca835e5afd3e8c603e073e7c83f2cdd961a0f69), [`6aa06b0`](https://github.com/scalar/scalar/commit/6aa06b0f843ae3d8e6771e3c02ac11ee0043a4b1), [`81b0a7a`](https://github.com/scalar/scalar/commit/81b0a7a4245619f03161eae639dc5834b77432b6), [`6ec8c29`](https://github.com/scalar/scalar/commit/6ec8c299d912111b029e8058979d00968b70691a), [`704fa30`](https://github.com/scalar/scalar/commit/704fa302b2cdbb17b19ca2d742537ca163d58c1c), [`33edbf2`](https://github.com/scalar/scalar/commit/33edbf2a2648eb72ae49e36dfd289d4d57dc18e0), [`4fe1643`](https://github.com/scalar/scalar/commit/4fe1643be51f76a8ebdfd75f5675337b8d43418e), [`75ad74c`](https://github.com/scalar/scalar/commit/75ad74c0eee10103b966ce4707e4823d819456a8), [`eba18d0`](https://github.com/scalar/scalar/commit/eba18d06267a163a8f91396a66f817100ee59461), [`43bc5e8`](https://github.com/scalar/scalar/commit/43bc5e8b90dc0edf7176d0ddfc64bf3212494458)]:
|
|
16
|
+
- @scalar/types@0.4.0
|
|
17
|
+
- @scalar/workspace-store@0.18.0
|
|
18
|
+
- @scalar/openapi-types@0.5.1
|
|
19
|
+
- @scalar/helpers@0.0.13
|
|
20
|
+
- @scalar/json-magic@0.7.0
|
|
21
|
+
- @scalar/themes@0.13.23
|
|
22
|
+
- @scalar/object-utils@1.2.9
|
|
23
|
+
|
|
24
|
+
## 0.5.2
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- f8efecd: feat: use new schema example generation in the response
|
|
29
|
+
- Updated dependencies [3f6d0b9]
|
|
30
|
+
- Updated dependencies [2089748]
|
|
31
|
+
- Updated dependencies [f3e17d8]
|
|
32
|
+
- Updated dependencies [8a7fb2a]
|
|
33
|
+
- Updated dependencies [1335923]
|
|
34
|
+
- Updated dependencies [07397c8]
|
|
35
|
+
- Updated dependencies [f69e7cc]
|
|
36
|
+
- @scalar/helpers@0.0.12
|
|
37
|
+
- @scalar/json-magic@0.6.1
|
|
38
|
+
- @scalar/types@0.3.2
|
|
39
|
+
- @scalar/workspace-store@0.17.1
|
|
40
|
+
- @scalar/openapi-types@0.5.0
|
|
41
|
+
- @scalar/object-utils@1.2.8
|
|
42
|
+
- @scalar/themes@0.13.22
|
|
43
|
+
|
|
3
44
|
## 0.5.1
|
|
4
45
|
|
|
5
46
|
### Patch Changes
|
|
@@ -40,9 +40,9 @@ export declare const operationSchema: import("zod").ZodObject<{
|
|
|
40
40
|
content: import("zod").ZodOptional<import("zod").ZodUnknown>;
|
|
41
41
|
style: import("zod").ZodOptional<import("zod").ZodEnum<{
|
|
42
42
|
matrix: "matrix";
|
|
43
|
-
simple: "simple";
|
|
44
|
-
form: "form";
|
|
45
43
|
label: "label";
|
|
44
|
+
form: "form";
|
|
45
|
+
simple: "simple";
|
|
46
46
|
spaceDelimited: "spaceDelimited";
|
|
47
47
|
pipeDelimited: "pipeDelimited";
|
|
48
48
|
deepObject: "deepObject";
|
|
@@ -81,7 +81,6 @@ export declare const operationSchema: import("zod").ZodObject<{
|
|
|
81
81
|
uid: import("zod/v4/core").$ZodBranded<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>, "operation">;
|
|
82
82
|
path: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodString>>;
|
|
83
83
|
method: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
84
|
-
connect: "connect";
|
|
85
84
|
delete: "delete";
|
|
86
85
|
get: "get";
|
|
87
86
|
head: "head";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/operation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,IAAI,WAAW,EAAiB,MAAM,YAAY,CAAA;AAE5F,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AACnC,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAA;AAC7C,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/operation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,IAAI,WAAW,EAAiB,MAAM,YAAY,CAAA;AAE5F,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AACnC,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAA;AAC7C,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAAgB,CAAA"}
|
|
@@ -10,9 +10,9 @@ export declare const parameterTypeSchema: z.ZodEnum<{
|
|
|
10
10
|
export type ParamType = z.infer<typeof parameterTypeSchema>;
|
|
11
11
|
export declare const parameterStyleSchema: z.ZodEnum<{
|
|
12
12
|
matrix: "matrix";
|
|
13
|
-
simple: "simple";
|
|
14
|
-
form: "form";
|
|
15
13
|
label: "label";
|
|
14
|
+
form: "form";
|
|
15
|
+
simple: "simple";
|
|
16
16
|
spaceDelimited: "spaceDelimited";
|
|
17
17
|
pipeDelimited: "pipeDelimited";
|
|
18
18
|
deepObject: "deepObject";
|
|
@@ -42,9 +42,9 @@ export declare const oasParameterSchema: z.ZodObject<{
|
|
|
42
42
|
content: z.ZodOptional<z.ZodUnknown>;
|
|
43
43
|
style: z.ZodOptional<z.ZodEnum<{
|
|
44
44
|
matrix: "matrix";
|
|
45
|
-
simple: "simple";
|
|
46
|
-
form: "form";
|
|
47
45
|
label: "label";
|
|
46
|
+
form: "form";
|
|
47
|
+
simple: "simple";
|
|
48
48
|
spaceDelimited: "spaceDelimited";
|
|
49
49
|
pipeDelimited: "pipeDelimited";
|
|
50
50
|
deepObject: "deepObject";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-examples.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/request-examples.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,OAAO,KAAK,EAAoB,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAKtC;;;;;GAKG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCvC,CA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsB/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAKjE,2DAA2D;AAC3D,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAU/B,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AAEjE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;;;;;;;;;;;;;EAqD9D;AAKD,6DAA6D;AAC7D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,uBAAuB,CAsHpF;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,cAAc,CA2HxG"}
|
|
@@ -314,6 +314,13 @@ function createExampleFromRequest(request, name, server) {
|
|
|
314
314
|
})
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
|
+
if (contentType?.startsWith("text/")) {
|
|
318
|
+
body.activeBody = "raw";
|
|
319
|
+
body.raw = {
|
|
320
|
+
encoding: "text",
|
|
321
|
+
value: requestBody?.text ?? ""
|
|
322
|
+
};
|
|
323
|
+
}
|
|
317
324
|
if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith("multipart/")) {
|
|
318
325
|
parameters.headers.push({
|
|
319
326
|
key: "Content-Type",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/request-examples.ts"],
|
|
4
|
-
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { objectKeys } from '@scalar/helpers/object/object-keys'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { schemaModel } from '@/helpers/schema-model'\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\n\nimport type { ParameterContent, RequestParameter } from './parameters'\nimport type { Request } from './requests'\nimport type { Server } from './server'\n\n// ---------------------------------------------------------------------------\n// Example Parameters\n\n/**\n * TODO: Deprecate this.\n *\n * The request schema should be stored in the request and any\n * parameters should be validated against that\n */\nexport const requestExampleParametersSchema = z\n .object({\n key: z.string().default(''),\n value: z.coerce.string().default(''),\n enabled: z.boolean().default(true),\n file: z.any().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n enum: z.array(z.string()).optional(),\n examples: z.array(z.any()).optional(),\n type: z\n .union([\n // 'string'\n z.string(),\n // ['string', 'null']\n z.array(z.string()),\n ])\n .optional(),\n format: z.string().optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n default: z.any().optional(),\n nullable: z.boolean().optional(),\n })\n // set nullable: to true if type is ['string', 'null']\n .transform((_data) => {\n const data = { ..._data }\n\n // type: ['string', 'null'] -> nullable: true\n if (Array.isArray(data.type) && data.type.includes('null')) {\n data.nullable = true\n }\n\n // Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.\n if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {\n data.type = data.type.find((item) => item !== 'null')\n }\n\n return data\n })\n\n/** Convert the array of parameters to an object keyed by the parameter name */\nexport const parameterArrayToObject = (params: RequestExampleParameter[]) =>\n params.reduce<Record<string, string>>((map, param) => {\n map[param.key] = param.value\n return map\n }, {})\n\n/** Request examples - formerly known as instances - are \"children\" of requests */\nexport type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>\n\nexport const xScalarFileValueSchema = z\n .object({\n url: z.string(),\n base64: z.string().optional(),\n })\n .nullable()\n\n/**\n * When files are required for an example we provide the options\n * to provide a public URL or a base64 encoded string\n */\nexport type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>\n\n/**\n * Schema for the OAS serialization of request example parameters\n *\n * File values can be optionally fetched on import OR inserted as a base64 encoded string\n */\nexport const xScalarFormDataValue = z.union([\n z.object({\n type: z.literal('string'),\n value: z.string(),\n }),\n z.object({\n type: z.literal('file'),\n file: xScalarFileValueSchema,\n }),\n])\n\nexport type XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>\n\n// ---------------------------------------------------------------------------\n// Example Body\n\n/**\n * Possible encodings for example request bodies when using text formats\n *\n * TODO: This list may not be comprehensive enough\n */\nexport const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'] as const\n\nexport type BodyEncoding = (typeof exampleRequestBodyEncoding)[number]\n\nexport const exampleBodyMime = [\n 'application/json',\n 'text/plain',\n 'text/html',\n 'application/javascript',\n 'application/xml',\n 'application/yaml',\n 'application/edn',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n /** Used for direct files */\n 'binary',\n] as const\n\nexport type BodyMime = (typeof exampleBodyMime)[number]\n\nconst contentMapping: Record<BodyEncoding, BodyMime> = {\n json: 'application/json',\n text: 'text/plain',\n html: 'text/html',\n javascript: 'application/javascript',\n xml: 'application/xml',\n yaml: 'application/yaml',\n edn: 'application/edn',\n} as const\n\n/**\n * TODO: Migrate away from this layout to the format used in the extension\n *\n * If a user changes the encoding of the body we expect the content to change as well\n */\nexport const exampleRequestBodySchema = z.object({\n raw: z\n .object({\n encoding: z.enum(exampleRequestBodyEncoding),\n value: z.string().default(''),\n mimeType: z.string().optional(),\n })\n .optional(),\n formData: z\n .object({\n encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),\n value: requestExampleParametersSchema.array().default([]),\n })\n .optional(),\n binary: z.instanceof(Blob).optional(),\n activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),\n})\n\nexport type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>\n\n/** Schema for the OAS serialization of request example bodies */\nexport const xScalarExampleBodySchema = z.object({\n encoding: z.enum(exampleBodyMime),\n /**\n * Body content as an object with a separately specified encoding or a simple pre-encoded string value\n *\n * Ideally we would convert any objects into the proper encoding on import\n */\n content: z.union([z.record(z.string(), z.any()), z.string()]),\n /** When the encoding is `binary` this will be used to link to the file */\n file: xScalarFileValueSchema.optional(),\n})\n\nexport type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>\n\n// ---------------------------------------------------------------------------\n// Example Schema\n\nexport const requestExampleSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['EXAMPLE']>(),\n type: z.literal('requestExample').optional().default('requestExample'),\n requestUid: z.string().brand<ENTITY_BRANDS['OPERATION']>().optional(),\n name: z.string().optional().default('Name'),\n body: exampleRequestBodySchema.optional().default({ activeBody: 'raw' }),\n parameters: z\n .object({\n path: requestExampleParametersSchema.array().default([]),\n query: requestExampleParametersSchema.array().default([]),\n headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),\n cookies: requestExampleParametersSchema.array().default([]),\n })\n .optional()\n .default({\n path: [],\n query: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n cookies: [],\n }),\n /** TODO: Should this be deprecated? */\n serverVariables: z.record(z.string(), z.array(z.string())).optional(),\n})\n\nexport type RequestExample = z.infer<typeof requestExampleSchema>\n\n/** For OAS serialization we just store the simple key/value pairs */\nconst xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional()\n\n/** Schema for the OAS serialization of request examples */\nexport const xScalarExampleSchema = z.object({\n /** TODO: Should this be required? */\n name: z.string().optional(),\n body: xScalarExampleBodySchema.optional(),\n parameters: z.object({\n path: xScalarExampleParameterSchema,\n query: xScalarExampleParameterSchema,\n headers: xScalarExampleParameterSchema,\n cookies: xScalarExampleParameterSchema,\n }),\n})\n\nexport type XScalarExample = z.infer<typeof xScalarExampleSchema>\n\n/**\n * Convert a request example to the xScalar serialized format\n *\n * TODO: The base format should be migrated to align MUCH closer to the serialized format\n */\nexport function convertExampleToXScalar(example: RequestExample) {\n const active = example.body?.activeBody\n\n const xScalarBody: XScalarExampleBody = {\n encoding: 'text/plain',\n content: '',\n }\n\n if (example.body?.activeBody === 'binary') {\n xScalarBody.encoding = 'binary'\n // TODO: Need to allow users to set these properties\n xScalarBody.file = null\n }\n\n if (active === 'formData' && example.body?.[active]) {\n const body = example.body[active]\n xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded'\n\n // TODO: Need to allow users to set these properties\n xScalarBody.content = body.value.reduce<Record<string, XScalarFormDataValue>>((map, param) => {\n /** TODO: We need to ensure only file or value is set */\n map[param.key] = param.file\n ? {\n type: 'file',\n file: null,\n }\n : {\n type: 'string',\n value: param.value,\n }\n return map\n }, {})\n }\n\n if (example.body?.activeBody === 'raw') {\n xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain'\n\n xScalarBody.content = example.body.raw?.value ?? ''\n }\n\n const parameters: XScalarExample['parameters'] = {}\n\n keysOf(example.parameters ?? {}).forEach((key) => {\n if (example.parameters?.[key].length) {\n parameters[key] = parameterArrayToObject(example.parameters[key])\n }\n })\n\n return xScalarExampleSchema.parse({\n /** Only add the body if we have content or the body should be a file */\n body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,\n parameters,\n })\n}\n\n// ---------------------------------------------------------------------------\n// Example Helpers\n\n/** Create new instance parameter from a request parameter */\nexport function createParamInstance(param: RequestParameter): RequestExampleParameter {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && objectKeys(param.examples).length > 0) {\n const exampleValues = Object.entries(param.examples).map(([_, example]) => {\n // returns the external value if it exists\n if (example.externalValue) {\n return example.externalValue\n }\n\n // returns the value if it exists and is defined\n // e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']\n return example.value\n })\n\n // returns the first example as selected value along other examples\n return { value: exampleValues[0], examples: exampleValues }\n }\n\n // param example e.g. { example: 'foo' }\n if (isDefined(param.example)) {\n return { value: param.example }\n }\n\n // param examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(param.examples) && param.examples.length > 0) {\n return { value: param.examples[0] }\n }\n\n // schema example e.g. { example: 'foo' } while being discouraged\n // see https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-20\n if (isDefined(schema?.example)) {\n return { value: schema.example }\n }\n\n // schema examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(schema?.examples) && schema.examples.length > 0) {\n // For boolean type, default to false when using schema examples\n if (schema?.type === 'boolean') {\n return { value: schema.default ?? false }\n }\n return { value: schema.examples[0] }\n }\n\n // content examples e.g. { content: { 'application/json': { examples: { foo: { value: 'bar' } } } } }\n if (param.content) {\n const firstContentType = objectKeys(param.content)[0]\n if (firstContentType) {\n const content = (param.content as ParameterContent)[firstContentType]\n if (content?.examples) {\n const firstExampleKey = Object.keys(content.examples)[0]\n if (firstExampleKey) {\n const example = content.examples[firstExampleKey]\n if (isDefined(example?.value)) {\n return { value: example.value }\n }\n }\n }\n // content example e.g. { example: 'foo' }\n if (isDefined(content?.example)) {\n return { value: content.example }\n }\n }\n }\n\n return null\n })() as null | { value: any; examples?: string[] }\n\n /**\n * TODO:\n * - Need better value defaulting here\n * - Need to handle non-string parameters much better\n * - Need to handle unions/array values for schema\n */\n const value = String(firstExample?.value ?? schema?.default ?? '')\n\n // Handle non-string enums and enums within items for array types\n const parseEnum = (() => {\n if (schema?.enum && schema?.type !== 'string') {\n return schema.enum?.map(String)\n }\n\n if (schema?.items?.enum && schema?.type === 'array') {\n return schema.items.enum.map(String)\n }\n\n return schema?.enum\n })()\n\n // Handle parameter examples\n const examples =\n firstExample?.examples ||\n (schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples)\n\n // safe parse the example\n const example = schemaModel(\n {\n ...schema,\n key: param.name,\n value,\n description: param.description,\n required: param.required,\n /** Initialized all required properties to enabled */\n enabled: !!param.required,\n enum: parseEnum,\n examples,\n },\n requestExampleParametersSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${param.name} is invalid.`)\n return requestExampleParametersSchema.parse({})\n }\n\n return example\n}\n\n/**\n * Create new request example from a request\n * Iterates the name of the example if provided\n */\nexport function createExampleFromRequest(request: Request, name: string, server?: Server): RequestExample {\n // ---------------------------------------------------------------------------\n // Populate all parameters with an example value\n const parameters: Record<'path' | 'cookie' | 'header' | 'query' | 'headers', RequestExampleParameter[]> = {\n path: [],\n query: [],\n cookie: [],\n // deprecated TODO: add zod transform to remove\n header: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n }\n\n // Populated the separated params\n request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)))\n\n // TODO: add zod transform to remove header and only support headers\n if (parameters.header.length > 0) {\n parameters.headers = parameters.header\n parameters.header = []\n }\n\n // Get content type header\n const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')\n\n // ---------------------------------------------------------------------------\n // Handle request body defaulting for various content type encodings\n const body: ExampleRequestBody = {\n activeBody: 'raw',\n }\n\n // If we have a request body or a content type header\n // TODO: we don't even handle path parameters here\n if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation(request)\n const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value\n\n // Handle JSON and JSON-like mimetypes\n if (contentType?.includes('/json') || contentType?.endsWith('+json')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'json',\n mimeType: contentType,\n value: requestBody?.text ?? JSON.stringify({}),\n }\n }\n\n if (contentType === 'application/xml') {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'xml',\n value: requestBody?.text ?? '',\n }\n }\n\n /**\n * TODO: Are we loading example files from somewhere based on the spec?\n * How are we handling the body values\n */\n if (contentType === 'application/octet-stream') {\n body.activeBody = 'binary'\n body.binary = undefined\n }\n\n if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {\n body.activeBody = 'formData'\n body.formData = {\n encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',\n value: (requestBody?.params || []).map((param) => {\n if (param.value instanceof File) {\n return {\n key: param.name,\n value: 'BINARY',\n file: param.value,\n enabled: true,\n }\n }\n return {\n key: param.name,\n value: param.value || '',\n enabled: true,\n }\n }),\n }\n }\n\n // Add the content-type header if it doesn't exist and if it's not multipart request\n if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith('multipart/')) {\n parameters.headers.push({\n key: 'Content-Type',\n value: requestBody.mimeType,\n enabled: true,\n })\n }\n }\n\n const serverVariables = server ? getServerVariableExamples(server) : {}\n\n // safe parse the example\n const example = schemaModel(\n {\n requestUid: request.uid,\n parameters,\n name,\n body,\n serverVariables,\n },\n requestExampleSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${request.uid} is invalid.`)\n return requestExampleSchema.parse({})\n }\n return example\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,mBAAmB;AAC5B,SAAS,mCAAmC;AAC5C,SAAS,iCAAiC;AAenC,MAAM,iCAAiC,EAC3C,OAAO;AAAA,EACN,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE;AAAA,EAC1B,OAAO,EAAE,OAAO,OAAO,EAAE,QAAQ,EAAE;AAAA,EACnC,SAAS,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACjC,MAAM,EAAE,IAAI,EAAE,SAAS;AAAA,EACvB,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,EAAE,QA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AU;AAChD,cAAI,MAAM,iBAAiB,MAAM;AAC/B,mBAAO;AAAA,cACL,KAAK,MAAM;AAAA,cACX,OAAO;AAAA,cACP,MAAM,MAAM;AAAA,cACZ,SAAS;AAAA,YACX;AAAA,UACF;AACA,iBAAO;AAAA,YACL,KAAK,MAAM;AAAA,YACX,OAAO,MAAM,SAAS;AAAA,YACtB,SAAS;AAAA,UACX;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAGA,QAAI,aAAa,YAAY,CAAC,qBAAqB,CAAC,YAAY,SAAS,WAAW,YAAY,GAAG;AACjG,iBAAW,QAAQ,KAAK;AAAA,QACtB,KAAK;AAAA,QACL,OAAO,YAAY;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,kBAAkB,SAAS,0BAA0B,MAAM,IAAI,CAAC;AAGtE,QAAM,UAAU;AAAA,IACd;AAAA,MACE,YAAY,QAAQ;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,cAAc,QAAQ,GAAG,cAAc;AACpD,WAAO,qBAAqB,MAAM,CAAC,CAAC;AAAA,EACtC;AACA,SAAO;AACT;",
|
|
4
|
+
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { objectKeys } from '@scalar/helpers/object/object-keys'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { schemaModel } from '@/helpers/schema-model'\nimport { getRequestBodyFromOperation } from '@/spec-getters/get-request-body-from-operation'\nimport { getServerVariableExamples } from '@/spec-getters/get-server-variable-examples'\n\nimport type { ParameterContent, RequestParameter } from './parameters'\nimport type { Request } from './requests'\nimport type { Server } from './server'\n\n// ---------------------------------------------------------------------------\n// Example Parameters\n\n/**\n * TODO: Deprecate this.\n *\n * The request schema should be stored in the request and any\n * parameters should be validated against that\n */\nexport const requestExampleParametersSchema = z\n .object({\n key: z.string().default(''),\n value: z.coerce.string().default(''),\n enabled: z.boolean().default(true),\n file: z.any().optional(),\n description: z.string().optional(),\n required: z.boolean().optional(),\n enum: z.array(z.string()).optional(),\n examples: z.array(z.any()).optional(),\n type: z\n .union([\n // 'string'\n z.string(),\n // ['string', 'null']\n z.array(z.string()),\n ])\n .optional(),\n format: z.string().optional(),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n default: z.any().optional(),\n nullable: z.boolean().optional(),\n })\n // set nullable: to true if type is ['string', 'null']\n .transform((_data) => {\n const data = { ..._data }\n\n // type: ['string', 'null'] -> nullable: true\n if (Array.isArray(data.type) && data.type.includes('null')) {\n data.nullable = true\n }\n\n // Hey, if it's just one value and 'null', we can make it a string and ditch the 'null'.\n if (Array.isArray(data.type) && data.type.length === 2 && data.type.includes('null')) {\n data.type = data.type.find((item) => item !== 'null')\n }\n\n return data\n })\n\n/** Convert the array of parameters to an object keyed by the parameter name */\nexport const parameterArrayToObject = (params: RequestExampleParameter[]) =>\n params.reduce<Record<string, string>>((map, param) => {\n map[param.key] = param.value\n return map\n }, {})\n\n/** Request examples - formerly known as instances - are \"children\" of requests */\nexport type RequestExampleParameter = z.infer<typeof requestExampleParametersSchema>\n\nexport const xScalarFileValueSchema = z\n .object({\n url: z.string(),\n base64: z.string().optional(),\n })\n .nullable()\n\n/**\n * When files are required for an example we provide the options\n * to provide a public URL or a base64 encoded string\n */\nexport type XScalarFileValue = z.infer<typeof xScalarFileValueSchema>\n\n/**\n * Schema for the OAS serialization of request example parameters\n *\n * File values can be optionally fetched on import OR inserted as a base64 encoded string\n */\nexport const xScalarFormDataValue = z.union([\n z.object({\n type: z.literal('string'),\n value: z.string(),\n }),\n z.object({\n type: z.literal('file'),\n file: xScalarFileValueSchema,\n }),\n])\n\nexport type XScalarFormDataValue = z.infer<typeof xScalarFormDataValue>\n\n// ---------------------------------------------------------------------------\n// Example Body\n\n/**\n * Possible encodings for example request bodies when using text formats\n *\n * TODO: This list may not be comprehensive enough\n */\nexport const exampleRequestBodyEncoding = ['json', 'text', 'html', 'javascript', 'xml', 'yaml', 'edn'] as const\n\nexport type BodyEncoding = (typeof exampleRequestBodyEncoding)[number]\n\nexport const exampleBodyMime = [\n 'application/json',\n 'text/plain',\n 'text/html',\n 'application/javascript',\n 'application/xml',\n 'application/yaml',\n 'application/edn',\n 'application/octet-stream',\n 'application/x-www-form-urlencoded',\n 'multipart/form-data',\n /** Used for direct files */\n 'binary',\n] as const\n\nexport type BodyMime = (typeof exampleBodyMime)[number]\n\nconst contentMapping: Record<BodyEncoding, BodyMime> = {\n json: 'application/json',\n text: 'text/plain',\n html: 'text/html',\n javascript: 'application/javascript',\n xml: 'application/xml',\n yaml: 'application/yaml',\n edn: 'application/edn',\n} as const\n\n/**\n * TODO: Migrate away from this layout to the format used in the extension\n *\n * If a user changes the encoding of the body we expect the content to change as well\n */\nexport const exampleRequestBodySchema = z.object({\n raw: z\n .object({\n encoding: z.enum(exampleRequestBodyEncoding),\n value: z.string().default(''),\n mimeType: z.string().optional(),\n })\n .optional(),\n formData: z\n .object({\n encoding: z.union([z.literal('form-data'), z.literal('urlencoded')]).default('form-data'),\n value: requestExampleParametersSchema.array().default([]),\n })\n .optional(),\n binary: z.instanceof(Blob).optional(),\n activeBody: z.union([z.literal('raw'), z.literal('formData'), z.literal('binary')]).default('raw'),\n})\n\nexport type ExampleRequestBody = z.infer<typeof exampleRequestBodySchema>\n\n/** Schema for the OAS serialization of request example bodies */\nexport const xScalarExampleBodySchema = z.object({\n encoding: z.enum(exampleBodyMime),\n /**\n * Body content as an object with a separately specified encoding or a simple pre-encoded string value\n *\n * Ideally we would convert any objects into the proper encoding on import\n */\n content: z.union([z.record(z.string(), z.any()), z.string()]),\n /** When the encoding is `binary` this will be used to link to the file */\n file: xScalarFileValueSchema.optional(),\n})\n\nexport type XScalarExampleBody = z.infer<typeof xScalarExampleBodySchema>\n\n// ---------------------------------------------------------------------------\n// Example Schema\n\nexport const requestExampleSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['EXAMPLE']>(),\n type: z.literal('requestExample').optional().default('requestExample'),\n requestUid: z.string().brand<ENTITY_BRANDS['OPERATION']>().optional(),\n name: z.string().optional().default('Name'),\n body: exampleRequestBodySchema.optional().default({ activeBody: 'raw' }),\n parameters: z\n .object({\n path: requestExampleParametersSchema.array().default([]),\n query: requestExampleParametersSchema.array().default([]),\n headers: requestExampleParametersSchema.array().default([{ key: 'Accept', value: '*/*', enabled: true }]),\n cookies: requestExampleParametersSchema.array().default([]),\n })\n .optional()\n .default({\n path: [],\n query: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n cookies: [],\n }),\n /** TODO: Should this be deprecated? */\n serverVariables: z.record(z.string(), z.array(z.string())).optional(),\n})\n\nexport type RequestExample = z.infer<typeof requestExampleSchema>\n\n/** For OAS serialization we just store the simple key/value pairs */\nconst xScalarExampleParameterSchema = z.record(z.string(), z.string()).optional()\n\n/** Schema for the OAS serialization of request examples */\nexport const xScalarExampleSchema = z.object({\n /** TODO: Should this be required? */\n name: z.string().optional(),\n body: xScalarExampleBodySchema.optional(),\n parameters: z.object({\n path: xScalarExampleParameterSchema,\n query: xScalarExampleParameterSchema,\n headers: xScalarExampleParameterSchema,\n cookies: xScalarExampleParameterSchema,\n }),\n})\n\nexport type XScalarExample = z.infer<typeof xScalarExampleSchema>\n\n/**\n * Convert a request example to the xScalar serialized format\n *\n * TODO: The base format should be migrated to align MUCH closer to the serialized format\n */\nexport function convertExampleToXScalar(example: RequestExample) {\n const active = example.body?.activeBody\n\n const xScalarBody: XScalarExampleBody = {\n encoding: 'text/plain',\n content: '',\n }\n\n if (example.body?.activeBody === 'binary') {\n xScalarBody.encoding = 'binary'\n // TODO: Need to allow users to set these properties\n xScalarBody.file = null\n }\n\n if (active === 'formData' && example.body?.[active]) {\n const body = example.body[active]\n xScalarBody.encoding = body.encoding === 'form-data' ? 'multipart/form-data' : 'application/x-www-form-urlencoded'\n\n // TODO: Need to allow users to set these properties\n xScalarBody.content = body.value.reduce<Record<string, XScalarFormDataValue>>((map, param) => {\n /** TODO: We need to ensure only file or value is set */\n map[param.key] = param.file\n ? {\n type: 'file',\n file: null,\n }\n : {\n type: 'string',\n value: param.value,\n }\n return map\n }, {})\n }\n\n if (example.body?.activeBody === 'raw') {\n xScalarBody.encoding = contentMapping[example.body.raw?.encoding ?? 'text'] ?? 'text/plain'\n\n xScalarBody.content = example.body.raw?.value ?? ''\n }\n\n const parameters: XScalarExample['parameters'] = {}\n\n keysOf(example.parameters ?? {}).forEach((key) => {\n if (example.parameters?.[key].length) {\n parameters[key] = parameterArrayToObject(example.parameters[key])\n }\n })\n\n return xScalarExampleSchema.parse({\n /** Only add the body if we have content or the body should be a file */\n body: xScalarBody.content || xScalarBody.encoding === 'binary' ? xScalarBody : undefined,\n parameters,\n })\n}\n\n// ---------------------------------------------------------------------------\n// Example Helpers\n\n/** Create new instance parameter from a request parameter */\nexport function createParamInstance(param: RequestParameter): RequestExampleParameter {\n const schema = param.schema as any\n\n const firstExample = (() => {\n if (param.examples && !Array.isArray(param.examples) && objectKeys(param.examples).length > 0) {\n const exampleValues = Object.entries(param.examples).map(([_, example]) => {\n // returns the external value if it exists\n if (example.externalValue) {\n return example.externalValue\n }\n\n // returns the value if it exists and is defined\n // e.g. { examples: { foo: { value: 'bar' } } } would return ['bar']\n return example.value\n })\n\n // returns the first example as selected value along other examples\n return { value: exampleValues[0], examples: exampleValues }\n }\n\n // param example e.g. { example: 'foo' }\n if (isDefined(param.example)) {\n return { value: param.example }\n }\n\n // param examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(param.examples) && param.examples.length > 0) {\n return { value: param.examples[0] }\n }\n\n // schema example e.g. { example: 'foo' } while being discouraged\n // see https://spec.openapis.org/oas/v3.1.1.html#fixed-fields-20\n if (isDefined(schema?.example)) {\n return { value: schema.example }\n }\n\n // schema examples e.g. { examples: ['foo', 'bar'] }\n if (Array.isArray(schema?.examples) && schema.examples.length > 0) {\n // For boolean type, default to false when using schema examples\n if (schema?.type === 'boolean') {\n return { value: schema.default ?? false }\n }\n return { value: schema.examples[0] }\n }\n\n // content examples e.g. { content: { 'application/json': { examples: { foo: { value: 'bar' } } } } }\n if (param.content) {\n const firstContentType = objectKeys(param.content)[0]\n if (firstContentType) {\n const content = (param.content as ParameterContent)[firstContentType]\n if (content?.examples) {\n const firstExampleKey = Object.keys(content.examples)[0]\n if (firstExampleKey) {\n const example = content.examples[firstExampleKey]\n if (isDefined(example?.value)) {\n return { value: example.value }\n }\n }\n }\n // content example e.g. { example: 'foo' }\n if (isDefined(content?.example)) {\n return { value: content.example }\n }\n }\n }\n\n return null\n })() as null | { value: any; examples?: string[] }\n\n /**\n * TODO:\n * - Need better value defaulting here\n * - Need to handle non-string parameters much better\n * - Need to handle unions/array values for schema\n */\n const value = String(firstExample?.value ?? schema?.default ?? '')\n\n // Handle non-string enums and enums within items for array types\n const parseEnum = (() => {\n if (schema?.enum && schema?.type !== 'string') {\n return schema.enum?.map(String)\n }\n\n if (schema?.items?.enum && schema?.type === 'array') {\n return schema.items.enum.map(String)\n }\n\n return schema?.enum\n })()\n\n // Handle parameter examples\n const examples =\n firstExample?.examples ||\n (schema?.examples && schema?.type !== 'string' ? schema.examples?.map(String) : schema?.examples)\n\n // safe parse the example\n const example = schemaModel(\n {\n ...schema,\n key: param.name,\n value,\n description: param.description,\n required: param.required,\n /** Initialized all required properties to enabled */\n enabled: !!param.required,\n enum: parseEnum,\n examples,\n },\n requestExampleParametersSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${param.name} is invalid.`)\n return requestExampleParametersSchema.parse({})\n }\n\n return example\n}\n\n/**\n * Create new request example from a request\n * Iterates the name of the example if provided\n */\nexport function createExampleFromRequest(request: Request, name: string, server?: Server): RequestExample {\n // ---------------------------------------------------------------------------\n // Populate all parameters with an example value\n const parameters: Record<'path' | 'cookie' | 'header' | 'query' | 'headers', RequestExampleParameter[]> = {\n path: [],\n query: [],\n cookie: [],\n // deprecated TODO: add zod transform to remove\n header: [],\n headers: [{ key: 'Accept', value: '*/*', enabled: true }],\n }\n\n // Populated the separated params\n request.parameters?.forEach((p) => parameters[p.in].push(createParamInstance(p)))\n\n // TODO: add zod transform to remove header and only support headers\n if (parameters.header.length > 0) {\n parameters.headers = parameters.header\n parameters.header = []\n }\n\n // Get content type header\n const contentTypeHeader = parameters.headers.find((h) => h.key.toLowerCase() === 'content-type')\n\n // ---------------------------------------------------------------------------\n // Handle request body defaulting for various content type encodings\n const body: ExampleRequestBody = {\n activeBody: 'raw',\n }\n\n // If we have a request body or a content type header\n // TODO: we don't even handle path parameters here\n if (request.requestBody || contentTypeHeader?.value) {\n const requestBody = getRequestBodyFromOperation(request)\n const contentType = request.requestBody ? requestBody?.mimeType : contentTypeHeader?.value\n\n // Handle JSON and JSON-like mimetypes\n if (contentType?.includes('/json') || contentType?.endsWith('+json')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'json',\n mimeType: contentType,\n value: requestBody?.text ?? JSON.stringify({}),\n }\n }\n\n if (contentType === 'application/xml') {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'xml',\n value: requestBody?.text ?? '',\n }\n }\n\n /**\n * TODO: Are we loading example files from somewhere based on the spec?\n * How are we handling the body values\n */\n if (contentType === 'application/octet-stream') {\n body.activeBody = 'binary'\n body.binary = undefined\n }\n\n if (contentType === 'application/x-www-form-urlencoded' || contentType === 'multipart/form-data') {\n body.activeBody = 'formData'\n body.formData = {\n encoding: contentType === 'application/x-www-form-urlencoded' ? 'urlencoded' : 'form-data',\n value: (requestBody?.params || []).map((param) => {\n if (param.value instanceof File) {\n return {\n key: param.name,\n value: 'BINARY',\n file: param.value,\n enabled: true,\n }\n }\n return {\n key: param.name,\n value: param.value || '',\n enabled: true,\n }\n }),\n }\n }\n\n if (contentType?.startsWith('text/')) {\n body.activeBody = 'raw'\n body.raw = {\n encoding: 'text',\n value: requestBody?.text ?? '',\n }\n }\n\n // Add the content-type header if it doesn't exist and if it's not multipart request\n if (requestBody?.mimeType && !contentTypeHeader && !requestBody.mimeType.startsWith('multipart/')) {\n parameters.headers.push({\n key: 'Content-Type',\n value: requestBody.mimeType,\n enabled: true,\n })\n }\n }\n\n const serverVariables = server ? getServerVariableExamples(server) : {}\n\n // safe parse the example\n const example = schemaModel(\n {\n requestUid: request.uid,\n parameters,\n name,\n body,\n serverVariables,\n },\n requestExampleSchema,\n false,\n )\n\n if (!example) {\n console.warn(`Example at ${request.uid} is invalid.`)\n return requestExampleSchema.parse({})\n }\n return example\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,mBAAmB;AAC5B,SAAS,mCAAmC;AAC5C,SAAS,iCAAiC;AAenC,MAAM,iCAAiC,EAC3C,OAAO;AAAA,EACN,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE;AAAA,EAC1B,OAAO,EAAE,OAAO,OAAO,EAAE,QAAQ,EAAE;AAAA,EACnC,SAAS,EAAE,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACjC,MAAM,EAAE,IAAI,EAAE,SAAS;AAAA,EACvB,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,UAAU,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC/B,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACnC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACpC,MAAM,EACH,MAAM;AAAA;AAAA,IAEL,EAAE,OAAO;AAAA;AAAA,IAET,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,EACpB,CAAC,EACA,SAAS;AAAA,EACZ,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,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K,aAAa;AAClB,WAAK,MAAM;AAAA,QACT,UAAU;AAAA,QACV,OAAO,aAAa,QAAQ;AAAA,MAC9B;AAAA,IACF;AAGA,QAAI,aAAa,YAAY,CAAC,qBAAqB,CAAC,YAAY,SAAS,WAAW,YAAY,GAAG;AACjG,iBAAW,QAAQ,KAAK;AAAA,QACtB,KAAK;AAAA,QACL,OAAO,YAAY;AAAA,QACnB,SAAS;AAAA,MACX,CAAC;AAAA,IACH;AAAA,EACF;AAEA,QAAM,kBAAkB,SAAS,0BAA0B,MAAM,IAAI,CAAC;AAGtE,QAAM,UAAU;AAAA,IACd;AAAA,MACE,YAAY,QAAQ;AAAA,MACpB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,CAAC,SAAS;AACZ,YAAQ,KAAK,cAAc,QAAQ,GAAG,cAAc;AACpD,WAAO,qBAAqB,MAAM,CAAC,CAAC;AAAA,EACtC;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["example"]
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { type PostResponseSchema, XPostResponseSchema } from '@scalar/openapi-types/schemas/extensions';
|
|
3
3
|
import { XScalarStability } from '@scalar/types';
|
|
4
4
|
import { type RequestExample } from './request-examples.js';
|
|
5
|
-
export declare const requestMethods: readonly ["
|
|
5
|
+
export declare const requestMethods: readonly ["delete", "get", "head", "options", "patch", "post", "put", "trace"];
|
|
6
6
|
export type RequestMethod = (typeof requestMethods)[number];
|
|
7
7
|
/** A single set of populated values for a sent request */
|
|
8
8
|
export type ResponseInstance = Omit<Response, 'headers'> & {
|
|
@@ -58,9 +58,9 @@ export declare const oasRequestSchema: z.ZodObject<{
|
|
|
58
58
|
content: z.ZodOptional<z.ZodUnknown>;
|
|
59
59
|
style: z.ZodOptional<z.ZodEnum<{
|
|
60
60
|
matrix: "matrix";
|
|
61
|
-
simple: "simple";
|
|
62
|
-
form: "form";
|
|
63
61
|
label: "label";
|
|
62
|
+
form: "form";
|
|
63
|
+
simple: "simple";
|
|
64
64
|
spaceDelimited: "spaceDelimited";
|
|
65
65
|
pipeDelimited: "pipeDelimited";
|
|
66
66
|
deepObject: "deepObject";
|
|
@@ -156,9 +156,9 @@ export declare const requestSchema: z.ZodObject<{
|
|
|
156
156
|
content: z.ZodOptional<z.ZodUnknown>;
|
|
157
157
|
style: z.ZodOptional<z.ZodEnum<{
|
|
158
158
|
matrix: "matrix";
|
|
159
|
-
simple: "simple";
|
|
160
|
-
form: "form";
|
|
161
159
|
label: "label";
|
|
160
|
+
form: "form";
|
|
161
|
+
simple: "simple";
|
|
162
162
|
spaceDelimited: "spaceDelimited";
|
|
163
163
|
pipeDelimited: "pipeDelimited";
|
|
164
164
|
deepObject: "deepObject";
|
|
@@ -197,7 +197,6 @@ export declare const requestSchema: z.ZodObject<{
|
|
|
197
197
|
uid: z.core.$ZodBranded<z.ZodDefault<z.ZodOptional<z.ZodString>>, "operation">;
|
|
198
198
|
path: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
199
199
|
method: z.ZodDefault<z.ZodEnum<{
|
|
200
|
-
connect: "connect";
|
|
201
200
|
delete: "delete";
|
|
202
201
|
get: "get";
|
|
203
202
|
head: "head";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/requests.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvC,OAAO,EACL,KAAK,kBAAkB,EAEvB,mBAAmB,EACpB,MAAM,0CAA0C,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGhD,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,oBAAoB,CAAA;AAG9E,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoD3B,CAAA;AAyCF,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AACnE,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC,iBAAiB,CAAC,CAAA;AAExF,8CAA8C;AAC9C,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAKG,CAAA;AAE7B,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AACnD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA"}
|
|
@@ -10,7 +10,7 @@ import { oasSecurityRequirementSchema } from "@scalar/types/entities";
|
|
|
10
10
|
import { oasParameterSchema } from "./parameters.js";
|
|
11
11
|
import { xScalarExampleSchema } from "./request-examples.js";
|
|
12
12
|
import { oasExternalDocumentationSchema } from "./spec-objects.js";
|
|
13
|
-
const requestMethods = ["
|
|
13
|
+
const requestMethods = ["delete", "get", "head", "options", "patch", "post", "put", "trace"];
|
|
14
14
|
const requestBodySchema = z.any();
|
|
15
15
|
const oasRequestSchema = z.object({
|
|
16
16
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/requests.ts"],
|
|
4
|
-
"sourcesContent": ["import { selectedSecuritySchemeUidSchema } from '@/entities/shared/utility'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { type ZodSchema, z } from 'zod'\n\nimport {\n type PostResponseSchema,\n XCodeSamplesSchema,\n XPostResponseSchema,\n} from '@scalar/openapi-types/schemas/extensions'\nimport { XScalarStability } from '@scalar/types'\nimport { oasSecurityRequirementSchema } from '@scalar/types/entities'\nimport { oasParameterSchema } from './parameters'\nimport { type RequestExample, xScalarExampleSchema } from './request-examples'\nimport { oasExternalDocumentationSchema } from './spec-objects'\n\nexport const requestMethods = ['
|
|
5
|
-
"mappings": "AAAA,SAAS,uCAAuC;AAChD,SAA6B,oBAAoB;AACjD,SAAyB,SAAS;AAElC;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,oCAAoC;AAC7C,SAAS,0BAA0B;AACnC,SAA8B,4BAA4B;AAC1D,SAAS,sCAAsC;AAExC,MAAM,iBAAiB,CAAC,
|
|
4
|
+
"sourcesContent": ["import { selectedSecuritySchemeUidSchema } from '@/entities/shared/utility'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { type ZodSchema, z } from 'zod'\n\nimport {\n type PostResponseSchema,\n XCodeSamplesSchema,\n XPostResponseSchema,\n} from '@scalar/openapi-types/schemas/extensions'\nimport { XScalarStability } from '@scalar/types'\nimport { oasSecurityRequirementSchema } from '@scalar/types/entities'\nimport { oasParameterSchema } from './parameters'\nimport { type RequestExample, xScalarExampleSchema } from './request-examples'\nimport { oasExternalDocumentationSchema } from './spec-objects'\n\nexport const requestMethods = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'trace'] as const\n\nexport type RequestMethod = (typeof requestMethods)[number]\n\n/** A single set of populated values for a sent request */\nexport type ResponseInstance = Omit<Response, 'headers'> & {\n /** Store headers as an object to match what we had with axios */\n headers: Record<string, string>\n /** Keys of headers which set cookies */\n cookieHeaderKeys: string[]\n /** Time in ms the request took */\n duration: number\n /** The response status */\n status: number\n /** The response status text */\n statusText: string\n /** The response method */\n method: RequestMethod\n /** The request path */\n path: string\n} & (\n | {\n /** The response data */\n data: string | Blob\n /** The response size in bytes */\n size: number\n }\n | {\n /** A stream reader for a streamable response body */\n reader: ReadableStreamDefaultReader<Uint8Array>\n }\n )\n\n/** A single request/response set to save to the history stack */\nexport type RequestEvent = {\n request: RequestExample\n response: ResponseInstance\n timestamp: number\n}\n\n// TODO: Type body definitions\ntype RequestBody = object\nconst requestBodySchema = z.any() satisfies ZodSchema<RequestBody>\n\n/** Open API Compliant Request Validator */\nexport const oasRequestSchema = z.object({\n /**\n * A list of tags for API documentation control. Tags can be used for logical\n * grouping of operations by resources or any other qualifier.\n *\n * These tags are the openapi spec tag names, not uids\n */\n 'tags': z.string().array().optional(),\n /** A short summary of what the operation does. */\n 'summary': z.string().optional(),\n /** A verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation. */\n 'description': z.string().optional(),\n /**\n * Unique string used to identify the operation. The id MUST be unique among all operations described in the API.\n * The operationId value is case-sensitive. Tools and libraries MAY use the operationId to uniquely identify an\n * operation, therefore, it is RECOMMENDED to follow bin common programming naming conventions./\n */\n 'operationId': z.string().optional(),\n /**\n * A declaration of which security mechanisms can be used across the API. The list of\n * values includes alternative security requirement objects that can be used. Only\n * one of the security requirement objects need to be satisfied to authorize a request.\n * Individual operations can override this definition. To make security optional, an empty\n * security requirement ({}) can be included in the array.\n */\n 'security': z.array(oasSecurityRequirementSchema).optional(),\n /**\n * The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the\n * HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the\n * HTTP spec is vague (such as GET, HEAD and DELETE), requestBody is permitted but does not have well-defined\n * semantics and SHOULD be avoided if possible.\n */\n 'requestBody': requestBodySchema.optional(),\n /**\n * Request parameters\n */\n 'parameters': oasParameterSchema.array().optional(),\n /**\n * External documentation object\n */\n 'externalDocs': oasExternalDocumentationSchema.optional(),\n 'deprecated': z.boolean().optional(),\n /** Response formats */\n 'responses': z.record(z.string(), z.any()).optional(),\n /** Callbacks */\n 'callbacks': z.record(z.string(), z.record(z.string(), z.record(z.string(), z.any()))).optional(),\n /** xScalar examples */\n 'x-scalar-examples': z.record(z.string(), xScalarExampleSchema).optional(),\n /** Hide operations */\n 'x-internal': z.boolean().optional(),\n /** Ignore operations */\n 'x-scalar-ignore': z.boolean().optional(),\n})\n\n/**\n * An OpenAPI extension to indicate the stability of the operation\n *\n * @example\n * ```yaml\n * x-scalar-stability: deprecated\n * ```\n */\nconst ScalarStabilitySchema = z.object({\n 'x-scalar-stability': z\n .enum([XScalarStability.Deprecated, XScalarStability.Experimental, XScalarStability.Stable])\n .optional()\n .catch(undefined),\n})\n\n/**\n * Extended properties added to the spec definition for client usage\n *\n * WARNING: DO NOT ADD PROPERTIES THAT SHARE A NAME WITH OAS OPERATION ENTITIES\n *\n * This object is directly converted to a spec operation during saving\n */\nconst extendedRequestSchema = z.object({\n type: z.literal('request').optional().default('request'),\n uid: nanoidSchema.brand<ENTITY_BRANDS['OPERATION']>(),\n /** Path Key */\n path: z.string().optional().default(''),\n /** Request Method */\n method: z.enum(requestMethods).default('get'),\n /** List of server UIDs specific to the request */\n servers: z.string().brand<ENTITY_BRANDS['SERVER']>().array().default([]),\n /** The currently selected server */\n selectedServerUid: z.string().brand<ENTITY_BRANDS['SERVER']>().optional().nullable().default(null),\n /** List of example UIDs associated with the request */\n examples: z.string().brand<ENTITY_BRANDS['EXAMPLE']>().array().default([]),\n /** List of security scheme UIDs associated with the request */\n selectedSecuritySchemeUids: selectedSecuritySchemeUidSchema,\n})\n\nexport type PostResponseScript = z.infer<typeof PostResponseSchema>\nexport type PostResponseScripts = z.infer<typeof XPostResponseSchema>['x-post-response']\n\n/** Unified request schema for client usage */\nexport const requestSchema = oasRequestSchema\n .omit({ 'x-scalar-examples': true })\n .merge(XCodeSamplesSchema)\n .merge(ScalarStabilitySchema)\n .merge(extendedRequestSchema)\n .merge(XPostResponseSchema)\n\nexport type Request = z.infer<typeof requestSchema>\nexport type RequestPayload = z.input<typeof requestSchema>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uCAAuC;AAChD,SAA6B,oBAAoB;A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AEzE,cAAc,EAAE,QAAQ,EAAE,SAAS;AAAA;AAAA,EAEnC,mBAAmB,EAAE,QAAQ,EAAE,SAAS;AAC1C,CAAC;AAUD,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,sBAAsB,EACnB,KAAK,CAAC,iBAAiB,YAAY,iBAAiB,cAAc,iBAAiB,MAAM,CAAC,EAC1F,SAAS,EACT,MAAM,MAAS;AACpB,CAAC;AASD,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,MAAM,EAAE,QAAQ,SAAS,EAAE,SAAS,EAAE,QAAQ,SAAS;AAAA,EACvD,KAAK,aAAa,MAAkC;AAAA;AAAA,EAEpD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE;AAAA;AAAA,EAEtC,QAAQ,EAAE,KAAK,cAAc,EAAE,QAAQ,KAAK;AAAA;AAAA,EAE5C,SAAS,EAAE,OAAO,EAAE,MAA+B,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEvE,mBAAmB,EAAE,OAAO,EAAE,MAA+B,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,IAAI;AAAA;AAAA,EAEjG,UAAU,EAAE,OAAO,EAAE,MAAgC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;AAAA;AAAA,EAEzE,4BAA4B;AAC9B,CAAC;AAMM,MAAM,gBAAgB,iBAC1B,KAAK,EAAE,qBAAqB,KAAK,CAAC,EAClC,MAAM,kBAAkB,EACxB,MAAM,qBAAqB,EAC3B,MAAM,qBAAqB,EAC3B,MAAM,mBAAmB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Webhook } from '@scalar/types/legacy';
|
|
2
|
-
import type { Request } from '../entities/spec/requests.js';
|
|
3
|
-
import type { Tag } from '../entities/spec/spec-objects.js';
|
|
4
1
|
/**
|
|
5
2
|
* Check if an entity should be ignored
|
|
6
3
|
*/
|
|
7
|
-
export declare const shouldIgnoreEntity: (data:
|
|
4
|
+
export declare const shouldIgnoreEntity: (data: {
|
|
5
|
+
"x-internal"?: boolean;
|
|
6
|
+
"x-scalar-ignore"?: boolean;
|
|
7
|
+
}) => boolean;
|
|
8
8
|
//# sourceMappingURL=should-ignore-entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"should-ignore-entity.d.ts","sourceRoot":"","sources":["../../src/helpers/should-ignore-entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"should-ignore-entity.d.ts","sourceRoot":"","sources":["../../src/helpers/should-ignore-entity.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM;IAAE,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,YAC3B,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/should-ignore-entity.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Check if an entity should be ignored\n */\nexport const shouldIgnoreEntity = (data: { 'x-internal'?: boolean; 'x-scalar-ignore'?: boolean }) =>\n data?.['x-internal'] === true || data?.['x-scalar-ignore'] === true\n"],
|
|
5
|
+
"mappings": "AAGO,MAAM,qBAAqB,CAAC,SACjC,OAAO,YAAY,MAAM,QAAQ,OAAO,iBAAiB,MAAM;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.5.0/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,GAAI,MAAM,OAAO,CAAC,UAAU,KAAG,OAAO,CAAC,YAAY,
|
|
1
|
+
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/migrations/v-2.5.0/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAA;AAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,mCAAmC;AACnC,eAAO,MAAM,eAAe,GAAI,MAAM,OAAO,CAAC,UAAU,KAAG,OAAO,CAAC,YAAY,CAwK9E,CAAA"}
|
|
@@ -40,13 +40,17 @@ const migrate_v_2_5_0 = (data) => {
|
|
|
40
40
|
);
|
|
41
41
|
const requests = Object.entries(data.requests || {}).reduce(
|
|
42
42
|
(acc, [key, request]) => {
|
|
43
|
+
if (request.method === "connect") {
|
|
44
|
+
return acc;
|
|
45
|
+
}
|
|
43
46
|
acc[key] = {
|
|
44
47
|
...request,
|
|
45
48
|
uid: request.uid,
|
|
46
49
|
servers: request.servers,
|
|
47
50
|
selectedServerUid: request.selectedServerUid,
|
|
48
51
|
examples: request.examples,
|
|
49
|
-
selectedSecuritySchemeUids: request.selectedSecuritySchemeUids
|
|
52
|
+
selectedSecuritySchemeUids: request.selectedSecuritySchemeUids,
|
|
53
|
+
method: request.method
|
|
50
54
|
};
|
|
51
55
|
return acc;
|
|
52
56
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/migrations/v-2.5.0/migration.ts"],
|
|
4
|
-
"sourcesContent": ["import type { v_2_4_0 } from '@/migrations/v-2.4.0/types.generated'\n\nimport type { v_2_5_0 } from './types.generated'\n\n/** V-2.4.0 to V-2.5.0 migration */\nexport const migrate_v_2_5_0 = (data: v_2_4_0.DataRecord): v_2_5_0['DataRecord'] => {\n console.info('Performing data migration v-2.4.0 to v-2.5.0')\n\n const cookies = Object.entries(data.cookies || {}).reduce<Record<string, v_2_5_0['Cookie']>>((acc, [key, cookie]) => {\n acc[key] = {\n ...cookie,\n uid: cookie.uid as v_2_5_0['Cookie']['uid'],\n } satisfies v_2_5_0['Cookie']\n return acc\n }, {})\n\n const collections = Object.entries(data.collections || {}).reduce<Record<string, v_2_5_0['Collection']>>(\n (acc, [key, collection]) => {\n acc[key] = {\n ...collection,\n info: collection.info ?? {\n title: 'API',\n version: '1.0',\n },\n uid: collection.uid as v_2_5_0['Collection']['uid'],\n selectedSecuritySchemeUids:\n collection.selectedSecuritySchemeUids as v_2_5_0['Collection']['selectedSecuritySchemeUids'],\n servers: collection.servers.map((uid) => uid as v_2_5_0['Server']['uid']),\n tags: collection.tags.map((uid) => uid as v_2_5_0['Tag']['uid']),\n requests: collection.requests.map((uid) => uid as v_2_5_0['Request']['uid']),\n children: collection.children.map((uid) => uid as v_2_5_0['Request']['uid'] | v_2_5_0['Tag']['uid']),\n selectedServerUid: collection.selectedServerUid as v_2_5_0['Server']['uid'],\n useCollectionSecurity: false,\n } satisfies v_2_5_0['Collection']\n return acc\n },\n {},\n )\n\n const environments = Object.entries(data.environments || {}).reduce<Record<string, v_2_5_0['Environment']>>(\n (acc, [key, environment]) => {\n acc[key] = {\n ...environment,\n uid: environment.uid as v_2_5_0['Environment']['uid'],\n } satisfies v_2_5_0['Environment']\n return acc\n },\n {},\n )\n\n const requests = Object.entries(data.requests || {}).reduce<Record<string, v_2_5_0['Request']>>(\n (acc, [key, request]) => {\n acc[key] = {\n ...request,\n uid: request.uid as v_2_5_0['Request']['uid'],\n servers: request.servers as v_2_5_0['Request']['servers'],\n selectedServerUid: request.selectedServerUid as v_2_5_0['Request']['selectedServerUid'],\n examples: request.examples as v_2_5_0['Request']['examples'],\n selectedSecuritySchemeUids:\n request.selectedSecuritySchemeUids as v_2_5_0['Request']['selectedSecuritySchemeUids'],\n } satisfies v_2_5_0['Request']\n return acc\n },\n {},\n )\n\n const requestExamples = Object.entries(data.requestExamples || {}).reduce<Record<string, v_2_5_0['RequestExample']>>(\n (acc, [key, example]) => {\n const headers = example.parameters.headers\n\n // Check if \"Accept\" header exists\n const hasAcceptHeader = headers.some((header) => header.key.toLowerCase() === 'accept')\n\n if (!hasAcceptHeader) {\n // Add \"Accept\" header as the first entry\n headers.unshift({ key: 'Accept', value: '*/*', enabled: true })\n }\n\n // Update the example with potentially modified headers\n acc[key] = {\n ...example,\n uid: example.uid as v_2_5_0['RequestExample']['uid'],\n requestUid: example.requestUid as v_2_5_0['RequestExample']['requestUid'],\n parameters: {\n ...example.parameters,\n headers,\n },\n }\n return acc\n },\n {},\n )\n\n const securitySchemes = Object.entries(data.securitySchemes || {}).reduce<Record<string, v_2_5_0['SecurityScheme']>>(\n (acc, [key, securityScheme]) => {\n acc[key] = {\n ...securityScheme,\n uid: securityScheme.uid as v_2_5_0['SecurityScheme']['uid'],\n } satisfies v_2_5_0['SecurityScheme']\n return acc\n },\n {},\n )\n\n const servers = Object.entries(data.servers || {}).reduce<Record<string, v_2_5_0['Server']>>((acc, [key, server]) => {\n acc[key] = {\n ...server,\n uid: server.uid as v_2_5_0['Server']['uid'],\n variables: Object.entries(server.variables || {}).reduce<\n Record<\n string,\n {\n enum?: [string, ...string[]]\n default: string\n description?: string\n }\n >\n >((variablesAcc, [variableKey, variable]) => {\n variablesAcc[variableKey] = {\n default: variable.default ?? '',\n description: variable.description ?? '',\n ...(variable.enum?.length && { enum: variable.enum as [string, ...string[]] }),\n }\n return variablesAcc\n }, {}),\n }\n return acc\n }, {})\n\n const tags = Object.entries(data.tags || {}).reduce<Record<string, v_2_5_0['Tag']>>((acc, [key, tag]) => {\n acc[key] = {\n ...tag,\n uid: tag.uid as v_2_5_0['Tag']['uid'],\n children: tag.children as v_2_5_0['Tag']['children'],\n } satisfies v_2_5_0['Tag']\n return acc\n }, {})\n\n const workspaces = Object.entries(data.workspaces || {}).reduce<Record<string, v_2_5_0['Workspace']>>(\n (acc, [key, workspace]) => {\n acc[key] = {\n ...workspace,\n uid: workspace.uid as v_2_5_0['Workspace']['uid'],\n collections: workspace.collections.map((uid) => uid as v_2_5_0['Collection']['uid']),\n cookies: workspace.cookies.map((uid) => uid as v_2_5_0['Cookie']['uid']),\n selectedHttpClient: {\n targetKey: 'shell',\n clientKey: 'curl',\n },\n }\n return acc\n },\n {},\n )\n\n return {\n ...data,\n collections,\n cookies,\n environments,\n requests,\n requestExamples,\n securitySchemes,\n servers,\n tags,\n workspaces,\n } satisfies v_2_5_0['DataRecord']\n}\n"],
|
|
5
|
-
"mappings": "AAKO,MAAM,kBAAkB,CAAC,SAAoD;AAClF,UAAQ,KAAK,8CAA8C;AAE3D,QAAM,UAAU,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,EAAE,OAA0C,CAAC,KAAK,CAAC,KAAK,MAAM,MAAM;AACnH,QAAI,GAAG,IAAI;AAAA,MACT,GAAG;AAAA,MACH,KAAK,OAAO;AAAA,IACd;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,QAAM,cAAc,OAAO,QAAQ,KAAK,eAAe,CAAC,CAAC,EAAE;AAAA,IACzD,CAAC,KAAK,CAAC,KAAK,UAAU,MAAM;AAC1B,UAAI,GAAG,IAAI;AAAA,QACT,GAAG;AAAA,QACH,MAAM,WAAW,QAAQ;AAAA,UACvB,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA,KAAK,WAAW;AAAA,QAChB,4BACE,WAAW;AAAA,QACb,SAAS,WAAW,QAAQ,IAAI,CAAC,QAAQ,GAA+B;AAAA,QACxE,MAAM,WAAW,KAAK,IAAI,CAAC,QAAQ,GAA4B;AAAA,QAC/D,UAAU,WAAW,SAAS,IAAI,CAAC,QAAQ,GAAgC;AAAA,QAC3E,UAAU,WAAW,SAAS,IAAI,CAAC,QAAQ,GAAwD;AAAA,QACnG,mBAAmB,WAAW;AAAA,QAC9B,uBAAuB;AAAA,MACzB;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,eAAe,OAAO,QAAQ,KAAK,gBAAgB,CAAC,CAAC,EAAE;AAAA,IAC3D,CAAC,KAAK,CAAC,KAAK,WAAW,MAAM;AAC3B,UAAI,GAAG,IAAI;AAAA,QACT,GAAG;AAAA,QACH,KAAK,YAAY;AAAA,MACnB;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,OAAO,QAAQ,KAAK,YAAY,CAAC,CAAC,EAAE;AAAA,IACnD,CAAC,KAAK,CAAC,KAAK,OAAO,MAAM;
|
|
4
|
+
"sourcesContent": ["import type { v_2_4_0 } from '@/migrations/v-2.4.0/types.generated'\n\nimport type { v_2_5_0 } from './types.generated'\n\n/** V-2.4.0 to V-2.5.0 migration */\nexport const migrate_v_2_5_0 = (data: v_2_4_0.DataRecord): v_2_5_0['DataRecord'] => {\n console.info('Performing data migration v-2.4.0 to v-2.5.0')\n\n const cookies = Object.entries(data.cookies || {}).reduce<Record<string, v_2_5_0['Cookie']>>((acc, [key, cookie]) => {\n acc[key] = {\n ...cookie,\n uid: cookie.uid as v_2_5_0['Cookie']['uid'],\n } satisfies v_2_5_0['Cookie']\n return acc\n }, {})\n\n const collections = Object.entries(data.collections || {}).reduce<Record<string, v_2_5_0['Collection']>>(\n (acc, [key, collection]) => {\n acc[key] = {\n ...collection,\n info: collection.info ?? {\n title: 'API',\n version: '1.0',\n },\n uid: collection.uid as v_2_5_0['Collection']['uid'],\n selectedSecuritySchemeUids:\n collection.selectedSecuritySchemeUids as v_2_5_0['Collection']['selectedSecuritySchemeUids'],\n servers: collection.servers.map((uid) => uid as v_2_5_0['Server']['uid']),\n tags: collection.tags.map((uid) => uid as v_2_5_0['Tag']['uid']),\n requests: collection.requests.map((uid) => uid as v_2_5_0['Request']['uid']),\n children: collection.children.map((uid) => uid as v_2_5_0['Request']['uid'] | v_2_5_0['Tag']['uid']),\n selectedServerUid: collection.selectedServerUid as v_2_5_0['Server']['uid'],\n useCollectionSecurity: false,\n } satisfies v_2_5_0['Collection']\n return acc\n },\n {},\n )\n\n const environments = Object.entries(data.environments || {}).reduce<Record<string, v_2_5_0['Environment']>>(\n (acc, [key, environment]) => {\n acc[key] = {\n ...environment,\n uid: environment.uid as v_2_5_0['Environment']['uid'],\n } satisfies v_2_5_0['Environment']\n return acc\n },\n {},\n )\n\n const requests = Object.entries(data.requests || {}).reduce<Record<string, v_2_5_0['Request']>>(\n (acc, [key, request]) => {\n // Skip 'connect' operations as they are not supported in v-2.5.0\n if (request.method === 'connect') {\n return acc\n }\n\n acc[key] = {\n ...request,\n uid: request.uid as v_2_5_0['Request']['uid'],\n servers: request.servers as v_2_5_0['Request']['servers'],\n selectedServerUid: request.selectedServerUid as v_2_5_0['Request']['selectedServerUid'],\n examples: request.examples as v_2_5_0['Request']['examples'],\n selectedSecuritySchemeUids:\n request.selectedSecuritySchemeUids as v_2_5_0['Request']['selectedSecuritySchemeUids'],\n method: request.method as v_2_5_0['Request']['method'],\n } satisfies v_2_5_0['Request']\n return acc\n },\n {},\n )\n\n const requestExamples = Object.entries(data.requestExamples || {}).reduce<Record<string, v_2_5_0['RequestExample']>>(\n (acc, [key, example]) => {\n const headers = example.parameters.headers\n\n // Check if \"Accept\" header exists\n const hasAcceptHeader = headers.some((header) => header.key.toLowerCase() === 'accept')\n\n if (!hasAcceptHeader) {\n // Add \"Accept\" header as the first entry\n headers.unshift({ key: 'Accept', value: '*/*', enabled: true })\n }\n\n // Update the example with potentially modified headers\n acc[key] = {\n ...example,\n uid: example.uid as v_2_5_0['RequestExample']['uid'],\n requestUid: example.requestUid as v_2_5_0['RequestExample']['requestUid'],\n parameters: {\n ...example.parameters,\n headers,\n },\n }\n return acc\n },\n {},\n )\n\n const securitySchemes = Object.entries(data.securitySchemes || {}).reduce<Record<string, v_2_5_0['SecurityScheme']>>(\n (acc, [key, securityScheme]) => {\n acc[key] = {\n ...securityScheme,\n uid: securityScheme.uid as v_2_5_0['SecurityScheme']['uid'],\n } satisfies v_2_5_0['SecurityScheme']\n return acc\n },\n {},\n )\n\n const servers = Object.entries(data.servers || {}).reduce<Record<string, v_2_5_0['Server']>>((acc, [key, server]) => {\n acc[key] = {\n ...server,\n uid: server.uid as v_2_5_0['Server']['uid'],\n variables: Object.entries(server.variables || {}).reduce<\n Record<\n string,\n {\n enum?: [string, ...string[]]\n default: string\n description?: string\n }\n >\n >((variablesAcc, [variableKey, variable]) => {\n variablesAcc[variableKey] = {\n default: variable.default ?? '',\n description: variable.description ?? '',\n ...(variable.enum?.length && { enum: variable.enum as [string, ...string[]] }),\n }\n return variablesAcc\n }, {}),\n }\n return acc\n }, {})\n\n const tags = Object.entries(data.tags || {}).reduce<Record<string, v_2_5_0['Tag']>>((acc, [key, tag]) => {\n acc[key] = {\n ...tag,\n uid: tag.uid as v_2_5_0['Tag']['uid'],\n children: tag.children as v_2_5_0['Tag']['children'],\n } satisfies v_2_5_0['Tag']\n return acc\n }, {})\n\n const workspaces = Object.entries(data.workspaces || {}).reduce<Record<string, v_2_5_0['Workspace']>>(\n (acc, [key, workspace]) => {\n acc[key] = {\n ...workspace,\n uid: workspace.uid as v_2_5_0['Workspace']['uid'],\n collections: workspace.collections.map((uid) => uid as v_2_5_0['Collection']['uid']),\n cookies: workspace.cookies.map((uid) => uid as v_2_5_0['Cookie']['uid']),\n selectedHttpClient: {\n targetKey: 'shell',\n clientKey: 'curl',\n },\n }\n return acc\n },\n {},\n )\n\n return {\n ...data,\n collections,\n cookies,\n environments,\n requests,\n requestExamples,\n securitySchemes,\n servers,\n tags,\n workspaces,\n } satisfies v_2_5_0['DataRecord']\n}\n"],
|
|
5
|
+
"mappings": "AAKO,MAAM,kBAAkB,CAAC,SAAoD;AAClF,UAAQ,KAAK,8CAA8C;AAE3D,QAAM,UAAU,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,EAAE,OAA0C,CAAC,KAAK,CAAC,KAAK,MAAM,MAAM;AACnH,QAAI,GAAG,IAAI;AAAA,M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AS,WAAW;AAAA,UAC7B,aAAa,SAAS,eAAe;AAAA,UACrC,GAAI,SAAS,MAAM,UAAU,EAAE,MAAM,SAAS,KAA8B;AAAA,QAC9E;AACA,eAAO;AAAA,MACT,GAAG,CAAC,CAAC;AAAA,IACP;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,QAAM,OAAO,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,EAAE,OAAuC,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM;AACvG,QAAI,GAAG,IAAI;AAAA,MACT,GAAG;AAAA,MACH,KAAK,IAAI;AAAA,MACT,UAAU,IAAI;AAAA,IAChB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,OAAO,QAAQ,KAAK,cAAc,CAAC,CAAC,EAAE;AAAA,IACvD,CAAC,KAAK,CAAC,KAAK,SAAS,MAAM;AACzB,UAAI,GAAG,IAAI;AAAA,QACT,GAAG;AAAA,QACH,KAAK,UAAU;AAAA,QACf,aAAa,UAAU,YAAY,IAAI,CAAC,QAAQ,GAAmC;AAAA,QACnF,SAAS,UAAU,QAAQ,IAAI,CAAC,QAAQ,GAA+B;AAAA,QACvE,oBAAoB;AAAA,UAClB,WAAW;AAAA,UACX,WAAW;AAAA,QACb;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -13,6 +13,8 @@ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
|
13
13
|
* @param parentSchema - The parent schema, if any.
|
|
14
14
|
* @param name - The name of the property being processed.
|
|
15
15
|
* @returns An example value for the given schema.
|
|
16
|
+
*
|
|
17
|
+
* @deprecated Use the one from `@scalar/api-client/v2/blocks/operation-code-sample` instead.
|
|
16
18
|
*/
|
|
17
19
|
export declare const getExampleFromSchema: (schema: OpenAPIV3_1.SchemaObject, options?: {
|
|
18
20
|
/** Fallback string for empty string values. */
|
|
@@ -1 +1 @@
|
|
|
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,WAAW,EAAE,MAAM,uBAAuB,CAAA;AA4bxD
|
|
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,WAAW,EAAE,MAAM,uBAAuB,CAAA;AA4bxD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,WAAW,CAAC,YAAY,EAChC,UAAU;IACR,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4CAA4C;IAC5C,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,uDAAuD;IACvD,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACvB,iEAAiE;IACjE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,qDAAqD;IACrD,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,EACD,OAAO,OAAO,CAAC;IACb,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,EAAE,WAAW,CAAC,YAAY,CAAA;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;CACtB,CAAC,KACD,GAyJF,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/spec-getters/get-example-from-schema.ts"],
|
|
4
|
-
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { getRaw } from '@scalar/json-magic/magic-proxy'\nimport type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackOverridesProxy } from '@scalar/workspace-store/helpers/overrides-proxy'\n\n/** Maximum recursion depth to prevent infinite loops in circular references */\nconst MAX_LEVELS_DEEP = 10\n\n/**\n * Maximum properties to include after level 3 to prevent exponential growth\n * in deeply nested object structures\n */\nconst MAX_PROPERTIES = 10\n\n/** Default name used for additional properties when no custom name is provided */\nconst DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'propertyName*'\n\n/**\n * Pre-computed date/time values to avoid expensive Date operations on every call.\n * These are calculated once at module load time for better performance.\n */\nconst currentISOString = new Date().toISOString()\nconst currentDateString = currentISOString.split('T')[0]!\nconst currentTimeString = currentISOString.split('T')[1]!.split('.')[0]!\n\n/**\n * Mapping of OpenAPI string formats to example values.\n * Used to generate realistic examples for different string formats.\n */\nconst genericExampleValues: Record<string, string> = {\n 'date-time': currentISOString,\n 'date': currentDateString,\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': currentTimeString,\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 * Generate example values for string types based on their format.\n * Special handling for binary format which returns a File object.\n */\nconst guessFromFormat = (\n schema: OpenAPIV3_1.SchemaObject,\n makeUpRandomData: boolean = false,\n fallback: string = '',\n): string | File => {\n // Handle binary format specially - return a File object\n if ('type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary') {\n return new File([''], 'filename')\n }\n\n // Return format-specific example if we have one and are making up data\n if (makeUpRandomData && 'format' in schema && schema.format) {\n return genericExampleValues[schema.format] ?? fallback\n }\n\n return fallback\n}\n\n/**\n * WeakMap cache for memoizing resolved example results.\n * Uses the resolved schema object as the key for efficient lookups.\n */\nconst resultCache = new WeakMap<object, unknown>()\n\n/** Cache required property names per parent schema for O(1) membership checks */\nconst requiredNamesCache = new WeakMap<object, ReadonlySet<string>>()\n\n/**\n * Retrieves the set of required property names from a schema.\n * Caches the result in a WeakMap for efficient lookups.\n */\nconst getRequiredNames = (parentSchema: OpenAPIV3_1.SchemaObject | undefined): ReadonlySet<string> | undefined => {\n if (!parentSchema) {\n return undefined\n }\n\n const cached = requiredNamesCache.get(parentSchema)\n if (cached) {\n return cached\n }\n\n if ('required' in parentSchema) {\n const required = parentSchema.required\n if (Array.isArray(required) && required.length > 0) {\n const set = new Set<string>(required)\n requiredNamesCache.set(parentSchema, set)\n return set\n }\n }\n\n return undefined\n}\n\n/**\n * Cache the result for a schema if it is an object type.\n * Primitive values are not cached to avoid unnecessary WeakMap operations.\n */\nconst cache = (schema: OpenAPIV3_1.SchemaObject, result: unknown) => {\n if (typeof result !== 'object' || result === null) {\n return result\n }\n resultCache.set(getRaw(unpackOverridesProxy(schema)), result)\n return result\n}\n\n/**\n * Check if a schema uses composition keywords (allOf, oneOf, anyOf).\n * These require special handling for merging or selecting schemas.\n */\nconst isComposed = (schema: OpenAPIV3_1.SchemaObject): boolean => !!(schema.allOf || schema.oneOf || schema.anyOf)\n\n/**\n * Determine if a property should be omitted based on the options.\n * Properties are omitted if they are not required and the option is enabled.\n */\nconst shouldOmitProperty = (\n schema: OpenAPIV3_1.SchemaObject,\n parentSchema: OpenAPIV3_1.SchemaObject | undefined,\n propertyName: string | undefined,\n options: { omitEmptyAndOptionalProperties?: boolean } | undefined,\n): boolean => {\n if (options?.omitEmptyAndOptionalProperties !== true) {\n return false\n }\n\n // Never omit container types (objects/arrays) or composed schemas\n const isContainer = ('type' in schema && (schema.type === 'object' || schema.type === 'array')) || isComposed(schema)\n if (isContainer) {\n return false\n }\n\n // Do not omit if explicit example-like values are present\n if (\n ('examples' in schema && Array.isArray(schema.examples) && schema.examples.length > 0) ||\n ('example' in schema && schema.example !== undefined) ||\n ('default' in schema && schema.default !== undefined) ||\n ('const' in schema && schema.const !== undefined) ||\n ('enum' in schema && Array.isArray(schema.enum) && schema.enum.length > 0)\n ) {\n return false\n }\n\n // Check if the property is required\n const name = propertyName ?? schema.title ?? ''\n const requiredNames = getRequiredNames(parentSchema)\n const isRequired = requiredNames ? requiredNames.has(name) : false\n\n return !isRequired\n}\n\n/**\n * Merge two example values with predictable semantics.\n * Arrays are concatenated, objects are merged, otherwise the new value wins.\n */\nconst mergeExamples = (baseValue: unknown, newValue: unknown): unknown => {\n if (Array.isArray(baseValue) && Array.isArray(newValue)) {\n return [...baseValue, ...newValue]\n }\n if (baseValue && typeof baseValue === 'object' && newValue && typeof newValue === 'object') {\n return { ...(baseValue as Record<string, unknown>), ...(newValue as Record<string, unknown>) }\n }\n return newValue\n}\n\n/**\n * Build an example for an object schema, including properties, patternProperties,\n * additionalProperties, and composition (allOf/oneOf/anyOf) merging.\n */\nconst handleObjectSchema = (\n schema: OpenAPIV3_1.SchemaObject,\n options: Parameters<typeof getExampleFromSchema>[1],\n level: number,\n seen: WeakSet<object>,\n): unknown => {\n const response: Record<string, unknown> = {}\n\n if ('properties' in schema && schema.properties) {\n const propertyNames = Object.keys(schema.properties)\n const limit = level > 3 ? Math.min(MAX_PROPERTIES, propertyNames.length) : propertyNames.length\n\n for (let i = 0; i < limit; i++) {\n const propertyName = propertyNames[i]!\n const propertySchema = getResolvedRef(schema.properties[propertyName])\n if (!propertySchema) {\n continue\n }\n\n const propertyXmlName = options?.xml && 'xml' in propertySchema ? propertySchema.xml?.name : undefined\n const value = getExampleFromSchema(propertySchema, options, {\n level: level + 1,\n parentSchema: schema,\n name: propertyName,\n seen,\n })\n\n if (typeof value !== 'undefined') {\n response[propertyXmlName ?? propertyName] = value\n }\n }\n\n if (level > 3 && propertyNames.length > MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n }\n }\n\n if ('patternProperties' in schema && schema.patternProperties) {\n for (const pattern of Object.keys(schema.patternProperties)) {\n const propertySchema = getResolvedRef(schema.patternProperties[pattern])\n if (!propertySchema) {\n continue\n }\n response[pattern] = getExampleFromSchema(propertySchema, options, {\n level: level + 1,\n parentSchema: schema,\n name: pattern,\n seen,\n })\n }\n }\n\n if (\n 'additionalProperties' in schema &&\n schema.additionalProperties !== undefined &&\n schema.additionalProperties !== false\n ) {\n const additional = getResolvedRef(schema.additionalProperties)\n const isAnyType =\n schema.additionalProperties === true ||\n (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length === 0)\n\n const additionalName =\n typeof additional === 'object' &&\n 'x-additionalPropertiesName' in additional &&\n typeof additional['x-additionalPropertiesName'] === 'string' &&\n additional['x-additionalPropertiesName'].trim().length > 0\n ? `${additional['x-additionalPropertiesName'].trim()}*`\n : DEFAULT_ADDITIONAL_PROPERTIES_NAME\n\n response[additionalName] = isAnyType\n ? 'anything'\n : typeof additional === 'object'\n ? getExampleFromSchema(additional, options, {\n level: level + 1,\n seen,\n })\n : 'anything'\n }\n\n // onOf\n if (schema.oneOf?.[0]) {\n Object.assign(\n response,\n getExampleFromSchema(getResolvedRef(schema.oneOf[0]), options, {\n level: level + 1,\n seen,\n }),\n )\n }\n // anyOf\n else if (schema.anyOf?.[0]) {\n Object.assign(\n response,\n getExampleFromSchema(getResolvedRef(schema.anyOf[0]), options, {\n level: level + 1,\n seen,\n }),\n )\n }\n // allOf\n else if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {\n let merged: unknown = response\n for (const item of schema.allOf) {\n const ex = getExampleFromSchema(getResolvedRef(item), options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n })\n merged = mergeExamples(merged, ex)\n }\n if (merged && typeof merged === 'object') {\n Object.assign(response, merged as Record<string, unknown>)\n }\n }\n\n if (options?.xml && 'xml' in schema && schema.xml?.name && level === 0) {\n const wrapped: Record<string, unknown> = {}\n wrapped[schema.xml.name] = response\n return cache(schema, wrapped)\n }\n\n return cache(schema, response)\n}\n\n/** Build an example for an array schema, including items, allOf, oneOf/anyOf, and XML wrapping */\nconst handleArraySchema = (\n schema: OpenAPIV3_1.SchemaObject,\n options: Parameters<typeof getExampleFromSchema>[1],\n level: number,\n seen: WeakSet<object>,\n) => {\n const items = 'items' in schema ? getResolvedRef(schema.items) : undefined\n const itemsXmlTagName = items && typeof items === 'object' && 'xml' in items ? items.xml?.name : undefined\n const wrapItems = !!(options?.xml && 'xml' in schema && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName as string]: schema.example } : schema.example)\n }\n\n if (items && typeof items === 'object') {\n if (Array.isArray(items.allOf) && items.allOf.length > 0) {\n const allOf = items.allOf.filter(isDefined)\n const first = getResolvedRef(allOf[0])\n\n if (first && typeof first === 'object' && 'type' in first && first.type === 'object') {\n const combined: OpenAPIV3_1.SchemaObject = { type: 'object', allOf }\n const merged = getExampleFromSchema(combined, options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n })\n return cache(schema, wrapItems ? [{ [itemsXmlTagName as string]: merged }] : [merged])\n }\n\n const examples = allOf\n .map((s: any) =>\n getExampleFromSchema(getResolvedRef(s), options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n }),\n )\n .filter(isDefined)\n return cache(\n schema,\n wrapItems ? (examples as unknown[]).map((e) => ({ [itemsXmlTagName as string]: e })) : examples,\n )\n }\n\n const union = items.anyOf || items.oneOf\n if (union && union.length > 0) {\n const first = union[0] as OpenAPIV3_1.SchemaObject\n const ex = getExampleFromSchema(getResolvedRef(first), options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n })\n return cache(schema, wrapItems ? [{ [itemsXmlTagName as string]: ex }] : [ex])\n }\n }\n\n const isObject =\n items && typeof items === 'object' && (('type' in items && items.type === 'object') || 'properties' in items)\n const isArray =\n items && typeof items === 'object' && (('type' in items && items.type === 'array') || 'items' in items)\n\n if (items && typeof items === 'object' && (('type' in items && items.type) || isObject || isArray)) {\n const ex = getExampleFromSchema(items as OpenAPIV3_1.SchemaObject, options, {\n level: level + 1,\n seen,\n })\n return cache(schema, wrapItems ? [{ [itemsXmlTagName as string]: ex }] : [ex])\n }\n\n return cache(schema, [])\n}\n\n/** Return primitive example value for single-type schemas, or undefined if not primitive */\nconst getPrimitiveValue = (\n schema: OpenAPIV3_1.SchemaObject,\n makeUpRandomData: boolean,\n emptyString: string | undefined,\n) => {\n if ('type' in schema && schema.type && !Array.isArray(schema.type)) {\n switch (schema.type) {\n case 'string':\n return guessFromFormat(schema, makeUpRandomData, emptyString ?? '')\n case 'boolean':\n return true\n case 'integer':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'number':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'array':\n return []\n default:\n return undefined\n }\n }\n return undefined\n}\n\n/** Return primitive example value for union-type schemas (type: string[]) */\nconst getUnionPrimitiveValue = (\n schema: OpenAPIV3_1.SchemaObject,\n makeUpRandomData: boolean,\n emptyString: string | undefined,\n) => {\n if ('type' in schema && Array.isArray(schema.type)) {\n if (schema.type.includes('null')) {\n return null\n }\n\n const first = schema.type[0]\n if (first) {\n switch (first) {\n case 'string':\n return guessFromFormat(schema, makeUpRandomData, emptyString ?? '')\n case 'boolean':\n return true\n case 'integer':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'number':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'null':\n return null\n default:\n return undefined\n }\n }\n }\n return undefined\n}\n\n/**\n * Generate an example value from a given OpenAPI SchemaObject.\n *\n * This function recursively processes OpenAPI schemas to create realistic example data.\n * It handles all OpenAPI schema types including primitives, objects, arrays, and\n * composition schemas (allOf, oneOf, anyOf).\n * Uses a tonne of caching for maximum performance.\n *\n * @param schema - The OpenAPI SchemaObject to generate an example from.\n * @param options - Options to customize example generation.\n * @param level - The current recursion depth.\n * @param parentSchema - The parent schema, if any.\n * @param name - The name of the property being processed.\n * @returns An example value for the given schema.\n */\nexport const getExampleFromSchema = (\n schema: OpenAPIV3_1.SchemaObject,\n options?: {\n /** Fallback string for empty string values. */\n emptyString?: string\n /** Whether to use XML tag names as keys. */\n xml?: boolean\n /** Whether to show read-only/write-only properties. */\n mode?: 'read' | 'write'\n /** Dynamic variables which can replace values via x-variable. */\n variables?: Record<string, unknown>\n /** Whether to omit empty and optional properties. */\n omitEmptyAndOptionalProperties?: boolean\n },\n args?: Partial<{\n level: number\n parentSchema: OpenAPIV3_1.SchemaObject\n name: string\n seen: WeakSet<object>\n }>,\n): any => {\n const { level = 0, parentSchema, name, seen = new WeakSet() } = args ?? {}\n\n // Resolve any $ref references to get the actual schema\n const _schema = getResolvedRef(schema)\n if (!isDefined(_schema)) {\n return undefined\n }\n\n // Unpack from all proxies to get the raw schema object for cycle detection\n const targetValue = getRaw(unpackOverridesProxy(_schema))\n if (seen.has(targetValue)) {\n return '[Circular Reference]'\n }\n seen.add(targetValue)\n\n // Check cache first for performance - avoid recomputing the same schema\n if (resultCache.has(targetValue)) {\n seen.delete(targetValue)\n return resultCache.get(targetValue)\n }\n\n // Prevent infinite recursion in circular references\n if (level > MAX_LEVELS_DEEP) {\n seen.delete(targetValue)\n return '[Max Depth Exceeded]'\n }\n\n // Determine if we should generate realistic example data\n const makeUpRandomData = !!options?.emptyString\n\n // Early exits for schemas that should not be included (deprecated, readOnly, writeOnly, omitEmptyAndOptionalProperties)\n if (\n _schema.deprecated ||\n (options?.mode === 'write' && _schema.readOnly) ||\n (options?.mode === 'read' && _schema.writeOnly) ||\n shouldOmitProperty(_schema, parentSchema, name, options)\n ) {\n seen.delete(targetValue)\n return undefined\n }\n\n // Handle custom variables (x-variable extension)\n if ('x-variable' in _schema && _schema['x-variable']) {\n const value = options?.variables?.[_schema['x-variable']]\n if (value !== undefined) {\n // Type coercion for numeric types\n if ('type' in _schema && (_schema.type === 'number' || _schema.type === 'integer')) {\n seen.delete(targetValue)\n return cache(_schema, Number(value))\n }\n seen.delete(targetValue)\n return cache(_schema, value)\n }\n }\n\n // Priority order: examples > example > default > const > enum\n if (Array.isArray(_schema.examples) && _schema.examples.length > 0) {\n seen.delete(targetValue)\n return cache(_schema, _schema.examples[0])\n }\n if (_schema.example !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, _schema.example)\n }\n if (_schema.default !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, _schema.default)\n }\n if (_schema.const !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, _schema.const)\n }\n if (Array.isArray(_schema.enum) && _schema.enum.length > 0) {\n seen.delete(targetValue)\n return cache(_schema, _schema.enum[0])\n }\n\n // Handle object types - check for properties to identify objects\n if ('properties' in _schema || ('type' in _schema && _schema.type === 'object')) {\n const result = handleObjectSchema(_schema, options, level, seen)\n seen.delete(targetValue)\n return result\n }\n\n // Handle array types\n if (('type' in _schema && _schema.type === 'array') || 'items' in _schema) {\n const result = handleArraySchema(_schema, options, level, seen)\n seen.delete(targetValue)\n return result\n }\n\n // Handle primitive types without allocating temporary objects\n const primitive = getPrimitiveValue(_schema, makeUpRandomData, options?.emptyString)\n if (primitive !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, primitive)\n }\n\n // Handle composition schemas (oneOf, anyOf) at root level\n const discriminate = _schema.oneOf || _schema.anyOf\n if (Array.isArray(discriminate) && discriminate.length > 0) {\n // Find the first non-null type without allocating intermediate arrays\n for (const item of discriminate) {\n const resolved = getResolvedRef(item)\n if (resolved && (!('type' in resolved) || resolved.type !== 'null')) {\n seen.delete(targetValue)\n return cache(\n _schema,\n getExampleFromSchema(resolved, options, {\n level: level + 1,\n seen,\n }),\n )\n }\n }\n seen.delete(targetValue)\n return cache(_schema, null)\n }\n\n // Handle allOf at root level (non-object/array schemas)\n if (Array.isArray(_schema.allOf) && _schema.allOf.length > 0) {\n let merged: unknown = undefined\n const items = _schema.allOf\n for (const item of items) {\n const ex = getExampleFromSchema(item as OpenAPIV3_1.SchemaObject, options, {\n level: level + 1,\n parentSchema: _schema,\n seen,\n })\n if (merged === undefined) {\n merged = ex\n } else if (merged && typeof merged === 'object' && ex && typeof ex === 'object') {\n merged = mergeExamples(merged, ex)\n } else if (ex !== undefined) {\n // Prefer the latest defined primitive value\n merged = ex\n }\n }\n seen.delete(targetValue)\n return cache(_schema, merged ?? null)\n }\n\n // Handle union types (array of types)\n const unionPrimitive = getUnionPrimitiveValue(_schema, makeUpRandomData, options?.emptyString)\n if (unionPrimitive !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, unionPrimitive)\n }\n\n // Default fallback\n seen.delete(targetValue)\n return cache(_schema, null)\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AAEvB,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AAGrC,MAAM,kBAAkB;AAMxB,MAAM,iBAAiB;AAGvB,MAAM,qCAAqC;AAM3C,MAAM,oBAAmB,oBAAI,KAAK,GAAE,YAAY;AAChD,MAAM,oBAAoB,iBAAiB,MAAM,GAAG,EAAE,CAAC;AACvD,MAAM,oBAAoB,iBAAiB,MAAM,GAAG,EAAE,CAAC,EAAG,MAAM,GAAG,EAAE,CAAC;AAMtE,MAAM,uBAA+C;AAAA,EACnD,aAAa;AA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AAA,MACX;AAAA,IACF;AACA,SAAK,OAAO,WAAW;AACvB,WAAO,MAAM,SAAS,UAAU,IAAI;AAAA,EACtC;AAGA,QAAM,iBAAiB,uBAAuB,SAAS,kBAAkB,SAAS,WAAW;AAC7F,MAAI,mBAAmB,QAAW;AAChC,SAAK,OAAO,WAAW;AACvB,WAAO,MAAM,SAAS,cAAc;AAAA,EACtC;AAGA,OAAK,OAAO,WAAW;AACvB,SAAO,MAAM,SAAS,IAAI;AAC5B;",
|
|
4
|
+
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { getRaw } from '@scalar/json-magic/magic-proxy'\nimport type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackOverridesProxy } from '@scalar/workspace-store/helpers/overrides-proxy'\n\n/** Maximum recursion depth to prevent infinite loops in circular references */\nconst MAX_LEVELS_DEEP = 10\n\n/**\n * Maximum properties to include after level 3 to prevent exponential growth\n * in deeply nested object structures\n */\nconst MAX_PROPERTIES = 10\n\n/** Default name used for additional properties when no custom name is provided */\nconst DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'propertyName*'\n\n/**\n * Pre-computed date/time values to avoid expensive Date operations on every call.\n * These are calculated once at module load time for better performance.\n */\nconst currentISOString = new Date().toISOString()\nconst currentDateString = currentISOString.split('T')[0]!\nconst currentTimeString = currentISOString.split('T')[1]!.split('.')[0]!\n\n/**\n * Mapping of OpenAPI string formats to example values.\n * Used to generate realistic examples for different string formats.\n */\nconst genericExampleValues: Record<string, string> = {\n 'date-time': currentISOString,\n 'date': currentDateString,\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': currentTimeString,\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 * Generate example values for string types based on their format.\n * Special handling for binary format which returns a File object.\n */\nconst guessFromFormat = (\n schema: OpenAPIV3_1.SchemaObject,\n makeUpRandomData: boolean = false,\n fallback: string = '',\n): string | File => {\n // Handle binary format specially - return a File object\n if ('type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary') {\n return new File([''], 'filename')\n }\n\n // Return format-specific example if we have one and are making up data\n if (makeUpRandomData && 'format' in schema && schema.format) {\n return genericExampleValues[schema.format] ?? fallback\n }\n\n return fallback\n}\n\n/**\n * WeakMap cache for memoizing resolved example results.\n * Uses the resolved schema object as the key for efficient lookups.\n */\nconst resultCache = new WeakMap<object, unknown>()\n\n/** Cache required property names per parent schema for O(1) membership checks */\nconst requiredNamesCache = new WeakMap<object, ReadonlySet<string>>()\n\n/**\n * Retrieves the set of required property names from a schema.\n * Caches the result in a WeakMap for efficient lookups.\n */\nconst getRequiredNames = (parentSchema: OpenAPIV3_1.SchemaObject | undefined): ReadonlySet<string> | undefined => {\n if (!parentSchema) {\n return undefined\n }\n\n const cached = requiredNamesCache.get(parentSchema)\n if (cached) {\n return cached\n }\n\n if ('required' in parentSchema) {\n const required = parentSchema.required\n if (Array.isArray(required) && required.length > 0) {\n const set = new Set<string>(required)\n requiredNamesCache.set(parentSchema, set)\n return set\n }\n }\n\n return undefined\n}\n\n/**\n * Cache the result for a schema if it is an object type.\n * Primitive values are not cached to avoid unnecessary WeakMap operations.\n */\nconst cache = (schema: OpenAPIV3_1.SchemaObject, result: unknown) => {\n if (typeof result !== 'object' || result === null) {\n return result\n }\n resultCache.set(getRaw(unpackOverridesProxy(schema)), result)\n return result\n}\n\n/**\n * Check if a schema uses composition keywords (allOf, oneOf, anyOf).\n * These require special handling for merging or selecting schemas.\n */\nconst isComposed = (schema: OpenAPIV3_1.SchemaObject): boolean => !!(schema.allOf || schema.oneOf || schema.anyOf)\n\n/**\n * Determine if a property should be omitted based on the options.\n * Properties are omitted if they are not required and the option is enabled.\n */\nconst shouldOmitProperty = (\n schema: OpenAPIV3_1.SchemaObject,\n parentSchema: OpenAPIV3_1.SchemaObject | undefined,\n propertyName: string | undefined,\n options: { omitEmptyAndOptionalProperties?: boolean } | undefined,\n): boolean => {\n if (options?.omitEmptyAndOptionalProperties !== true) {\n return false\n }\n\n // Never omit container types (objects/arrays) or composed schemas\n const isContainer = ('type' in schema && (schema.type === 'object' || schema.type === 'array')) || isComposed(schema)\n if (isContainer) {\n return false\n }\n\n // Do not omit if explicit example-like values are present\n if (\n ('examples' in schema && Array.isArray(schema.examples) && schema.examples.length > 0) ||\n ('example' in schema && schema.example !== undefined) ||\n ('default' in schema && schema.default !== undefined) ||\n ('const' in schema && schema.const !== undefined) ||\n ('enum' in schema && Array.isArray(schema.enum) && schema.enum.length > 0)\n ) {\n return false\n }\n\n // Check if the property is required\n const name = propertyName ?? schema.title ?? ''\n const requiredNames = getRequiredNames(parentSchema)\n const isRequired = requiredNames ? requiredNames.has(name) : false\n\n return !isRequired\n}\n\n/**\n * Merge two example values with predictable semantics.\n * Arrays are concatenated, objects are merged, otherwise the new value wins.\n */\nconst mergeExamples = (baseValue: unknown, newValue: unknown): unknown => {\n if (Array.isArray(baseValue) && Array.isArray(newValue)) {\n return [...baseValue, ...newValue]\n }\n if (baseValue && typeof baseValue === 'object' && newValue && typeof newValue === 'object') {\n return { ...(baseValue as Record<string, unknown>), ...(newValue as Record<string, unknown>) }\n }\n return newValue\n}\n\n/**\n * Build an example for an object schema, including properties, patternProperties,\n * additionalProperties, and composition (allOf/oneOf/anyOf) merging.\n */\nconst handleObjectSchema = (\n schema: OpenAPIV3_1.SchemaObject,\n options: Parameters<typeof getExampleFromSchema>[1],\n level: number,\n seen: WeakSet<object>,\n): unknown => {\n const response: Record<string, unknown> = {}\n\n if ('properties' in schema && schema.properties) {\n const propertyNames = Object.keys(schema.properties)\n const limit = level > 3 ? Math.min(MAX_PROPERTIES, propertyNames.length) : propertyNames.length\n\n for (let i = 0; i < limit; i++) {\n const propertyName = propertyNames[i]!\n const propertySchema = getResolvedRef(schema.properties[propertyName])\n if (!propertySchema) {\n continue\n }\n\n const propertyXmlName = options?.xml && 'xml' in propertySchema ? propertySchema.xml?.name : undefined\n const value = getExampleFromSchema(propertySchema, options, {\n level: level + 1,\n parentSchema: schema,\n name: propertyName,\n seen,\n })\n\n if (typeof value !== 'undefined') {\n response[propertyXmlName ?? propertyName] = value\n }\n }\n\n if (level > 3 && propertyNames.length > MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n }\n }\n\n if ('patternProperties' in schema && schema.patternProperties) {\n for (const pattern of Object.keys(schema.patternProperties)) {\n const propertySchema = getResolvedRef(schema.patternProperties[pattern])\n if (!propertySchema) {\n continue\n }\n response[pattern] = getExampleFromSchema(propertySchema, options, {\n level: level + 1,\n parentSchema: schema,\n name: pattern,\n seen,\n })\n }\n }\n\n if (\n 'additionalProperties' in schema &&\n schema.additionalProperties !== undefined &&\n schema.additionalProperties !== false\n ) {\n const additional = getResolvedRef(schema.additionalProperties)\n const isAnyType =\n schema.additionalProperties === true ||\n (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length === 0)\n\n const additionalName =\n typeof additional === 'object' &&\n 'x-additionalPropertiesName' in additional &&\n typeof additional['x-additionalPropertiesName'] === 'string' &&\n additional['x-additionalPropertiesName'].trim().length > 0\n ? `${additional['x-additionalPropertiesName'].trim()}*`\n : DEFAULT_ADDITIONAL_PROPERTIES_NAME\n\n response[additionalName] = isAnyType\n ? 'anything'\n : typeof additional === 'object'\n ? getExampleFromSchema(additional, options, {\n level: level + 1,\n seen,\n })\n : 'anything'\n }\n\n // onOf\n if (schema.oneOf?.[0]) {\n Object.assign(\n response,\n getExampleFromSchema(getResolvedRef(schema.oneOf[0]), options, {\n level: level + 1,\n seen,\n }),\n )\n }\n // anyOf\n else if (schema.anyOf?.[0]) {\n Object.assign(\n response,\n getExampleFromSchema(getResolvedRef(schema.anyOf[0]), options, {\n level: level + 1,\n seen,\n }),\n )\n }\n // allOf\n else if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {\n let merged: unknown = response\n for (const item of schema.allOf) {\n const ex = getExampleFromSchema(getResolvedRef(item), options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n })\n merged = mergeExamples(merged, ex)\n }\n if (merged && typeof merged === 'object') {\n Object.assign(response, merged as Record<string, unknown>)\n }\n }\n\n if (options?.xml && 'xml' in schema && schema.xml?.name && level === 0) {\n const wrapped: Record<string, unknown> = {}\n wrapped[schema.xml.name] = response\n return cache(schema, wrapped)\n }\n\n return cache(schema, response)\n}\n\n/** Build an example for an array schema, including items, allOf, oneOf/anyOf, and XML wrapping */\nconst handleArraySchema = (\n schema: OpenAPIV3_1.SchemaObject,\n options: Parameters<typeof getExampleFromSchema>[1],\n level: number,\n seen: WeakSet<object>,\n) => {\n const items = 'items' in schema ? getResolvedRef(schema.items) : undefined\n const itemsXmlTagName = items && typeof items === 'object' && 'xml' in items ? items.xml?.name : undefined\n const wrapItems = !!(options?.xml && 'xml' in schema && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName as string]: schema.example } : schema.example)\n }\n\n if (items && typeof items === 'object') {\n if (Array.isArray(items.allOf) && items.allOf.length > 0) {\n const allOf = items.allOf.filter(isDefined)\n const first = getResolvedRef(allOf[0])\n\n if (first && typeof first === 'object' && 'type' in first && first.type === 'object') {\n const combined: OpenAPIV3_1.SchemaObject = { type: 'object', allOf }\n const merged = getExampleFromSchema(combined, options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n })\n return cache(schema, wrapItems ? [{ [itemsXmlTagName as string]: merged }] : [merged])\n }\n\n const examples = allOf\n .map((s: any) =>\n getExampleFromSchema(getResolvedRef(s), options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n }),\n )\n .filter(isDefined)\n return cache(\n schema,\n wrapItems ? (examples as unknown[]).map((e) => ({ [itemsXmlTagName as string]: e })) : examples,\n )\n }\n\n const union = items.anyOf || items.oneOf\n if (union && union.length > 0) {\n const first = union[0] as OpenAPIV3_1.SchemaObject\n const ex = getExampleFromSchema(getResolvedRef(first), options, {\n level: level + 1,\n parentSchema: schema,\n seen,\n })\n return cache(schema, wrapItems ? [{ [itemsXmlTagName as string]: ex }] : [ex])\n }\n }\n\n const isObject =\n items && typeof items === 'object' && (('type' in items && items.type === 'object') || 'properties' in items)\n const isArray =\n items && typeof items === 'object' && (('type' in items && items.type === 'array') || 'items' in items)\n\n if (items && typeof items === 'object' && (('type' in items && items.type) || isObject || isArray)) {\n const ex = getExampleFromSchema(items as OpenAPIV3_1.SchemaObject, options, {\n level: level + 1,\n seen,\n })\n return cache(schema, wrapItems ? [{ [itemsXmlTagName as string]: ex }] : [ex])\n }\n\n return cache(schema, [])\n}\n\n/** Return primitive example value for single-type schemas, or undefined if not primitive */\nconst getPrimitiveValue = (\n schema: OpenAPIV3_1.SchemaObject,\n makeUpRandomData: boolean,\n emptyString: string | undefined,\n) => {\n if ('type' in schema && schema.type && !Array.isArray(schema.type)) {\n switch (schema.type) {\n case 'string':\n return guessFromFormat(schema, makeUpRandomData, emptyString ?? '')\n case 'boolean':\n return true\n case 'integer':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'number':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'array':\n return []\n default:\n return undefined\n }\n }\n return undefined\n}\n\n/** Return primitive example value for union-type schemas (type: string[]) */\nconst getUnionPrimitiveValue = (\n schema: OpenAPIV3_1.SchemaObject,\n makeUpRandomData: boolean,\n emptyString: string | undefined,\n) => {\n if ('type' in schema && Array.isArray(schema.type)) {\n if (schema.type.includes('null')) {\n return null\n }\n\n const first = schema.type[0]\n if (first) {\n switch (first) {\n case 'string':\n return guessFromFormat(schema, makeUpRandomData, emptyString ?? '')\n case 'boolean':\n return true\n case 'integer':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'number':\n return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1\n case 'null':\n return null\n default:\n return undefined\n }\n }\n }\n return undefined\n}\n\n/**\n * Generate an example value from a given OpenAPI SchemaObject.\n *\n * This function recursively processes OpenAPI schemas to create realistic example data.\n * It handles all OpenAPI schema types including primitives, objects, arrays, and\n * composition schemas (allOf, oneOf, anyOf).\n * Uses a tonne of caching for maximum performance.\n *\n * @param schema - The OpenAPI SchemaObject to generate an example from.\n * @param options - Options to customize example generation.\n * @param level - The current recursion depth.\n * @param parentSchema - The parent schema, if any.\n * @param name - The name of the property being processed.\n * @returns An example value for the given schema.\n *\n * @deprecated Use the one from `@scalar/api-client/v2/blocks/operation-code-sample` instead.\n */\nexport const getExampleFromSchema = (\n schema: OpenAPIV3_1.SchemaObject,\n options?: {\n /** Fallback string for empty string values. */\n emptyString?: string\n /** Whether to use XML tag names as keys. */\n xml?: boolean\n /** Whether to show read-only/write-only properties. */\n mode?: 'read' | 'write'\n /** Dynamic variables which can replace values via x-variable. */\n variables?: Record<string, unknown>\n /** Whether to omit empty and optional properties. */\n omitEmptyAndOptionalProperties?: boolean\n },\n args?: Partial<{\n level: number\n parentSchema: OpenAPIV3_1.SchemaObject\n name: string\n seen: WeakSet<object>\n }>,\n): any => {\n const { level = 0, parentSchema, name, seen = new WeakSet() } = args ?? {}\n\n // Resolve any $ref references to get the actual schema\n const _schema = getResolvedRef(schema)\n if (!isDefined(_schema)) {\n return undefined\n }\n\n // Unpack from all proxies to get the raw schema object for cycle detection\n const targetValue = getRaw(unpackOverridesProxy(_schema))\n if (seen.has(targetValue)) {\n return '[Circular Reference]'\n }\n seen.add(targetValue)\n\n // Check cache first for performance - avoid recomputing the same schema\n if (resultCache.has(targetValue)) {\n seen.delete(targetValue)\n return resultCache.get(targetValue)\n }\n\n // Prevent infinite recursion in circular references\n if (level > MAX_LEVELS_DEEP) {\n seen.delete(targetValue)\n return '[Max Depth Exceeded]'\n }\n\n // Determine if we should generate realistic example data\n const makeUpRandomData = !!options?.emptyString\n\n // Early exits for schemas that should not be included (deprecated, readOnly, writeOnly, omitEmptyAndOptionalProperties)\n if (\n _schema.deprecated ||\n (options?.mode === 'write' && _schema.readOnly) ||\n (options?.mode === 'read' && _schema.writeOnly) ||\n shouldOmitProperty(_schema, parentSchema, name, options)\n ) {\n seen.delete(targetValue)\n return undefined\n }\n\n // Handle custom variables (x-variable extension)\n if ('x-variable' in _schema && _schema['x-variable']) {\n const value = options?.variables?.[_schema['x-variable']]\n if (value !== undefined) {\n // Type coercion for numeric types\n if ('type' in _schema && (_schema.type === 'number' || _schema.type === 'integer')) {\n seen.delete(targetValue)\n return cache(_schema, Number(value))\n }\n seen.delete(targetValue)\n return cache(_schema, value)\n }\n }\n\n // Priority order: examples > example > default > const > enum\n if (Array.isArray(_schema.examples) && _schema.examples.length > 0) {\n seen.delete(targetValue)\n return cache(_schema, _schema.examples[0])\n }\n if (_schema.example !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, _schema.example)\n }\n if (_schema.default !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, _schema.default)\n }\n if (_schema.const !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, _schema.const)\n }\n if (Array.isArray(_schema.enum) && _schema.enum.length > 0) {\n seen.delete(targetValue)\n return cache(_schema, _schema.enum[0])\n }\n\n // Handle object types - check for properties to identify objects\n if ('properties' in _schema || ('type' in _schema && _schema.type === 'object')) {\n const result = handleObjectSchema(_schema, options, level, seen)\n seen.delete(targetValue)\n return result\n }\n\n // Handle array types\n if (('type' in _schema && _schema.type === 'array') || 'items' in _schema) {\n const result = handleArraySchema(_schema, options, level, seen)\n seen.delete(targetValue)\n return result\n }\n\n // Handle primitive types without allocating temporary objects\n const primitive = getPrimitiveValue(_schema, makeUpRandomData, options?.emptyString)\n if (primitive !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, primitive)\n }\n\n // Handle composition schemas (oneOf, anyOf) at root level\n const discriminate = _schema.oneOf || _schema.anyOf\n if (Array.isArray(discriminate) && discriminate.length > 0) {\n // Find the first non-null type without allocating intermediate arrays\n for (const item of discriminate) {\n const resolved = getResolvedRef(item)\n if (resolved && (!('type' in resolved) || resolved.type !== 'null')) {\n seen.delete(targetValue)\n return cache(\n _schema,\n getExampleFromSchema(resolved, options, {\n level: level + 1,\n seen,\n }),\n )\n }\n }\n seen.delete(targetValue)\n return cache(_schema, null)\n }\n\n // Handle allOf at root level (non-object/array schemas)\n if (Array.isArray(_schema.allOf) && _schema.allOf.length > 0) {\n let merged: unknown = undefined\n const items = _schema.allOf\n for (const item of items) {\n const ex = getExampleFromSchema(item as OpenAPIV3_1.SchemaObject, options, {\n level: level + 1,\n parentSchema: _schema,\n seen,\n })\n if (merged === undefined) {\n merged = ex\n } else if (merged && typeof merged === 'object' && ex && typeof ex === 'object') {\n merged = mergeExamples(merged, ex)\n } else if (ex !== undefined) {\n // Prefer the latest defined primitive value\n merged = ex\n }\n }\n seen.delete(targetValue)\n return cache(_schema, merged ?? null)\n }\n\n // Handle union types (array of types)\n const unionPrimitive = getUnionPrimitiveValue(_schema, makeUpRandomData, options?.emptyString)\n if (unionPrimitive !== undefined) {\n seen.delete(targetValue)\n return cache(_schema, unionPrimitive)\n }\n\n // Default fallback\n seen.delete(targetValue)\n return cache(_schema, null)\n}\n"],
|
|
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QAAQ,MAAM,SAAS,GAAG;AAC5D,QAAI,SAAkB;AACtB,UAAM,QAAQ,QAAQ;AACtB,eAAW,QAAQ,OAAO;AACxB,YAAM,KAAK,qBAAqB,MAAkC,SAAS;AAAA,QACzE,OAAO,QAAQ;AAAA,QACf,cAAc;AAAA,QACd;AAAA,MACF,CAAC;AACD,UAAI,WAAW,QAAW;AACxB,iBAAS;AAAA,MACX,WAAW,UAAU,OAAO,WAAW,YAAY,MAAM,OAAO,OAAO,UAAU;AAC/E,iBAAS,cAAc,QAAQ,EAAE;AAAA,MACnC,WAAW,OAAO,QAAW;AAE3B,iBAAS;AAAA,MACX;AAAA,IACF;AACA,SAAK,OAAO,WAAW;AACvB,WAAO,MAAM,SAAS,UAAU,IAAI;AAAA,EACtC;AAGA,QAAM,iBAAiB,uBAAuB,SAAS,kBAAkB,SAAS,WAAW;AAC7F,MAAI,mBAAmB,QAAW;AAChC,SAAK,OAAO,WAAW;AACvB,WAAO,MAAM,SAAS,cAAc;AAAA,EACtC;AAGA,OAAK,OAAO,WAAW;AACvB,SAAO,MAAM,SAAS,IAAI;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -36,7 +36,7 @@ const dereferenceDocument = async (document, { shouldLoad = true } = {}) => {
|
|
|
36
36
|
loadErrors = response.errors ?? [];
|
|
37
37
|
}
|
|
38
38
|
const { specification } = upgrade(filesystem);
|
|
39
|
-
const { schema, errors: derefErrors = [] } =
|
|
39
|
+
const { schema, errors: derefErrors = [] } = dereference(specification);
|
|
40
40
|
return {
|
|
41
41
|
schema,
|
|
42
42
|
errors: [...loadErrors, ...derefErrors]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/transforms/import-spec.ts"],
|
|
4
|
-
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { isHttpMethod } from '@scalar/helpers/http/is-http-method'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type LoadResult, dereference, load, upgrade } from '@scalar/openapi-parser'\nimport type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { ApiReferenceConfiguration } from '@scalar/types/api-reference'\nimport type { SecuritySchemeOauth2 } from '@scalar/types/entities'\nimport {\n type Oauth2FlowPayload,\n type SecurityScheme,\n type SecuritySchemePayload,\n securitySchemeSchema,\n} from '@scalar/types/entities'\nimport type { UnknownObject } from '@scalar/types/utils'\nimport type { Entries } from 'type-fest'\n\nimport type { SelectedSecuritySchemeUids } from '@/entities/shared/utility'\nimport { type Collection, type CollectionPayload, collectionSchema } from '@/entities/spec/collection'\nimport type { RequestParameterPayload } from '@/entities/spec/parameters'\nimport { type RequestExample, createExampleFromRequest } from '@/entities/spec/request-examples'\nimport { type Request, type RequestPayload, requestSchema } from '@/entities/spec/requests'\nimport { type Server, serverSchema } from '@/entities/spec/server'\nimport { type Tag, tagSchema } from '@/entities/spec/spec-objects'\nimport { schemaModel } from '@/helpers/schema-model'\nimport { getServersFromDocument } from '@/helpers/servers'\n\nconst dereferenceDocument = async (\n document: string | UnknownObject,\n { shouldLoad = true }: { shouldLoad?: boolean } = {},\n) => {\n if (document === null || (typeof document === 'string' && document.trim() === '')) {\n console.warn('[@scalar/oas-utils] Empty OpenAPI document provided.')\n\n return {\n schema: {} as OpenAPIV3_1.Document,\n errors: [],\n }\n }\n\n let filesystem: LoadResult['filesystem'] | string | UnknownObject = document\n let loadErrors: LoadResult['errors'] = []\n\n if (shouldLoad) {\n // TODO: Plugins for URLs and files with the proxy are missing here.\n // @see packages/api-reference/src/helpers/parse.ts\n const response = await load(document).catch((e) => ({\n errors: [\n {\n code: e.code,\n message: e.message,\n },\n ],\n filesystem: [],\n }))\n filesystem = response.filesystem\n loadErrors = response.errors ?? []\n }\n\n const { specification } = upgrade(filesystem)\n const { schema, errors: derefErrors = [] } = await dereference(specification)\n\n return {\n schema,\n errors: [...loadErrors, ...derefErrors],\n }\n}\n\n/** Takes a string or object and parses it into an openapi spec compliant schema */\nexport const parseSchema = async (\n originalDocument: string | UnknownObject | undefined,\n {\n shouldLoad = true,\n /** If a dereferenced document is provided, we will skip the dereferencing step. */\n dereferencedDocument = undefined,\n }: { shouldLoad?: boolean; dereferencedDocument?: OpenAPIV3_1.Document } = {},\n) => {\n // Skip, if a dereferenced document is provided\n const { schema, errors } = dereferencedDocument\n ? {\n schema: dereferencedDocument,\n errors: [],\n }\n : // Otherwise, dereference the original document\n await dereferenceDocument(originalDocument ?? '', {\n shouldLoad,\n })\n\n if (!schema) {\n console.warn('[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined')\n }\n\n return {\n /**\n * Temporary fix for the parser returning an empty array\n * TODO: remove this once the parser is fixed\n */\n schema: (Array.isArray(schema) ? {} : schema) as OpenAPIV3_1.Document,\n errors,\n }\n}\n\n/** Converts selected security requirements to uids */\nexport const getSelectedSecuritySchemeUids = (\n securityRequirements: (string | string[])[],\n preferredSecurityNames: (string | string[])[] = [],\n securitySchemeMap: Record<string, SecurityScheme['uid']>,\n): SelectedSecuritySchemeUids => {\n // Set the first security requirement if no preferred security schemes are set\n const names =\n securityRequirements[0] && !preferredSecurityNames.length ? [securityRequirements[0]] : preferredSecurityNames\n\n // Map names to uids\n const uids = names\n .map((name) =>\n Array.isArray(name) ? name.map((k) => securitySchemeMap[k]).filter(isDefined) : securitySchemeMap[name],\n )\n .filter(isDefined)\n\n return uids\n}\n\n/** Create a \"uid\" from a slug */\nexport const getSlugUid = (slug: string) => `slug-uid-${slug}` as Collection['uid']\n\nexport type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> &\n Pick<ApiReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers' | 'slug'> & {\n /** The dereferenced document */\n dereferencedDocument?: OpenAPIV3_1.Document\n /** Sets the preferred security scheme on the collection instead of the requests */\n useCollectionSecurity?: boolean\n /** Call the load step from the parser */\n shouldLoad?: boolean\n }\n\n/**\n * Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)\n *\n * The imported entities maintain a close mapping to the original OpenAPI specification to enable:\n * - Bi-directional translation between spec and workspace entities\n * - Preservation of specification details and structure\n * - Accurate representation of relationships between components\n *\n * Relationships between entities are maintained through unique identifiers (UIDs) which allow:\n * - Flexible organization at different levels (workspace, collection, request)\n * - Proper linking between related components\n * - Easy lookup and reference of dependent entities\n */\nexport async function importSpecToWorkspace(\n content: string | UnknownObject | undefined,\n {\n /** If a dereferenced document is provided, we will skip the dereferencing step. */\n dereferencedDocument,\n authentication,\n baseServerURL,\n documentUrl,\n servers: configuredServers,\n useCollectionSecurity = false,\n slug,\n shouldLoad,\n watchMode = false,\n }: ImportSpecToWorkspaceArgs = {},\n): Promise<\n | {\n error: false\n collection: Collection\n requests: Request[]\n schema: OpenAPIV3_1.Document\n examples: RequestExample[]\n servers: Server[]\n tags: Tag[]\n securitySchemes: SecurityScheme[]\n }\n | { error: true; importWarnings: string[]; collection: undefined }\n> {\n const { schema, errors } = await parseSchema(content, { shouldLoad, dereferencedDocument })\n const importWarnings: string[] = [...errors.map((e) => e.message)]\n\n if (!schema) {\n return { importWarnings, error: true, collection: undefined }\n }\n // ---------------------------------------------------------------------------\n // Some entities will be broken out as individual lists for modification in the workspace\n const start = performance.now()\n const requests: Request[] = []\n\n // Add the base server url to collection servers\n const collectionServers: Server[] = getServersFromDocument(configuredServers || schema.servers, {\n baseServerURL,\n documentUrl,\n })\n\n // Store operation servers\n const operationServers: Server[] = []\n\n /**\n * List of all tag strings. For non compliant specs we may need to\n * add top level tag objects for missing tag objects\n */\n const tagNames: Set<string> = new Set()\n\n // ---------------------------------------------------------------------------\n // SECURITY HANDLING\n\n const security = schema.components?.securitySchemes ?? schema?.securityDefinitions ?? {}\n\n // @ts-expect-error - Toss out a deprecated warning for the old authentication state\n if (authentication?.oAuth2 || authentication?.apiKey || authentication?.http) {\n console.warn(\n `DEPRECATION WARNING: It looks like you're using legacy authentication config. Please migrate to use the updated config. See https://github.com/scalar/scalar/blob/main/documentation/configuration.md#authentication-partial This will be removed in a future version.`,\n )\n }\n\n const securitySchemes = (Object.entries(security) as Entries<Record<string, OpenAPIV3_1.SecuritySchemeObject>>)\n .map?.(([nameKey, _scheme]) => {\n // Apply any transforms we need before parsing\n const payload = {\n ..._scheme,\n // Add the new auth config overrides, we keep the old code below for backwards compatibility\n ...(authentication?.securitySchemes?.[nameKey] ?? {}),\n nameKey,\n } as SecuritySchemePayload\n\n // For oauth2 we need to add the type to the flows + prefill from authentication\n if (payload.type === 'oauth2' && payload.flows) {\n const flowKeys = Object.keys(payload.flows) as Array<keyof typeof payload.flows>\n\n flowKeys.forEach((key) => {\n if (!payload.flows?.[key] || _scheme.type !== 'oauth2') {\n return\n }\n const authFlow = (authentication?.securitySchemes?.[nameKey] as SecuritySchemeOauth2)?.flows?.[key] ?? {}\n\n // This part handles setting of flows via the new auth config, the rest can be removed in a future version\n payload.flows[key] = {\n ...(_scheme.flows?.[key] ?? {}),\n ...authFlow,\n } satisfies Oauth2FlowPayload\n\n const flow = payload.flows[key] as Oauth2FlowPayload\n\n // Set the type\n flow.type = key\n\n // Prefill values from authorization config - old deprecated config\n // @ts-expect-error - deprecated\n if (authentication?.oAuth2) {\n // @ts-expect-error - deprecated\n if (authentication.oAuth2.accessToken) {\n // @ts-expect-error - deprecated\n flow.token = authentication.oAuth2.accessToken\n }\n\n // @ts-expect-error - deprecated\n if (authentication.oAuth2.clientId) {\n // @ts-expect-error - deprecated\n flow['x-scalar-client-id'] = authentication.oAuth2.clientId\n }\n\n // @ts-expect-error - deprecated\n if (authentication.oAuth2.scopes) {\n // @ts-expect-error - deprecated\n flow.selectedScopes = authentication.oAuth2.scopes\n }\n\n if (flow.type === 'password') {\n // @ts-expect-error - deprecated\n flow.username = authentication.oAuth2.username\n // @ts-expect-error - deprecated\n flow.password = authentication.oAuth2.password\n }\n }\n\n // Convert scopes to an object\n if (Array.isArray(flow.scopes)) {\n flow.scopes = flow.scopes.reduce((prev, s) => ({ ...prev, [s]: '' }), {})\n }\n\n // Handle x-defaultClientId\n if (flow['x-defaultClientId']) {\n flow['x-scalar-client-id'] = flow['x-defaultClientId']\n }\n })\n }\n // Otherwise we just prefill - old deprecated config\n else if (authentication) {\n // ApiKey\n // @ts-expect-error - deprecated\n if (payload.type === 'apiKey' && authentication.apiKey?.token) {\n // @ts-expect-error - deprecated\n payload.value = authentication.apiKey.token\n }\n // HTTP\n else if (payload.type === 'http') {\n // @ts-expect-error - deprecated\n if (payload.scheme === 'basic' && authentication.http?.basic) {\n // @ts-expect-error - deprecated\n payload.username = authentication.http.basic.username ?? ''\n // @ts-expect-error - deprecated\n payload.password = authentication.http.basic.password ?? ''\n }\n // Bearer\n // @ts-expect-error - deprecated\n else if (payload.scheme === 'bearer' && authentication.http?.bearer?.token) {\n // @ts-expect-error - deprecated\n payload.token = authentication.http.bearer.token ?? ''\n }\n }\n }\n\n const scheme = schemaModel(payload, securitySchemeSchema, false)\n if (!scheme) {\n importWarnings.push(`Security scheme ${nameKey} is invalid.`)\n }\n\n return scheme\n })\n .filter((v) => !!v)\n\n // Map of security scheme names to UIDs\n const securitySchemeMap: Record<string, SecurityScheme['uid']> = {}\n securitySchemes.forEach((s) => {\n securitySchemeMap[s.nameKey] = s.uid\n })\n\n // ---------------------------------------------------------------------------\n // REQUEST HANDLING\n\n keysOf(schema.paths ?? {}).forEach((pathString) => {\n const path = schema?.paths?.[pathString]\n\n if (!path) {\n return\n }\n // Path level servers must be saved\n const pathServers = serverSchema.array().parse(path.servers ?? [])\n for (const server of pathServers) {\n collectionServers.push(server)\n }\n\n // Creates a sorted array of methods based on the path object.\n const methods = Object.keys(path).filter(isHttpMethod)\n\n methods.forEach((method) => {\n const operation = path[method]\n if (!operation) {\n return\n }\n\n const operationLevelServers = serverSchema.array().parse(operation.servers ?? [])\n\n for (const server of operationLevelServers) {\n operationServers.push(server)\n }\n\n // We will save a list of all tags to ensure they exists at the top level\n // TODO: make sure we add any loose requests with no tags to the collection children\n operation.tags?.forEach((t: string) => tagNames.add(t))\n\n // Remove security here and add it correctly below\n const { security: operationSecurity, ...operationWithoutSecurity } = operation\n\n const securityRequirements: (string | string[])[] = (operationSecurity ?? schema.security ?? [])\n .map((s: OpenAPIV3_1.SecurityRequirementObject) => {\n const keys = Object.keys(s)\n return keys.length > 1 ? keys : keys[0]\n })\n .filter(isDefined)\n\n // Filter the preferred security schemes to only include the ones that are in the security requirements\n const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat().filter((name) => {\n // Match up complex security requirements, array to array\n if (Array.isArray(name)) {\n // We match every element in the array\n return securityRequirements.some(\n (r) => Array.isArray(r) && r.length === name.length && r.every((v, i) => v === name[i]),\n )\n }\n return securityRequirements.includes(name)\n })\n\n // Set the initially selected security scheme\n const selectedSecuritySchemeUids =\n securityRequirements.length && !useCollectionSecurity\n ? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)\n : []\n\n const requestPayload: RequestPayload = {\n ...operationWithoutSecurity,\n method,\n path: pathString,\n security: operationSecurity,\n selectedServerUid: operationLevelServers?.[0]?.uid,\n selectedSecuritySchemeUids,\n // Merge path and operation level parameters\n parameters: [...(path?.parameters ?? []), ...(operation.parameters ?? [])] as RequestParameterPayload[],\n servers: [...pathServers, ...operationLevelServers].map((s) => s.uid),\n }\n\n // Remove any examples from the request payload as they conflict with our examples property and are not valid\n if (requestPayload.examples) {\n console.warn('[@scalar/api-client] operation.examples is not a valid openapi property')\n delete requestPayload.examples\n }\n\n // Save parse the request\n const request = schemaModel(requestPayload, requestSchema, false)\n\n if (!request) {\n importWarnings.push(`${method} Request at ${path} is invalid.`)\n } else {\n requests.push(request)\n }\n })\n })\n\n // ---------------------------------------------------------------------------\n // TAG HANDLING\n\n // TODO: We may need to handle de-duping tags\n const tags = schemaModel(schema?.tags ?? [], tagSchema.array(), false) ?? []\n\n // Delete any tag names that already have a definition\n tags.forEach((t) => tagNames.delete(t.name))\n\n // Add an entry for any tags that are used but do not have a definition\n tagNames.forEach((name) => name && tags.push(tagSchema.parse({ name })))\n\n // Tag name to UID map\n const tagMap: Record<string, Tag> = {}\n tags.forEach((t) => {\n tagMap[t.name] = t\n })\n\n // Add all tags by default. We will remove nested ones\n const collectionChildren = new Set<Collection['children'][number]>(tags.map((t) => t.uid))\n\n // Nested folders go before any requests\n tags.forEach((t) => {\n t['x-scalar-children']?.forEach((c) => {\n // Add the uid to the appropriate parent.children\n const nestedUid = tagMap[c.tagName]?.uid\n\n if (nestedUid) {\n t.children.push(nestedUid)\n\n // Remove the nested uid from the root folder\n collectionChildren.delete(nestedUid)\n }\n })\n })\n\n // Add the request UIDs to the tag children (or collection root)\n requests.forEach((r) => {\n if (r.tags?.length) {\n r.tags.forEach((t) => {\n tagMap[t]?.children.push(r.uid)\n })\n } else {\n collectionChildren.add(r.uid)\n }\n })\n\n // ---------------------------------------------------------------------------\n\n const examples: RequestExample[] = []\n\n // Ensure each request has at least 1 example\n requests.forEach((request) => {\n // TODO: Need to handle parsing examples\n // if (request['x-scalar-examples']) return\n\n // Create the initial example\n const example = createExampleFromRequest(request, 'Default Example')\n\n examples.push(example)\n request.examples.push(example.uid)\n })\n\n // ---------------------------------------------------------------------------\n // Generate Collection\n\n // Grab the security requirements for this operation\n const securityRequirements: SelectedSecuritySchemeUids = (schema.security ?? [])\n .map((s: OpenAPIV3_1.SecurityRequirementObject) => {\n const keys = Object.keys(s)\n return keys.length > 1 ? keys : keys[0]\n })\n .filter(isDefined)\n\n // Here we do not filter these as we let the preferredSecurityScheme override the requirements\n const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat()\n\n // Set the initially selected security scheme\n const selectedSecuritySchemeUids =\n (securityRequirements.length || preferredSecurityNames?.length) && useCollectionSecurity\n ? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)\n : []\n\n // Set the uid as a prefixed slug if we have one\n const slugObj = slug?.length ? { uid: getSlugUid(slug) } : {}\n\n const collection = collectionSchema.parse({\n ...slugObj,\n ...schema,\n watchMode,\n documentUrl,\n useCollectionSecurity,\n requests: requests.map((r) => r.uid),\n servers: collectionServers.map((s) => s.uid),\n tags: tags.map((t) => t.uid),\n children: [...collectionChildren],\n security: schema.security ?? [{}],\n selectedServerUid: collectionServers?.[0]?.uid,\n selectedSecuritySchemeUids,\n components: {\n ...schema.components,\n },\n securitySchemes: securitySchemes.map((s) => s.uid),\n })\n\n const end = performance.now()\n console.log(`workspace: ${Math.round(end - start)} ms`)\n\n /**\n * Servers and requests will be saved in top level maps and indexed via UID to\n * maintain specification relationships\n */\n return {\n error: false,\n servers: [...collectionServers, ...operationServers],\n schema,\n requests,\n examples,\n collection,\n tags,\n securitySchemes,\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAA0B,aAAa,MAAM,eAAe;AAI5D;AAAA,EAIE;AAAA,OACK;AAKP,SAAkD,wBAAwB;AAE1E,SAA8B,gCAAgC;AAC9D,SAA4C,qBAAqB;AACjE,SAAsB,oBAAoB;AAC1C,SAAmB,iBAAiB;AACpC,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AAEvC,MAAM,sBAAsB,OAC1B,UACA,EAAE,aAAa,KAAK,IAA8B,CAAC,MAChD;AACH,MAAI,aAAa,QAAS,OAAO,aAAa,YAAY,SAAS,KAAK,MAAM,IAAK;AACjF,YAAQ,KAAK,sDAAsD;AAEnE,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,QAAQ,CAAC;AAAA,IACX;AAAA,EACF;AAEA,MAAI,aAAgE;AACpE,MAAI,aAAmC,CAAC;AAExC,MAAI,YAAY;AAGd,UAAM,WAAW,MAAM,KAAK,QAAQ,EAAE,MAAM,CAAC,OAAO;AAAA,MAClD,QAAQ;AAAA,QACN;AAAA,UACE,MAAM,EAAE;AAAA,UACR,SAAS,EAAE;AAAA,QACb;AAAA,MACF;AAAA,MACA,YAAY,CAAC;AAAA,IACf,EAAE;AACF,iBAAa,SAAS;AACtB,iBAAa,SAAS,UAAU,CAAC;AAAA,EACnC;AAEA,QAAM,EAAE,cAAc,IAAI,QAAQ,UAAU;AAC5C,QAAM,EAAE,QAAQ,QAAQ,cAAc,CAAC,EAAE,IAAI,
|
|
4
|
+
"sourcesContent": ["import { isDefined } from '@scalar/helpers/array/is-defined'\nimport { isHttpMethod } from '@scalar/helpers/http/is-http-method'\nimport { keysOf } from '@scalar/object-utils/arrays'\nimport { type LoadResult, dereference, load, upgrade } from '@scalar/openapi-parser'\nimport type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { ApiReferenceConfiguration } from '@scalar/types/api-reference'\nimport type { SecuritySchemeOauth2 } from '@scalar/types/entities'\nimport {\n type Oauth2FlowPayload,\n type SecurityScheme,\n type SecuritySchemePayload,\n securitySchemeSchema,\n} from '@scalar/types/entities'\nimport type { UnknownObject } from '@scalar/types/utils'\nimport type { Entries } from 'type-fest'\n\nimport type { SelectedSecuritySchemeUids } from '@/entities/shared/utility'\nimport { type Collection, type CollectionPayload, collectionSchema } from '@/entities/spec/collection'\nimport type { RequestParameterPayload } from '@/entities/spec/parameters'\nimport { type RequestExample, createExampleFromRequest } from '@/entities/spec/request-examples'\nimport { type Request, type RequestPayload, requestSchema } from '@/entities/spec/requests'\nimport { type Server, serverSchema } from '@/entities/spec/server'\nimport { type Tag, tagSchema } from '@/entities/spec/spec-objects'\nimport { schemaModel } from '@/helpers/schema-model'\nimport { getServersFromDocument } from '@/helpers/servers'\n\nconst dereferenceDocument = async (\n document: string | UnknownObject,\n { shouldLoad = true }: { shouldLoad?: boolean } = {},\n) => {\n if (document === null || (typeof document === 'string' && document.trim() === '')) {\n console.warn('[@scalar/oas-utils] Empty OpenAPI document provided.')\n\n return {\n schema: {} as OpenAPIV3_1.Document,\n errors: [],\n }\n }\n\n let filesystem: LoadResult['filesystem'] | string | UnknownObject = document\n let loadErrors: LoadResult['errors'] = []\n\n if (shouldLoad) {\n // TODO: Plugins for URLs and files with the proxy are missing here.\n // @see packages/api-reference/src/helpers/parse.ts\n const response = await load(document).catch((e) => ({\n errors: [\n {\n code: e.code,\n message: e.message,\n },\n ],\n filesystem: [],\n }))\n filesystem = response.filesystem\n loadErrors = response.errors ?? []\n }\n\n const { specification } = upgrade(filesystem)\n const { schema, errors: derefErrors = [] } = dereference(specification)\n\n return {\n schema,\n errors: [...loadErrors, ...derefErrors],\n }\n}\n\n/** Takes a string or object and parses it into an openapi spec compliant schema */\nexport const parseSchema = async (\n originalDocument: string | UnknownObject | undefined,\n {\n shouldLoad = true,\n /** If a dereferenced document is provided, we will skip the dereferencing step. */\n dereferencedDocument = undefined,\n }: { shouldLoad?: boolean; dereferencedDocument?: OpenAPIV3_1.Document } = {},\n) => {\n // Skip, if a dereferenced document is provided\n const { schema, errors } = dereferencedDocument\n ? {\n schema: dereferencedDocument,\n errors: [],\n }\n : // Otherwise, dereference the original document\n await dereferenceDocument(originalDocument ?? '', {\n shouldLoad,\n })\n\n if (!schema) {\n console.warn('[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined')\n }\n\n return {\n /**\n * Temporary fix for the parser returning an empty array\n * TODO: remove this once the parser is fixed\n */\n schema: (Array.isArray(schema) ? {} : schema) as OpenAPIV3_1.Document,\n errors,\n }\n}\n\n/** Converts selected security requirements to uids */\nexport const getSelectedSecuritySchemeUids = (\n securityRequirements: (string | string[])[],\n preferredSecurityNames: (string | string[])[] = [],\n securitySchemeMap: Record<string, SecurityScheme['uid']>,\n): SelectedSecuritySchemeUids => {\n // Set the first security requirement if no preferred security schemes are set\n const names =\n securityRequirements[0] && !preferredSecurityNames.length ? [securityRequirements[0]] : preferredSecurityNames\n\n // Map names to uids\n const uids = names\n .map((name) =>\n Array.isArray(name) ? name.map((k) => securitySchemeMap[k]).filter(isDefined) : securitySchemeMap[name],\n )\n .filter(isDefined)\n\n return uids\n}\n\n/** Create a \"uid\" from a slug */\nexport const getSlugUid = (slug: string) => `slug-uid-${slug}` as Collection['uid']\n\nexport type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> &\n Pick<ApiReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers' | 'slug'> & {\n /** The dereferenced document */\n dereferencedDocument?: OpenAPIV3_1.Document\n /** Sets the preferred security scheme on the collection instead of the requests */\n useCollectionSecurity?: boolean\n /** Call the load step from the parser */\n shouldLoad?: boolean\n }\n\n/**\n * Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)\n *\n * The imported entities maintain a close mapping to the original OpenAPI specification to enable:\n * - Bi-directional translation between spec and workspace entities\n * - Preservation of specification details and structure\n * - Accurate representation of relationships between components\n *\n * Relationships between entities are maintained through unique identifiers (UIDs) which allow:\n * - Flexible organization at different levels (workspace, collection, request)\n * - Proper linking between related components\n * - Easy lookup and reference of dependent entities\n */\nexport async function importSpecToWorkspace(\n content: string | UnknownObject | undefined,\n {\n /** If a dereferenced document is provided, we will skip the dereferencing step. */\n dereferencedDocument,\n authentication,\n baseServerURL,\n documentUrl,\n servers: configuredServers,\n useCollectionSecurity = false,\n slug,\n shouldLoad,\n watchMode = false,\n }: ImportSpecToWorkspaceArgs = {},\n): Promise<\n | {\n error: false\n collection: Collection\n requests: Request[]\n schema: OpenAPIV3_1.Document\n examples: RequestExample[]\n servers: Server[]\n tags: Tag[]\n securitySchemes: SecurityScheme[]\n }\n | { error: true; importWarnings: string[]; collection: undefined }\n> {\n const { schema, errors } = await parseSchema(content, { shouldLoad, dereferencedDocument })\n const importWarnings: string[] = [...errors.map((e) => e.message)]\n\n if (!schema) {\n return { importWarnings, error: true, collection: undefined }\n }\n // ---------------------------------------------------------------------------\n // Some entities will be broken out as individual lists for modification in the workspace\n const start = performance.now()\n const requests: Request[] = []\n\n // Add the base server url to collection servers\n const collectionServers: Server[] = getServersFromDocument(configuredServers || schema.servers, {\n baseServerURL,\n documentUrl,\n })\n\n // Store operation servers\n const operationServers: Server[] = []\n\n /**\n * List of all tag strings. For non compliant specs we may need to\n * add top level tag objects for missing tag objects\n */\n const tagNames: Set<string> = new Set()\n\n // ---------------------------------------------------------------------------\n // SECURITY HANDLING\n\n const security = schema.components?.securitySchemes ?? schema?.securityDefinitions ?? {}\n\n // @ts-expect-error - Toss out a deprecated warning for the old authentication state\n if (authentication?.oAuth2 || authentication?.apiKey || authentication?.http) {\n console.warn(\n `DEPRECATION WARNING: It looks like you're using legacy authentication config. Please migrate to use the updated config. See https://github.com/scalar/scalar/blob/main/documentation/configuration.md#authentication-partial This will be removed in a future version.`,\n )\n }\n\n const securitySchemes = (Object.entries(security) as Entries<Record<string, OpenAPIV3_1.SecuritySchemeObject>>)\n .map?.(([nameKey, _scheme]) => {\n // Apply any transforms we need before parsing\n const payload = {\n ..._scheme,\n // Add the new auth config overrides, we keep the old code below for backwards compatibility\n ...(authentication?.securitySchemes?.[nameKey] ?? {}),\n nameKey,\n } as SecuritySchemePayload\n\n // For oauth2 we need to add the type to the flows + prefill from authentication\n if (payload.type === 'oauth2' && payload.flows) {\n const flowKeys = Object.keys(payload.flows) as Array<keyof typeof payload.flows>\n\n flowKeys.forEach((key) => {\n if (!payload.flows?.[key] || _scheme.type !== 'oauth2') {\n return\n }\n const authFlow = (authentication?.securitySchemes?.[nameKey] as SecuritySchemeOauth2)?.flows?.[key] ?? {}\n\n // This part handles setting of flows via the new auth config, the rest can be removed in a future version\n payload.flows[key] = {\n ...(_scheme.flows?.[key] ?? {}),\n ...authFlow,\n } satisfies Oauth2FlowPayload\n\n const flow = payload.flows[key] as Oauth2FlowPayload\n\n // Set the type\n flow.type = key\n\n // Prefill values from authorization config - old deprecated config\n // @ts-expect-error - deprecated\n if (authentication?.oAuth2) {\n // @ts-expect-error - deprecated\n if (authentication.oAuth2.accessToken) {\n // @ts-expect-error - deprecated\n flow.token = authentication.oAuth2.accessToken\n }\n\n // @ts-expect-error - deprecated\n if (authentication.oAuth2.clientId) {\n // @ts-expect-error - deprecated\n flow['x-scalar-client-id'] = authentication.oAuth2.clientId\n }\n\n // @ts-expect-error - deprecated\n if (authentication.oAuth2.scopes) {\n // @ts-expect-error - deprecated\n flow.selectedScopes = authentication.oAuth2.scopes\n }\n\n if (flow.type === 'password') {\n // @ts-expect-error - deprecated\n flow.username = authentication.oAuth2.username\n // @ts-expect-error - deprecated\n flow.password = authentication.oAuth2.password\n }\n }\n\n // Convert scopes to an object\n if (Array.isArray(flow.scopes)) {\n flow.scopes = flow.scopes.reduce((prev, s) => ({ ...prev, [s]: '' }), {})\n }\n\n // Handle x-defaultClientId\n if (flow['x-defaultClientId']) {\n flow['x-scalar-client-id'] = flow['x-defaultClientId']\n }\n })\n }\n // Otherwise we just prefill - old deprecated config\n else if (authentication) {\n // ApiKey\n // @ts-expect-error - deprecated\n if (payload.type === 'apiKey' && authentication.apiKey?.token) {\n // @ts-expect-error - deprecated\n payload.value = authentication.apiKey.token\n }\n // HTTP\n else if (payload.type === 'http') {\n // @ts-expect-error - deprecated\n if (payload.scheme === 'basic' && authentication.http?.basic) {\n // @ts-expect-error - deprecated\n payload.username = authentication.http.basic.username ?? ''\n // @ts-expect-error - deprecated\n payload.password = authentication.http.basic.password ?? ''\n }\n // Bearer\n // @ts-expect-error - deprecated\n else if (payload.scheme === 'bearer' && authentication.http?.bearer?.token) {\n // @ts-expect-error - deprecated\n payload.token = authentication.http.bearer.token ?? ''\n }\n }\n }\n\n const scheme = schemaModel(payload, securitySchemeSchema, false)\n if (!scheme) {\n importWarnings.push(`Security scheme ${nameKey} is invalid.`)\n }\n\n return scheme\n })\n .filter((v) => !!v)\n\n // Map of security scheme names to UIDs\n const securitySchemeMap: Record<string, SecurityScheme['uid']> = {}\n securitySchemes.forEach((s) => {\n securitySchemeMap[s.nameKey] = s.uid\n })\n\n // ---------------------------------------------------------------------------\n // REQUEST HANDLING\n\n keysOf(schema.paths ?? {}).forEach((pathString) => {\n const path = schema?.paths?.[pathString]\n\n if (!path) {\n return\n }\n // Path level servers must be saved\n const pathServers = serverSchema.array().parse(path.servers ?? [])\n for (const server of pathServers) {\n collectionServers.push(server)\n }\n\n // Creates a sorted array of methods based on the path object.\n const methods = Object.keys(path).filter(isHttpMethod)\n\n methods.forEach((method) => {\n const operation = path[method]\n if (!operation) {\n return\n }\n\n const operationLevelServers = serverSchema.array().parse(operation.servers ?? [])\n\n for (const server of operationLevelServers) {\n operationServers.push(server)\n }\n\n // We will save a list of all tags to ensure they exists at the top level\n // TODO: make sure we add any loose requests with no tags to the collection children\n operation.tags?.forEach((t: string) => tagNames.add(t))\n\n // Remove security here and add it correctly below\n const { security: operationSecurity, ...operationWithoutSecurity } = operation\n\n const securityRequirements: (string | string[])[] = (operationSecurity ?? schema.security ?? [])\n .map((s: OpenAPIV3_1.SecurityRequirementObject) => {\n const keys = Object.keys(s)\n return keys.length > 1 ? keys : keys[0]\n })\n .filter(isDefined)\n\n // Filter the preferred security schemes to only include the ones that are in the security requirements\n const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat().filter((name) => {\n // Match up complex security requirements, array to array\n if (Array.isArray(name)) {\n // We match every element in the array\n return securityRequirements.some(\n (r) => Array.isArray(r) && r.length === name.length && r.every((v, i) => v === name[i]),\n )\n }\n return securityRequirements.includes(name)\n })\n\n // Set the initially selected security scheme\n const selectedSecuritySchemeUids =\n securityRequirements.length && !useCollectionSecurity\n ? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)\n : []\n\n const requestPayload: RequestPayload = {\n ...operationWithoutSecurity,\n method,\n path: pathString,\n security: operationSecurity,\n selectedServerUid: operationLevelServers?.[0]?.uid,\n selectedSecuritySchemeUids,\n // Merge path and operation level parameters\n parameters: [...(path?.parameters ?? []), ...(operation.parameters ?? [])] as RequestParameterPayload[],\n servers: [...pathServers, ...operationLevelServers].map((s) => s.uid),\n }\n\n // Remove any examples from the request payload as they conflict with our examples property and are not valid\n if (requestPayload.examples) {\n console.warn('[@scalar/api-client] operation.examples is not a valid openapi property')\n delete requestPayload.examples\n }\n\n // Save parse the request\n const request = schemaModel(requestPayload, requestSchema, false)\n\n if (!request) {\n importWarnings.push(`${method} Request at ${path} is invalid.`)\n } else {\n requests.push(request)\n }\n })\n })\n\n // ---------------------------------------------------------------------------\n // TAG HANDLING\n\n // TODO: We may need to handle de-duping tags\n const tags = schemaModel(schema?.tags ?? [], tagSchema.array(), false) ?? []\n\n // Delete any tag names that already have a definition\n tags.forEach((t) => tagNames.delete(t.name))\n\n // Add an entry for any tags that are used but do not have a definition\n tagNames.forEach((name) => name && tags.push(tagSchema.parse({ name })))\n\n // Tag name to UID map\n const tagMap: Record<string, Tag> = {}\n tags.forEach((t) => {\n tagMap[t.name] = t\n })\n\n // Add all tags by default. We will remove nested ones\n const collectionChildren = new Set<Collection['children'][number]>(tags.map((t) => t.uid))\n\n // Nested folders go before any requests\n tags.forEach((t) => {\n t['x-scalar-children']?.forEach((c) => {\n // Add the uid to the appropriate parent.children\n const nestedUid = tagMap[c.tagName]?.uid\n\n if (nestedUid) {\n t.children.push(nestedUid)\n\n // Remove the nested uid from the root folder\n collectionChildren.delete(nestedUid)\n }\n })\n })\n\n // Add the request UIDs to the tag children (or collection root)\n requests.forEach((r) => {\n if (r.tags?.length) {\n r.tags.forEach((t) => {\n tagMap[t]?.children.push(r.uid)\n })\n } else {\n collectionChildren.add(r.uid)\n }\n })\n\n // ---------------------------------------------------------------------------\n\n const examples: RequestExample[] = []\n\n // Ensure each request has at least 1 example\n requests.forEach((request) => {\n // TODO: Need to handle parsing examples\n // if (request['x-scalar-examples']) return\n\n // Create the initial example\n const example = createExampleFromRequest(request, 'Default Example')\n\n examples.push(example)\n request.examples.push(example.uid)\n })\n\n // ---------------------------------------------------------------------------\n // Generate Collection\n\n // Grab the security requirements for this operation\n const securityRequirements: SelectedSecuritySchemeUids = (schema.security ?? [])\n .map((s: OpenAPIV3_1.SecurityRequirementObject) => {\n const keys = Object.keys(s)\n return keys.length > 1 ? keys : keys[0]\n })\n .filter(isDefined)\n\n // Here we do not filter these as we let the preferredSecurityScheme override the requirements\n const preferredSecurityNames = [authentication?.preferredSecurityScheme ?? []].flat()\n\n // Set the initially selected security scheme\n const selectedSecuritySchemeUids =\n (securityRequirements.length || preferredSecurityNames?.length) && useCollectionSecurity\n ? getSelectedSecuritySchemeUids(securityRequirements, preferredSecurityNames, securitySchemeMap)\n : []\n\n // Set the uid as a prefixed slug if we have one\n const slugObj = slug?.length ? { uid: getSlugUid(slug) } : {}\n\n const collection = collectionSchema.parse({\n ...slugObj,\n ...schema,\n watchMode,\n documentUrl,\n useCollectionSecurity,\n requests: requests.map((r) => r.uid),\n servers: collectionServers.map((s) => s.uid),\n tags: tags.map((t) => t.uid),\n children: [...collectionChildren],\n security: schema.security ?? [{}],\n selectedServerUid: collectionServers?.[0]?.uid,\n selectedSecuritySchemeUids,\n components: {\n ...schema.components,\n },\n securitySchemes: securitySchemes.map((s) => s.uid),\n })\n\n const end = performance.now()\n console.log(`workspace: ${Math.round(end - start)} ms`)\n\n /**\n * Servers and requests will be saved in top level maps and indexed via UID to\n * maintain specification relationships\n */\n return {\n error: false,\n servers: [...collectionServers, ...operationServers],\n schema,\n requests,\n examples,\n collection,\n tags,\n securitySchemes,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAA0B,aAAa,MAAM,eAAe;AAI5D;AAAA,EAIE;AAAA,OACK;AAKP,SAAkD,wBAAwB;AAE1E,SAA8B,gCAAgC;AAC9D,SAA4C,qBAAqB;AACjE,SAAsB,oBAAoB;AAC1C,SAAmB,iBAAiB;AACpC,SAAS,mBAAmB;AAC5B,SAAS,8BAA8B;AAEvC,MAAM,sBAAsB,OAC1B,UACA,EAAE,aAAa,KAAK,IAA8B,CAAC,MAChD;AACH,MAAI,aAAa,QAAS,OAAO,aAAa,YAAY,SAAS,KAAK,MAAM,IAAK;AACjF,YAAQ,KAAK,sDAAsD;AAEnE,WAAO;AAAA,MACL,QAAQ,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
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.
|
|
19
|
+
"version": "0.6.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -97,26 +97,25 @@
|
|
|
97
97
|
"js-base64": "^3.7.8",
|
|
98
98
|
"microdiff": "^1.5.0",
|
|
99
99
|
"nanoid": "5.1.5",
|
|
100
|
-
"type-fest": "
|
|
100
|
+
"type-fest": "5.0.0",
|
|
101
101
|
"yaml": "2.8.0",
|
|
102
102
|
"zod": "4.1.11",
|
|
103
|
-
"@scalar/helpers": "0.0.
|
|
104
|
-
"@scalar/json-magic": "0.
|
|
105
|
-
"@scalar/object-utils": "1.2.
|
|
106
|
-
"@scalar/
|
|
107
|
-
"@scalar/
|
|
108
|
-
"@scalar/workspace-store": "0.
|
|
109
|
-
"@scalar/types": "0.
|
|
103
|
+
"@scalar/helpers": "0.0.13",
|
|
104
|
+
"@scalar/json-magic": "0.7.0",
|
|
105
|
+
"@scalar/object-utils": "1.2.9",
|
|
106
|
+
"@scalar/themes": "0.13.23",
|
|
107
|
+
"@scalar/openapi-types": "0.5.1",
|
|
108
|
+
"@scalar/workspace-store": "0.18.0",
|
|
109
|
+
"@scalar/types": "0.4.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/node": "^22.9.0",
|
|
113
|
-
"
|
|
114
|
-
"vite": "7.1.5",
|
|
113
|
+
"vite": "7.1.11",
|
|
115
114
|
"vitest": "3.2.4",
|
|
116
115
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
117
|
-
"@scalar/build-tooling": "0.2.
|
|
118
|
-
"@scalar/openapi-
|
|
119
|
-
"@scalar/openapi-
|
|
116
|
+
"@scalar/build-tooling": "0.2.8",
|
|
117
|
+
"@scalar/openapi-parser": "0.23.0",
|
|
118
|
+
"@scalar/openapi-types": "0.5.1"
|
|
120
119
|
},
|
|
121
120
|
"scripts": {
|
|
122
121
|
"build": "scalar-build-esbuild",
|