@scalar/oas-utils 0.5.2 → 0.6.1
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 +28 -0
- 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/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/transforms/import-spec.js +1 -1
- package/dist/transforms/import-spec.js.map +2 -2
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`bffef40`](https://github.com/scalar/scalar/commit/bffef4092e40d12052f8538267af71bc99b7172f)]:
|
|
8
|
+
- @scalar/workspace-store@0.18.1
|
|
9
|
+
|
|
10
|
+
## 0.6.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [#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
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- [#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
|
|
19
|
+
|
|
20
|
+
- [#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
|
|
21
|
+
|
|
22
|
+
- 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)]:
|
|
23
|
+
- @scalar/types@0.4.0
|
|
24
|
+
- @scalar/workspace-store@0.18.0
|
|
25
|
+
- @scalar/openapi-types@0.5.1
|
|
26
|
+
- @scalar/helpers@0.0.13
|
|
27
|
+
- @scalar/json-magic@0.7.0
|
|
28
|
+
- @scalar/themes@0.13.23
|
|
29
|
+
- @scalar/object-utils@1.2.9
|
|
30
|
+
|
|
3
31
|
## 0.5.2
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -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,CAAA;AAEJ,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,GAAI,QAAQ,uBAAuB,EAAE,2BAIhE,CAAA;AAER,kFAAkF;AAClF,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAEpF,eAAO,MAAM,sBAAsB;;;kBAKtB,CAAA;AAEb;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAErE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;mBAS/B,CAAA;AAEF,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA;AA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BAAuB,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,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,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,SAAS,EAAE,IAAI,EAAE,SAAS;AAAA,EAC1B,UAAU,EAAE,QAAQ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,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,kBAA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ACA;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
|
}
|
|
@@ -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
|
}
|
|
@@ -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,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,YAAY,aAAa;AAEtE,SAAO;AAAA,IACL;AAAA,IACA,QAAQ,CAAC,GAAG,YAAY,GAAG,WAAW;A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AI,CAAC,MAAM,EAAE,GAAG;AAAA,IAC3C,MAAM,KAAK,IAAI,CAAC,MAAM,EAAE,GAAG;AAAA,IAC3B,UAAU,CAAC,GAAG,kBAAkB;AAAA,IAChC,UAAU,OAAO,YAAY,CAAC,CAAC,CAAC;AAAA,IAChC,mBAAmB,oBAAoB,CAAC,GAAG;AAAA,IAC3C;AAAA,IACA,YAAY;AAAA,MACV,GAAG,OAAO;AAAA,IACZ;AAAA,IACA,iBAAiB,gBAAgB,IAAI,CAAC,MAAM,EAAE,GAAG;AAAA,EACnD,CAAC;AAED,QAAM,MAAM,YAAY,IAAI;AAC5B,UAAQ,IAAI,cAAc,KAAK,MAAM,MAAM,KAAK,CAAC,KAAK;AAMtD,SAAO;AAAA,IACL,OAAO;AAAA,IACP,SAAS,CAAC,GAAG,mBAAmB,GAAG,gBAAgB;AAAA,IACnD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["securityRequirements", "preferredSecurityNames", "selectedSecuritySchemeUids"]
|
|
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.1",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -100,22 +100,22 @@
|
|
|
100
100
|
"type-fest": "5.0.0",
|
|
101
101
|
"yaml": "2.8.0",
|
|
102
102
|
"zod": "4.1.11",
|
|
103
|
-
"@scalar/
|
|
104
|
-
"@scalar/object-utils": "1.2.
|
|
105
|
-
"@scalar/
|
|
106
|
-
"@scalar/openapi-types": "0.5.
|
|
107
|
-
"@scalar/
|
|
108
|
-
"@scalar/
|
|
109
|
-
"@scalar/
|
|
103
|
+
"@scalar/json-magic": "0.7.0",
|
|
104
|
+
"@scalar/object-utils": "1.2.9",
|
|
105
|
+
"@scalar/helpers": "0.0.13",
|
|
106
|
+
"@scalar/openapi-types": "0.5.1",
|
|
107
|
+
"@scalar/themes": "0.13.23",
|
|
108
|
+
"@scalar/workspace-store": "0.18.1",
|
|
109
|
+
"@scalar/types": "0.4.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/node": "^22.9.0",
|
|
113
|
-
"vite": "7.1.
|
|
113
|
+
"vite": "7.1.11",
|
|
114
114
|
"vitest": "3.2.4",
|
|
115
115
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
116
|
-
"@scalar/
|
|
117
|
-
"@scalar/
|
|
118
|
-
"@scalar/openapi-
|
|
116
|
+
"@scalar/build-tooling": "0.2.8",
|
|
117
|
+
"@scalar/openapi-parser": "0.23.0",
|
|
118
|
+
"@scalar/openapi-types": "0.5.1"
|
|
119
119
|
},
|
|
120
120
|
"scripts": {
|
|
121
121
|
"build": "scalar-build-esbuild",
|