@scalar/oas-utils 0.3.2 → 0.4.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 +22 -0
- package/dist/entities/spec/collection.d.ts +6 -12
- package/dist/entities/spec/collection.d.ts.map +1 -1
- package/dist/entities/spec/collection.js +1 -1
- package/dist/entities/spec/collection.js.map +2 -2
- package/dist/helpers/http-methods.js +9 -9
- package/dist/helpers/http-methods.js.map +1 -1
- package/dist/helpers/pretty-print-json.d.ts.map +1 -1
- package/dist/helpers/pretty-print-json.js.map +2 -2
- package/dist/transforms/import-spec.d.ts +8 -3
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +30 -9
- package/dist/transforms/import-spec.js.map +2 -2
- package/package.json +5 -5
- package/dist/entities/spec/operation.test.js +0 -43
- package/dist/entities/spec/operation.test.js.map +0 -7
- package/dist/entities/spec/parameters.test.js +0 -80
- package/dist/entities/spec/parameters.test.js.map +0 -7
- package/dist/entities/spec/request-example.test.js +0 -633
- package/dist/entities/spec/request-example.test.js.map +0 -7
- package/dist/entities/spec/server.test.js +0 -120
- package/dist/entities/spec/server.test.js.map +0 -7
- package/dist/entities/spec/spec-objects.test.js +0 -205
- package/dist/entities/spec/spec-objects.test.js.map +0 -7
- package/dist/entities/spec/x-scalar-environments.test.js +0 -11
- package/dist/entities/spec/x-scalar-environments.test.js.map +0 -7
- package/dist/entities/spec/x-scalar-secrets.test.js +0 -11
- package/dist/entities/spec/x-scalar-secrets.test.js.map +0 -7
- package/dist/helpers/ensure-protocol.test.js +0 -70
- package/dist/helpers/ensure-protocol.test.js.map +0 -7
- package/dist/helpers/fetch-document.test.js +0 -63
- package/dist/helpers/fetch-document.test.js.map +0 -7
- package/dist/helpers/find-variables.test.js +0 -20
- package/dist/helpers/find-variables.test.js.map +0 -7
- package/dist/helpers/is-defined.test.js +0 -37
- package/dist/helpers/is-defined.test.js.map +0 -7
- package/dist/helpers/is-local-url.test.js +0 -40
- package/dist/helpers/is-local-url.test.js.map +0 -7
- package/dist/helpers/is-valid-url.test.js +0 -17
- package/dist/helpers/is-valid-url.test.js.map +0 -7
- package/dist/helpers/json2xml.test.js +0 -19
- package/dist/helpers/json2xml.test.js.map +0 -7
- package/dist/helpers/make-url-absolute.test.js +0 -61
- package/dist/helpers/make-url-absolute.test.js.map +0 -7
- package/dist/helpers/merge-urls.test.js +0 -339
- package/dist/helpers/merge-urls.test.js.map +0 -7
- package/dist/helpers/normalize-mime-type-object.test.js +0 -53
- package/dist/helpers/normalize-mime-type-object.test.js.map +0 -7
- package/dist/helpers/normalize-mime-type.test.js +0 -33
- package/dist/helpers/normalize-mime-type.test.js.map +0 -7
- package/dist/helpers/omit-undefined-values.test.js +0 -89
- package/dist/helpers/omit-undefined-values.test.js.map +0 -7
- package/dist/helpers/parse.test.js +0 -45
- package/dist/helpers/parse.test.js.map +0 -7
- package/dist/helpers/pretty-print-json.test.js +0 -28
- package/dist/helpers/pretty-print-json.test.js.map +0 -7
- package/dist/helpers/redirect-to-proxy.test.js +0 -54
- package/dist/helpers/redirect-to-proxy.test.js.map +0 -7
- package/dist/helpers/regex-helpers.test.js +0 -154
- package/dist/helpers/regex-helpers.test.js.map +0 -7
- package/dist/helpers/replace-variables.test.js +0 -30
- package/dist/helpers/replace-variables.test.js.map +0 -7
- package/dist/helpers/security/get-schemes.test.js +0 -71
- package/dist/helpers/security/get-schemes.test.js.map +0 -7
- package/dist/helpers/security/has-token.test.js +0 -157
- package/dist/helpers/security/has-token.test.js.map +0 -7
- package/dist/migrations/semver.test.js +0 -21
- package/dist/migrations/semver.test.js.map +0 -7
- package/dist/migrations/v-2.4.0/migration.test.js +0 -90
- package/dist/migrations/v-2.4.0/migration.test.js.map +0 -7
- package/dist/migrations/v-2.5.0/migration.test.js +0 -108
- package/dist/migrations/v-2.5.0/migration.test.js.map +0 -7
- package/dist/spec-getters/get-example-from-schema.test.js +0 -1092
- package/dist/spec-getters/get-example-from-schema.test.js.map +0 -7
- package/dist/spec-getters/get-parameters-from-operation.test.js +0 -178
- package/dist/spec-getters/get-parameters-from-operation.test.js.map +0 -7
- package/dist/spec-getters/get-request-body-from-operation.test.js +0 -289
- package/dist/spec-getters/get-request-body-from-operation.test.js.map +0 -7
- package/dist/transforms/import-spec.test.js +0 -1124
- package/dist/transforms/import-spec.test.js.map +0 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [85877aa]
|
|
8
|
+
- @scalar/themes@0.13.1
|
|
9
|
+
|
|
10
|
+
## 0.4.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 1e87feb: refactor!: use dereferenced documents as a content source
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- cad6277: feat(themes)!: migrate to tailwind v4
|
|
19
|
+
- Updated dependencies [cad6277]
|
|
20
|
+
- @scalar/themes@0.13.0
|
|
21
|
+
- @scalar/object-utils@1.2.1
|
|
22
|
+
- @scalar/openapi-types@0.3.1
|
|
23
|
+
- @scalar/types@0.2.1
|
|
24
|
+
|
|
3
25
|
## 0.3.2
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
|
@@ -139,7 +139,7 @@ export declare const oasCollectionSchema: z.ZodObject<{
|
|
|
139
139
|
* security requirement ({}) can be included in the array.
|
|
140
140
|
*/
|
|
141
141
|
security: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>>, "many">>>;
|
|
142
|
-
externalDocs: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
142
|
+
externalDocs: z.ZodCatch<z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
143
143
|
description: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
144
144
|
url: z.ZodString;
|
|
145
145
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -154,7 +154,7 @@ export declare const oasCollectionSchema: z.ZodObject<{
|
|
|
154
154
|
}, {
|
|
155
155
|
url: string;
|
|
156
156
|
description?: unknown;
|
|
157
|
-
}
|
|
157
|
+
}>>>;
|
|
158
158
|
/** TODO: Type these */
|
|
159
159
|
components: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
160
160
|
/** TODO: Type these */
|
|
@@ -249,10 +249,7 @@ export declare const oasCollectionSchema: z.ZodObject<{
|
|
|
249
249
|
}> | undefined;
|
|
250
250
|
}, {
|
|
251
251
|
type?: "collection" | undefined;
|
|
252
|
-
externalDocs?:
|
|
253
|
-
url: string;
|
|
254
|
-
description?: unknown;
|
|
255
|
-
} | undefined;
|
|
252
|
+
externalDocs?: unknown;
|
|
256
253
|
openapi?: string | undefined;
|
|
257
254
|
jsonSchemaDialect?: string | undefined;
|
|
258
255
|
info?: unknown;
|
|
@@ -486,7 +483,7 @@ export declare const collectionSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
486
483
|
* security requirement ({}) can be included in the array.
|
|
487
484
|
*/
|
|
488
485
|
security: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>>, "many">>>;
|
|
489
|
-
externalDocs: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
486
|
+
externalDocs: z.ZodCatch<z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
490
487
|
description: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
491
488
|
url: z.ZodString;
|
|
492
489
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -501,7 +498,7 @@ export declare const collectionSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
501
498
|
}, {
|
|
502
499
|
url: string;
|
|
503
500
|
description?: unknown;
|
|
504
|
-
}
|
|
501
|
+
}>>>;
|
|
505
502
|
/** TODO: Type these */
|
|
506
503
|
components: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
507
504
|
/** TODO: Type these */
|
|
@@ -653,10 +650,7 @@ export declare const collectionSchema: z.ZodObject<z.objectUtil.extendShape<{
|
|
|
653
650
|
}, {
|
|
654
651
|
uid?: string | undefined;
|
|
655
652
|
type?: "collection" | undefined;
|
|
656
|
-
externalDocs?:
|
|
657
|
-
url: string;
|
|
658
|
-
description?: unknown;
|
|
659
|
-
} | undefined;
|
|
653
|
+
externalDocs?: unknown;
|
|
660
654
|
children?: string[] | undefined;
|
|
661
655
|
openapi?: string | undefined;
|
|
662
656
|
jsonSchemaDialect?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/collection.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,mBAAmB;IAC9B;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAbyC,EAAG,QAAQ,CAAC,EAAE,WAAW,CAAC,EAAE,QAC1E,CAAC,EAAE,SAAS;kBAAgB,EAAI,SAAQ;oBAAiB,EAAG,QAAQ,CAAC,EACrE,WAAU,CAAC,EAAE,SAAS;yBAAwB,EAAG,QAAQ,CAAC,EAAE,WAC3D,CAAC,EAAE,SAAS;oBAAmB,EAAG,UAAU;;uBAC1B,CAAC;kBAEW,CAAC;;;uBAER,CAAC;kBACrB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAeH;;;;;;OAMG;;;;;;;;;;;;;;;;;;IAGH,uBAAuB;;IAEvB,uBAAuB;;IAEvB,gDAAgD
|
|
1
|
+
{"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,GAAG,QAC1E,GAAG,SAAS;oBAAoB,SAAQ;sBAAoB,QAAQ,GACpE,WAAU,GAAG,SAAS;2BAA2B,QAAQ,GAAG,WAC3D,GAAG,SAAS;sBAAsB,UAAU;;uBAC1B,CAAC;kBAEW,CAAC;;;uBAER,CAAC;kBACrB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAeH;;;;;;OAMG;;;;;;;;;;;;;;;;;;IAGH,uBAAuB;;IAEvB,uBAAuB;;IAEvB,gDAAgD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAehD,qEAAqE;;IAErE,2FAA2F;;IAE3F,oCAAoC;;IAEpC,wDAAwD;;IAExD,gDAAgD;;IAEhD,8CAA8C;;IAE9C,gEAAgE;;IAKhE;;;;;OAKG;;IAEH;;;;OAIG;;IAEH,kFAAkF;;IAElF;;;;OAIG;;IAEH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAI8E,CAAA;AACnF,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA;AACzD,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA"}
|
|
@@ -26,7 +26,7 @@ const oasCollectionSchema = z.object({
|
|
|
26
26
|
* security requirement ({}) can be included in the array.
|
|
27
27
|
*/
|
|
28
28
|
"security": z.array(oasSecurityRequirementSchema).optional().default([]),
|
|
29
|
-
"externalDocs": oasExternalDocumentationSchema.optional(),
|
|
29
|
+
"externalDocs": oasExternalDocumentationSchema.optional().catch(void 0),
|
|
30
30
|
/** TODO: Type these */
|
|
31
31
|
"components": z.record(z.string(), z.unknown()).optional(),
|
|
32
32
|
/** TODO: Type these */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/entities/spec/collection.ts"],
|
|
4
|
-
"sourcesContent": ["import { selectedSecuritySchemeUidSchema } from '@/entities/shared/utility'\nimport { xScalarEnvironmentsSchema } from '@/entities/spec/x-scalar-environments'\nimport { xScalarSecretsSchema } from '@/entities/spec/x-scalar-secrets'\nimport { oasSecurityRequirementSchema } from '@scalar/types/entities'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { oasExternalDocumentationSchema, oasInfoSchema } from './spec-objects'\n\nexport const oasCollectionSchema = z.object({\n /**\n * @deprecated\n *\n * Needs to be remove as it is not a spec property\n */\n 'type': z.literal('collection').optional().default('collection'),\n 'openapi': z\n .union([z.string(), z.literal('3.0.0'), z.literal('3.1.0'), z.literal('4.0.0')])\n .optional()\n .default('3.1.0'),\n 'jsonSchemaDialect': z.string().optional(),\n 'info': oasInfoSchema.catch({\n title: 'API',\n version: '1.0',\n }),\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().default([]),\n 'externalDocs': oasExternalDocumentationSchema.optional(),\n /** TODO: Type these */\n 'components': z.record(z.string(), z.unknown()).optional(),\n /** TODO: Type these */\n 'webhooks': z.record(z.string(), z.unknown()).optional(),\n /** A custom icon representing the collection */\n 'x-scalar-icon': z.string().optional().default('interface-content-folder'),\n 'x-scalar-active-environment': z.string().optional(),\n 'x-scalar-environments': xScalarEnvironmentsSchema.optional(),\n 'x-scalar-secrets': xScalarSecretsSchema.optional(),\n // These properties will be stripped out and mapped back as id lists\n // servers\n // paths/**\n // servers\n // tags\n // security\n})\n\nexport const extendedCollectionSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['COLLECTION']>(),\n /** A list of security schemes UIDs associated with the collection */\n securitySchemes: z.string().array().default([]),\n /** List of currently selected security scheme UIDs, these can be overridden per request */\n selectedSecuritySchemeUids: selectedSecuritySchemeUidSchema,\n /** The currently selected server */\n selectedServerUid: z.string().brand<ENTITY_BRANDS['SERVER']>().optional(),\n /** UIDs which refer to servers on the workspace base */\n servers: z.string().brand<ENTITY_BRANDS['SERVER']>().array().default([]),\n /** Request UIDs associated with a collection */\n requests: z.string().brand<ENTITY_BRANDS['OPERATION']>().array().default([]),\n /** Tag UIDs associated with the collection */\n tags: z.string().brand<ENTITY_BRANDS['TAG']>().array().default([]),\n /** List of requests without tags and top level tag \"folders\" */\n children: z\n .union([z.string().brand<ENTITY_BRANDS['OPERATION']>(), z.string().brand<ENTITY_BRANDS['TAG']>()])\n .array()\n .default([]),\n /**\n * A link to where this document is stored\n *\n * - Used for watch mode\n * - Possibly useful for Git sync down the line\n */\n documentUrl: z.string().optional(),\n /**\n * Enables polling of OpenAPI document urls\n *\n * @remarks Only effective when `documentUrl` is set\n */\n watchMode: z.boolean().optional().default(false),\n /** Keeps track of which integration is associated with the specific collection */\n integration: z.string().nullable().optional(),\n /**\n * Selected authentication will be set at the collection level instead of the request level\n *\n * @default false\n */\n useCollectionSecurity: z.boolean().optional().default(false),\n /**\n * Status of the watcher from above\n *\n * @defaults to idle for all collections, doesn't mean that it can watch for changes\n */\n watchModeStatus: z.enum(['IDLE', 'WATCHING', 'ERROR']).optional().default('IDLE'),\n})\n\nexport const collectionSchema = oasCollectionSchema.merge(extendedCollectionSchema)\nexport type Collection = z.infer<typeof collectionSchema>\nexport type CollectionPayload = z.input<typeof collectionSchema>\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,uCAAuC;AAChD,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AACrC,SAAS,oCAAoC;AAC7C,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,gCAAgC,qBAAqB;AAEvD,MAAM,sBAAsB,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1C,QAAQ,EAAE,QAAQ,YAAY,EAAE,SAAS,EAAE,QAAQ,YAAY;AAAA,EAC/D,WAAW,EACR,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,CAAC,CAAC,EAC9E,SAAS,EACT,QAAQ,OAAO;AAAA,EAClB,qBAAqB,EAAE,OAAO,EAAE,SAAS;AAAA,EACzC,QAAQ,cAAc,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQD,YAAY,EAAE,MAAM,4BAA4B,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAAA,EACvE,gBAAgB,+BAA+B,SAAS;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { selectedSecuritySchemeUidSchema } from '@/entities/shared/utility'\nimport { xScalarEnvironmentsSchema } from '@/entities/spec/x-scalar-environments'\nimport { xScalarSecretsSchema } from '@/entities/spec/x-scalar-secrets'\nimport { oasSecurityRequirementSchema } from '@scalar/types/entities'\nimport { type ENTITY_BRANDS, nanoidSchema } from '@scalar/types/utils'\nimport { z } from 'zod'\n\nimport { oasExternalDocumentationSchema, oasInfoSchema } from './spec-objects'\n\nexport const oasCollectionSchema = z.object({\n /**\n * @deprecated\n *\n * Needs to be remove as it is not a spec property\n */\n 'type': z.literal('collection').optional().default('collection'),\n 'openapi': z\n .union([z.string(), z.literal('3.0.0'), z.literal('3.1.0'), z.literal('4.0.0')])\n .optional()\n .default('3.1.0'),\n 'jsonSchemaDialect': z.string().optional(),\n 'info': oasInfoSchema.catch({\n title: 'API',\n version: '1.0',\n }),\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().default([]),\n 'externalDocs': oasExternalDocumentationSchema.optional().catch(undefined),\n /** TODO: Type these */\n 'components': z.record(z.string(), z.unknown()).optional(),\n /** TODO: Type these */\n 'webhooks': z.record(z.string(), z.unknown()).optional(),\n /** A custom icon representing the collection */\n 'x-scalar-icon': z.string().optional().default('interface-content-folder'),\n 'x-scalar-active-environment': z.string().optional(),\n 'x-scalar-environments': xScalarEnvironmentsSchema.optional(),\n 'x-scalar-secrets': xScalarSecretsSchema.optional(),\n // These properties will be stripped out and mapped back as id lists\n // servers\n // paths/**\n // servers\n // tags\n // security\n})\n\nexport const extendedCollectionSchema = z.object({\n uid: nanoidSchema.brand<ENTITY_BRANDS['COLLECTION']>(),\n /** A list of security schemes UIDs associated with the collection */\n securitySchemes: z.string().array().default([]),\n /** List of currently selected security scheme UIDs, these can be overridden per request */\n selectedSecuritySchemeUids: selectedSecuritySchemeUidSchema,\n /** The currently selected server */\n selectedServerUid: z.string().brand<ENTITY_BRANDS['SERVER']>().optional(),\n /** UIDs which refer to servers on the workspace base */\n servers: z.string().brand<ENTITY_BRANDS['SERVER']>().array().default([]),\n /** Request UIDs associated with a collection */\n requests: z.string().brand<ENTITY_BRANDS['OPERATION']>().array().default([]),\n /** Tag UIDs associated with the collection */\n tags: z.string().brand<ENTITY_BRANDS['TAG']>().array().default([]),\n /** List of requests without tags and top level tag \"folders\" */\n children: z\n .union([z.string().brand<ENTITY_BRANDS['OPERATION']>(), z.string().brand<ENTITY_BRANDS['TAG']>()])\n .array()\n .default([]),\n /**\n * A link to where this document is stored\n *\n * - Used for watch mode\n * - Possibly useful for Git sync down the line\n */\n documentUrl: z.string().optional(),\n /**\n * Enables polling of OpenAPI document urls\n *\n * @remarks Only effective when `documentUrl` is set\n */\n watchMode: z.boolean().optional().default(false),\n /** Keeps track of which integration is associated with the specific collection */\n integration: z.string().nullable().optional(),\n /**\n * Selected authentication will be set at the collection level instead of the request level\n *\n * @default false\n */\n useCollectionSecurity: z.boolean().optional().default(false),\n /**\n * Status of the watcher from above\n *\n * @defaults to idle for all collections, doesn't mean that it can watch for changes\n */\n watchModeStatus: z.enum(['IDLE', 'WATCHING', 'ERROR']).optional().default('IDLE'),\n})\n\nexport const collectionSchema = oasCollectionSchema.merge(extendedCollectionSchema)\nexport type Collection = z.infer<typeof collectionSchema>\nexport type CollectionPayload = z.input<typeof collectionSchema>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uCAAuC;AAChD,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AACrC,SAAS,oCAAoC;AAC7C,SAA6B,oBAAoB;AACjD,SAAS,SAAS;AAElB,SAAS,gCAAgC,qBAAqB;AAEvD,MAAM,sBAAsB,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1C,QAAQ,EAAE,QAAQ,YAAY,EAAE,SAAS,EAAE,QAAQ,YAAY;AAAA,EAC/D,WAAW,EACR,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,CAAC,CAAC,EAC9E,SAAS,EACT,QAAQ,OAAO;AAAA,EAClB,qBAAqB,EAAE,OAAO,EAAE,SAAS;AAAA,EACzC,QAAQ,cAAc,MAAM;AAAA,IAC1B,OAAO;AAAA,IACP,SAAS;AAAA,EACX,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQD,YAAY,EAAE,MAAM,4BAA4B,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAAA,EACvE,gBAAgB,+BAA+B,SAAS,EAAE,MAAM,MAAS;AAAA;AAAA,EAEzE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AAAA;AAAA,EAEzD,YAAY,EAAE,OAAO,EAAE,OAAO,GA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QAAQ,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3D,iBAAiB,EAAE,KAAK,CAAC,QAAQ,YAAY,OAAO,CAAC,EAAE,SAAS,EAAE,QAAQ,MAAM;AAClF,CAAC;AAEM,MAAM,mBAAmB,oBAAoB,MAAM,wBAAwB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,47 +3,47 @@ const REQUEST_METHODS = {
|
|
|
3
3
|
get: {
|
|
4
4
|
short: "GET",
|
|
5
5
|
color: "text-blue",
|
|
6
|
-
backgroundColor: "bg-blue"
|
|
6
|
+
backgroundColor: "bg-blue/10"
|
|
7
7
|
},
|
|
8
8
|
post: {
|
|
9
9
|
short: "POST",
|
|
10
10
|
color: "text-green",
|
|
11
|
-
backgroundColor: "bg-green"
|
|
11
|
+
backgroundColor: "bg-green/10"
|
|
12
12
|
},
|
|
13
13
|
put: {
|
|
14
14
|
short: "PUT",
|
|
15
15
|
color: "text-orange",
|
|
16
|
-
backgroundColor: "bg-orange"
|
|
16
|
+
backgroundColor: "bg-orange/10"
|
|
17
17
|
},
|
|
18
18
|
patch: {
|
|
19
19
|
short: "PATCH",
|
|
20
20
|
color: "text-yellow",
|
|
21
|
-
backgroundColor: "bg-yellow"
|
|
21
|
+
backgroundColor: "bg-yellow/10"
|
|
22
22
|
},
|
|
23
23
|
delete: {
|
|
24
24
|
short: "DEL",
|
|
25
25
|
color: "text-red",
|
|
26
|
-
backgroundColor: "bg-red"
|
|
26
|
+
backgroundColor: "bg-red/10"
|
|
27
27
|
},
|
|
28
28
|
options: {
|
|
29
29
|
short: "OPTS",
|
|
30
30
|
color: "text-purple",
|
|
31
|
-
backgroundColor: "bg-purple"
|
|
31
|
+
backgroundColor: "bg-purple/10"
|
|
32
32
|
},
|
|
33
33
|
head: {
|
|
34
34
|
short: "HEAD",
|
|
35
35
|
color: "text-scalar-c-2",
|
|
36
|
-
backgroundColor: "bg-c-2"
|
|
36
|
+
backgroundColor: "bg-c-2/10"
|
|
37
37
|
},
|
|
38
38
|
connect: {
|
|
39
39
|
short: "CONN",
|
|
40
40
|
color: "text-c-2",
|
|
41
|
-
backgroundColor: "bg-c-2"
|
|
41
|
+
backgroundColor: "bg-c-2/10"
|
|
42
42
|
},
|
|
43
43
|
trace: {
|
|
44
44
|
short: "TRACE",
|
|
45
45
|
color: "text-c-2",
|
|
46
|
-
backgroundColor: "bg-c-2"
|
|
46
|
+
backgroundColor: "bg-c-2/10"
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
const BODY_METHODS = ["post", "put", "patch", "delete"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/http-methods.ts"],
|
|
4
|
-
"sourcesContent": ["import { type RequestMethod, requestMethods } from '@/entities/spec/requests'\n\n/**\n * HTTP methods in a specific order\n * Do not change the order\n */\nexport const REQUEST_METHODS: {\n [x in RequestMethod]: {\n short: string\n color: string\n backgroundColor: string\n }\n} = {\n get: {\n short: 'GET',\n color: 'text-blue',\n backgroundColor: 'bg-blue',\n },\n post: {\n short: 'POST',\n color: 'text-green',\n backgroundColor: 'bg-green',\n },\n put: {\n short: 'PUT',\n color: 'text-orange',\n backgroundColor: 'bg-orange',\n },\n patch: {\n short: 'PATCH',\n color: 'text-yellow',\n backgroundColor: 'bg-yellow',\n },\n delete: {\n short: 'DEL',\n color: 'text-red',\n backgroundColor: 'bg-red',\n },\n options: {\n short: 'OPTS',\n color: 'text-purple',\n backgroundColor: 'bg-purple',\n },\n head: {\n short: 'HEAD',\n color: 'text-scalar-c-2',\n backgroundColor: 'bg-c-2',\n },\n connect: {\n short: 'CONN',\n color: 'text-c-2',\n backgroundColor: 'bg-c-2',\n },\n trace: {\n short: 'TRACE',\n color: 'text-c-2',\n backgroundColor: 'bg-c-2',\n },\n} as const\n\n/** HTTP Methods which can have a body */\nconst BODY_METHODS = ['post', 'put', 'patch', 'delete'] as const\ntype BodyMethod = (typeof BODY_METHODS)[number]\n\n/** Makes a check to see if this method CAN have a body */\nexport const canMethodHaveBody = (method: RequestMethod): method is BodyMethod =>\n BODY_METHODS.includes(method as BodyMethod)\n\n/**\n * Accepts an HTTP Method name and returns some properties for the tag\n */\nexport const getHttpMethodInfo = (methodName: string) => {\n const normalizedMethod = methodName.trim().toLowerCase()\n return (\n REQUEST_METHODS[normalizedMethod as RequestMethod] ?? {\n short: normalizedMethod,\n color: 'text-c-2',\n backgroundColor: 'bg-c-2',\n }\n )\n}\n\n/** Type guard which takes in a string and returns true if it is in fact an HTTPMethod */\nexport const isHttpMethod = (method?: string | undefined): method is RequestMethod =>\n method ? requestMethods.includes(method as RequestMethod) : false\n"],
|
|
4
|
+
"sourcesContent": ["import { type RequestMethod, requestMethods } from '@/entities/spec/requests'\n\n/**\n * HTTP methods in a specific order\n * Do not change the order\n */\nexport const REQUEST_METHODS: {\n [x in RequestMethod]: {\n short: string\n color: string\n backgroundColor: string\n }\n} = {\n get: {\n short: 'GET',\n color: 'text-blue',\n backgroundColor: 'bg-blue/10',\n },\n post: {\n short: 'POST',\n color: 'text-green',\n backgroundColor: 'bg-green/10',\n },\n put: {\n short: 'PUT',\n color: 'text-orange',\n backgroundColor: 'bg-orange/10',\n },\n patch: {\n short: 'PATCH',\n color: 'text-yellow',\n backgroundColor: 'bg-yellow/10',\n },\n delete: {\n short: 'DEL',\n color: 'text-red',\n backgroundColor: 'bg-red/10',\n },\n options: {\n short: 'OPTS',\n color: 'text-purple',\n backgroundColor: 'bg-purple/10',\n },\n head: {\n short: 'HEAD',\n color: 'text-scalar-c-2',\n backgroundColor: 'bg-c-2/10',\n },\n connect: {\n short: 'CONN',\n color: 'text-c-2',\n backgroundColor: 'bg-c-2/10',\n },\n trace: {\n short: 'TRACE',\n color: 'text-c-2',\n backgroundColor: 'bg-c-2/10',\n },\n} as const\n\n/** HTTP Methods which can have a body */\nconst BODY_METHODS = ['post', 'put', 'patch', 'delete'] as const\ntype BodyMethod = (typeof BODY_METHODS)[number]\n\n/** Makes a check to see if this method CAN have a body */\nexport const canMethodHaveBody = (method: RequestMethod): method is BodyMethod =>\n BODY_METHODS.includes(method as BodyMethod)\n\n/**\n * Accepts an HTTP Method name and returns some properties for the tag\n */\nexport const getHttpMethodInfo = (methodName: string) => {\n const normalizedMethod = methodName.trim().toLowerCase()\n return (\n REQUEST_METHODS[normalizedMethod as RequestMethod] ?? {\n short: normalizedMethod,\n color: 'text-c-2',\n backgroundColor: 'bg-c-2',\n }\n )\n}\n\n/** Type guard which takes in a string and returns true if it is in fact an HTTPMethod */\nexport const isHttpMethod = (method?: string | undefined): method is RequestMethod =>\n method ? requestMethods.includes(method as RequestMethod) : false\n"],
|
|
5
5
|
"mappings": "AAAA,SAA6B,sBAAsB;AAM5C,MAAM,kBAMT;AAAA,EACF,KAAK;AAAA,IACH,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,QAAQ;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,MAAM;AAAA,IACJ,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,SAAS;AAAA,IACP,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AACF;AAGA,MAAM,eAAe,CAAC,QAAQ,OAAO,SAAS,QAAQ;AAI/C,MAAM,oBAAoB,CAAC,WAChC,aAAa,SAAS,MAAoB;AAKrC,MAAM,oBAAoB,CAAC,eAAuB;AACvD,QAAM,mBAAmB,WAAW,KAAK,EAAE,YAAY;AACvD,SACE,gBAAgB,gBAAiC,KAAK;AAAA,IACpD,OAAO;AAAA,IACP,OAAO;AAAA,IACP,iBAAiB;AAAA,EACnB;AAEJ;AAGO,MAAM,eAAe,CAAC,WAC3B,SAAS,eAAe,SAAS,MAAuB,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretty-print-json.d.ts","sourceRoot":"","sources":["../../src/helpers/pretty-print-json.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"pretty-print-json.d.ts","sourceRoot":"","sources":["../../src/helpers/pretty-print-json.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,KAAG,MAqBnF,CAAA;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,GAAG,UAiBvD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/helpers/pretty-print-json.ts"],
|
|
4
|
-
"sourcesContent": ["import { isJsonString } from './parse'\n\n/**\n * Takes JSON and formats it.\n */\nexport const prettyPrintJson = (value: string | number | any[] | Record<any, any>) => {\n if (typeof value === 'string') {\n // JSON string\n if (isJsonString(value)) {\n return JSON.stringify(JSON.parse(value), null, 2)\n }\n\n // Regular string\n return value\n }\n\n // Object\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value, null, 2)\n } catch {\n return replaceCircularDependencies(value)\n }\n }\n\n return value?.toString() ?? ''\n}\n\n/**\n * JSON.stringify, but with circular dependencies replaced with '[Circular]'\n */\nexport function replaceCircularDependencies(content: any) {\n const cache = new Set()\n\n return JSON.stringify(\n content,\n (_key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n return '[Circular]'\n }\n\n cache.add(value)\n }\n return value\n },\n 2,\n )\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,oBAAoB;AAKtB,MAAM,kBAAkB,CAAC,
|
|
4
|
+
"sourcesContent": ["import { isJsonString } from './parse'\n\n/**\n * Takes JSON and formats it.\n */\nexport const prettyPrintJson = (value: string | number | any[] | Record<any, any>): string => {\n if (typeof value === 'string') {\n // JSON string\n if (isJsonString(value)) {\n return JSON.stringify(JSON.parse(value), null, 2)\n }\n\n // Regular string\n return value\n }\n\n // Object\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value, null, 2)\n } catch {\n return replaceCircularDependencies(value)\n }\n }\n\n return value?.toString() ?? ''\n}\n\n/**\n * JSON.stringify, but with circular dependencies replaced with '[Circular]'\n */\nexport function replaceCircularDependencies(content: any) {\n const cache = new Set()\n\n return JSON.stringify(\n content,\n (_key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n return '[Circular]'\n }\n\n cache.add(value)\n }\n return value\n },\n 2,\n )\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,oBAAoB;AAKtB,MAAM,kBAAkB,CAAC,UAA8D;AAC5F,MAAI,OAAO,UAAU,UAAU;AAE7B,QAAI,aAAa,KAAK,GAAG;AACvB,aAAO,KAAK,UAAU,KAAK,MAAM,KAAK,GAAG,MAAM,CAAC;AAAA,IAClD;AAGA,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,UAAU,UAAU;AAC7B,QAAI;AACF,aAAO,KAAK,UAAU,OAAO,MAAM,CAAC;AAAA,IACtC,QAAQ;AACN,aAAO,4BAA4B,KAAK;AAAA,IAC1C;AAAA,EACF;AAEA,SAAO,OAAO,SAAS,KAAK;AAC9B;AAKO,SAAS,4BAA4B,SAAc;AACxD,QAAM,QAAQ,oBAAI,IAAI;AAEtB,SAAO,KAAK;AAAA,IACV;AAAA,IACA,CAAC,MAAM,UAAU;AACf,UAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,YAAI,MAAM,IAAI,KAAK,GAAG;AACpB,iBAAO;AAAA,QACT;AAEA,cAAM,IAAI,KAAK;AAAA,MACjB;AACA,aAAO;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,8 +9,9 @@ import { type Server } from '../entities/spec/server.js';
|
|
|
9
9
|
import { type Tag } from '../entities/spec/spec-objects.js';
|
|
10
10
|
import { type SecurityScheme } from '@scalar/types/entities';
|
|
11
11
|
/** Takes a string or object and parses it into an openapi spec compliant schema */
|
|
12
|
-
export declare const parseSchema: (
|
|
13
|
-
shouldLoad?: boolean
|
|
12
|
+
export declare const parseSchema: (originalDocument: string | UnknownObject | undefined, { shouldLoad, dereferencedDocument, }?: {
|
|
13
|
+
shouldLoad?: boolean;
|
|
14
|
+
dereferencedDocument?: OpenAPIV3_1.Document;
|
|
14
15
|
}) => Promise<{
|
|
15
16
|
/**
|
|
16
17
|
* Temporary fix for the parser returning an empty array
|
|
@@ -24,6 +25,8 @@ export declare const getSelectedSecuritySchemeUids: (securityRequirements: (stri
|
|
|
24
25
|
/** Create a "uid" from a slug */
|
|
25
26
|
export declare const getSlugUid: (slug: string) => Collection["uid"];
|
|
26
27
|
export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ApiReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers' | 'slug'> & {
|
|
28
|
+
/** The dereferenced document */
|
|
29
|
+
dereferencedDocument?: OpenAPIV3_1.Document;
|
|
27
30
|
/** Sets the preferred security scheme on the collection instead of the requests */
|
|
28
31
|
useCollectionSecurity?: boolean;
|
|
29
32
|
/** Call the load step from the parser */
|
|
@@ -42,7 +45,9 @@ export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' |
|
|
|
42
45
|
* - Proper linking between related components
|
|
43
46
|
* - Easy lookup and reference of dependent entities
|
|
44
47
|
*/
|
|
45
|
-
export declare function importSpecToWorkspace(
|
|
48
|
+
export declare function importSpecToWorkspace(content: string | UnknownObject | undefined, {
|
|
49
|
+
/** If a dereferenced document is provided, we will skip the dereferencing step. */
|
|
50
|
+
dereferencedDocument, authentication, baseServerURL, documentUrl, servers: configuredServers, useCollectionSecurity, slug, shouldLoad, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{
|
|
46
51
|
error: false;
|
|
47
52
|
collection: Collection;
|
|
48
53
|
requests: Request[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAoB,MAAM,4BAA4B,CAAA;AAEtG,OAAO,EAAE,KAAK,cAAc,EAA4B,MAAM,kCAAkC,CAAA;AAChG,OAAO,EAAE,KAAK,OAAO,EAAsC,MAAM,0BAA0B,CAAA;AAC3F,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,wBAAwB,CAAA;AAClE,OAAO,EAAE,KAAK,GAAG,EAAa,MAAM,8BAA8B,CAAA;AA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AAI,CAAC,yBAAyB,EAAE,eAAe,CAAM,GACvE,MAAM,EAAE,CA0CV"}
|
|
@@ -12,18 +12,18 @@ import { schemaModel } from "../helpers/schema-model.js";
|
|
|
12
12
|
import {
|
|
13
13
|
securitySchemeSchema
|
|
14
14
|
} from "@scalar/types/entities";
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
15
|
+
const dereferenceDocument = async (document, { shouldLoad = true } = {}) => {
|
|
16
|
+
if (document === null || typeof document === "string" && document.trim() === "") {
|
|
17
17
|
console.warn("[@scalar/oas-utils] Empty OpenAPI document provided.");
|
|
18
18
|
return {
|
|
19
19
|
schema: {},
|
|
20
20
|
errors: []
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
let filesystem =
|
|
23
|
+
let filesystem = document;
|
|
24
24
|
let loadErrors = [];
|
|
25
25
|
if (shouldLoad) {
|
|
26
|
-
const
|
|
26
|
+
const response = await load(document).catch((e) => ({
|
|
27
27
|
errors: [
|
|
28
28
|
{
|
|
29
29
|
code: e.code,
|
|
@@ -32,11 +32,30 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
|
32
32
|
],
|
|
33
33
|
filesystem: []
|
|
34
34
|
}));
|
|
35
|
-
filesystem =
|
|
36
|
-
loadErrors =
|
|
35
|
+
filesystem = response.filesystem;
|
|
36
|
+
loadErrors = response.errors ?? [];
|
|
37
37
|
}
|
|
38
38
|
const { specification } = upgrade(filesystem);
|
|
39
39
|
const { schema, errors: derefErrors = [] } = await dereference(specification);
|
|
40
|
+
return {
|
|
41
|
+
schema,
|
|
42
|
+
errors: [...loadErrors, ...derefErrors]
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const parseSchema = async (originalDocument, {
|
|
46
|
+
shouldLoad = true,
|
|
47
|
+
/** If a dereferenced document is provided, we will skip the dereferencing step. */
|
|
48
|
+
dereferencedDocument = void 0
|
|
49
|
+
} = {}) => {
|
|
50
|
+
const { schema, errors } = dereferencedDocument ? {
|
|
51
|
+
schema: dereferencedDocument,
|
|
52
|
+
errors: []
|
|
53
|
+
} : (
|
|
54
|
+
// Otherwise, dereference the original document
|
|
55
|
+
await dereferenceDocument(originalDocument ?? "", {
|
|
56
|
+
shouldLoad
|
|
57
|
+
})
|
|
58
|
+
);
|
|
40
59
|
if (!schema) {
|
|
41
60
|
console.warn("[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined");
|
|
42
61
|
}
|
|
@@ -46,7 +65,7 @@ const parseSchema = async (spec, { shouldLoad = true } = {}) => {
|
|
|
46
65
|
* TODO: remove this once the parser is fixed
|
|
47
66
|
*/
|
|
48
67
|
schema: Array.isArray(schema) ? {} : schema,
|
|
49
|
-
errors
|
|
68
|
+
errors
|
|
50
69
|
};
|
|
51
70
|
};
|
|
52
71
|
const getSelectedSecuritySchemeUids = (securityRequirements, preferredSecurityNames = [], securitySchemeMap) => {
|
|
@@ -57,7 +76,9 @@ const getSelectedSecuritySchemeUids = (securityRequirements, preferredSecurityNa
|
|
|
57
76
|
return uids;
|
|
58
77
|
};
|
|
59
78
|
const getSlugUid = (slug) => `slug-uid-${slug}`;
|
|
60
|
-
async function importSpecToWorkspace(
|
|
79
|
+
async function importSpecToWorkspace(content, {
|
|
80
|
+
/** If a dereferenced document is provided, we will skip the dereferencing step. */
|
|
81
|
+
dereferencedDocument,
|
|
61
82
|
authentication,
|
|
62
83
|
baseServerURL,
|
|
63
84
|
documentUrl,
|
|
@@ -67,7 +88,7 @@ async function importSpecToWorkspace(spec, {
|
|
|
67
88
|
shouldLoad,
|
|
68
89
|
watchMode = false
|
|
69
90
|
} = {}) {
|
|
70
|
-
const { schema, errors } = await parseSchema(
|
|
91
|
+
const { schema, errors } = await parseSchema(content, { shouldLoad, dereferencedDocument });
|
|
71
92
|
const importWarnings = [...errors.map((e) => e.message)];
|
|
72
93
|
if (!schema) {
|
|
73
94
|
return { importWarnings, error: true, collection: void 0 };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/transforms/import-spec.ts"],
|
|
4
|
-
"sourcesContent": ["import { 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 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 { isHttpMethod } from '@/helpers/http-methods'\nimport { isDefined } from '@/helpers/is-defined'\nimport { combineUrlAndPath } from '@/helpers/merge-urls'\nimport { schemaModel } from '@/helpers/schema-model'\nimport {\n type Oauth2FlowPayload,\n type SecurityScheme,\n type SecuritySchemePayload,\n securitySchemeSchema,\n} from '@scalar/types/entities'\n\n/** Takes a string or object and parses it into an openapi spec compliant schema */\nexport const parseSchema = async (spec: string | UnknownObject, { shouldLoad = true } = {}) => {\n if (spec === null || (typeof spec === 'string' && spec.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 = spec\n let loadErrors: LoadResult['errors'] = []\n\n if (shouldLoad) {\n // TODO: Plugins for URLs and files with the proxy is missing here.\n // @see packages/api-reference/src/helpers/parse.ts\n const resp = await load(spec).catch((e) => ({\n errors: [\n {\n code: e.code,\n message: e.message,\n },\n ],\n filesystem: [],\n }))\n filesystem = resp.filesystem\n loadErrors = resp.errors ?? []\n }\n\n const { specification } = upgrade(filesystem)\n const { schema, errors: derefErrors = [] } = await dereference(specification)\n\n if (!schema) {\n console.warn('[@scalar/oas-utils] OpenAPI Parser Warning: Schema is undefined')\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: [...loadErrors, ...derefErrors],\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 /** 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 spec: string | UnknownObject,\n {\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(spec, { shouldLoad })\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[] = getServersFromOpenApiDocument(configuredServers || schema.servers, {\n baseServerURL,\n })\n\n // Store operation servers\n const operationServers: Server[] = []\n\n // Fallback to the current window.location.origin if no servers are provided\n if (!collectionServers.length) {\n const fallbackUrl = getFallbackUrl()\n\n if (fallbackUrl) {\n collectionServers.push(serverSchema.parse({ url: fallbackUrl }))\n }\n }\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: OpenAPIV3_1.OperationObject = path[method]\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 // Add list of UIDs to associate security schemes\n // As per the spec if there is operation level security we ignore the top level requirements\n if (operationSecurity?.length) {\n requestPayload.security = operationSecurity.map((s: OpenAPIV3_1.SecurityRequirementObject) => {\n const keys = Object.keys(s)\n\n // Handle the case of {} for optional\n if (keys.length) {\n const [key] = Object.keys(s)\n if (key) {\n return {\n [key]: s[key],\n }\n }\n }\n return s\n })\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\n/**\n * Retrieves a list of servers from an OpenAPI document and converts them to a list of Server entities.\n */\nexport function getServersFromOpenApiDocument(\n servers: OpenAPIV3_1.ServerObject[] | undefined,\n { baseServerURL }: Pick<ApiReferenceConfiguration, 'baseServerURL'> = {},\n): Server[] {\n if (!servers || !Array.isArray(servers)) {\n return []\n }\n\n return servers\n .map((server): Server | undefined => {\n try {\n // Validate the server against the schema\n const parsedSchema = serverSchema.parse(server)\n\n // Prepend with the base server URL (if the given URL is relative)\n if (parsedSchema?.url?.startsWith('/')) {\n // Use the base server URL (if provided)\n if (baseServerURL) {\n parsedSchema.url = combineUrlAndPath(baseServerURL, parsedSchema.url)\n\n return parsedSchema\n }\n\n // Fallback to the current window origin\n const fallbackUrl = getFallbackUrl()\n\n if (fallbackUrl) {\n parsedSchema.url = combineUrlAndPath(fallbackUrl, parsedSchema.url.replace(/^\\//, ''))\n\n return parsedSchema\n }\n }\n\n // Must be good, return it\n return parsedSchema\n } catch (error) {\n console.warn('Oops, that\u2019s an invalid server configuration.')\n console.warn('Server:', server)\n console.warn('Error:', error)\n\n // Return undefined to remove the server\n return undefined\n }\n })\n .filter(isDefined)\n}\n\n/**\n * Fallback to the current window.location.origin, if available\n */\nfunction getFallbackUrl() {\n if (typeof window === 'undefined') {\n return undefined\n }\n\n if (typeof window?.location?.origin !== 'string') {\n return undefined\n }\n\n return window.location.origin\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,cAAc;AACvB,SAA0B,aAAa,MAAM,eAAe;AAQ5D,SAAkD,wBAAwB;AAE1E,SAA8B,gCAAgC;AAC9D,SAA4C,qBAAqB;AACjE,SAAsB,oBAAoB;AAC1C,SAAmB,iBAAiB;AACpC,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAAS,mBAAmB;AAC5B;AAAA,EAIE;AAAA,OACK;
|
|
4
|
+
"sourcesContent": ["import { 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 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 { isHttpMethod } from '@/helpers/http-methods'\nimport { isDefined } from '@/helpers/is-defined'\nimport { combineUrlAndPath } from '@/helpers/merge-urls'\nimport { schemaModel } from '@/helpers/schema-model'\nimport {\n type Oauth2FlowPayload,\n type SecurityScheme,\n type SecuritySchemePayload,\n securitySchemeSchema,\n} from '@scalar/types/entities'\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[] = getServersFromOpenApiDocument(configuredServers || schema.servers, {\n baseServerURL,\n })\n\n // Store operation servers\n const operationServers: Server[] = []\n\n // Fallback to the current window.location.origin if no servers are provided\n if (!collectionServers.length) {\n const fallbackUrl = getFallbackUrl()\n\n if (fallbackUrl) {\n collectionServers.push(serverSchema.parse({ url: fallbackUrl }))\n }\n }\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: OpenAPIV3_1.OperationObject = path[method]\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 // Add list of UIDs to associate security schemes\n // As per the spec if there is operation level security we ignore the top level requirements\n if (operationSecurity?.length) {\n requestPayload.security = operationSecurity.map((s: OpenAPIV3_1.SecurityRequirementObject) => {\n const keys = Object.keys(s)\n\n // Handle the case of {} for optional\n if (keys.length) {\n const [key] = Object.keys(s)\n if (key) {\n return {\n [key]: s[key],\n }\n }\n }\n return s\n })\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\n/**\n * Retrieves a list of servers from an OpenAPI document and converts them to a list of Server entities.\n */\nexport function getServersFromOpenApiDocument(\n servers: OpenAPIV3_1.ServerObject[] | undefined,\n { baseServerURL }: Pick<ApiReferenceConfiguration, 'baseServerURL'> = {},\n): Server[] {\n if (!servers || !Array.isArray(servers)) {\n return []\n }\n\n return servers\n .map((server): Server | undefined => {\n try {\n // Validate the server against the schema\n const parsedSchema = serverSchema.parse(server)\n\n // Prepend with the base server URL (if the given URL is relative)\n if (parsedSchema?.url?.startsWith('/')) {\n // Use the base server URL (if provided)\n if (baseServerURL) {\n parsedSchema.url = combineUrlAndPath(baseServerURL, parsedSchema.url)\n\n return parsedSchema\n }\n\n // Fallback to the current window origin\n const fallbackUrl = getFallbackUrl()\n\n if (fallbackUrl) {\n parsedSchema.url = combineUrlAndPath(fallbackUrl, parsedSchema.url.replace(/^\\//, ''))\n\n return parsedSchema\n }\n }\n\n // Must be good, return it\n return parsedSchema\n } catch (error) {\n console.warn('Oops, that\u2019s an invalid server configuration.')\n console.warn('Server:', server)\n console.warn('Error:', error)\n\n // Return undefined to remove the server\n return undefined\n }\n })\n .filter(isDefined)\n}\n\n/**\n * Fallback to the current window.location.origin, if available\n */\nfunction getFallbackUrl() {\n if (typeof window === 'undefined') {\n return undefined\n }\n\n if (typeof window?.location?.origin !== 'string') {\n return undefined\n }\n\n return window.location.origin\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,cAAc;AACvB,SAA0B,aAAa,MAAM,eAAe;AAQ5D,SAAkD,wBAAwB;AAE1E,SAA8B,gCAAgC;AAC9D,SAA4C,qBAAqB;AACjE,SAAsB,oBAAoB;AAC1C,SAAmB,iBAAiB;AACpC,SAAS,oBAAoB;AAC7B,SAAS,iBAAiB;AAC1B,SAAS,yBAAyB;AAClC,SAA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AAQ,KAAK,UAAU,KAAK;AAG5B,aAAO;AAAA,IACT;AAAA,EACF,CAAC,EACA,OAAO,SAAS;AACrB;AAKA,SAAS,iBAAiB;AACxB,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU,WAAW,UAAU;AAChD,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,SAAS;AACzB;",
|
|
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.4.1",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -93,9 +93,9 @@
|
|
|
93
93
|
"type-fest": "^4.20.0",
|
|
94
94
|
"yaml": "^2.4.5",
|
|
95
95
|
"zod": "3.24.1",
|
|
96
|
-
"@scalar/object-utils": "1.2.1",
|
|
97
96
|
"@scalar/openapi-types": "0.3.1",
|
|
98
|
-
"@scalar/themes": "0.
|
|
97
|
+
"@scalar/themes": "0.13.1",
|
|
98
|
+
"@scalar/object-utils": "1.2.1",
|
|
99
99
|
"@scalar/types": "0.2.1"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"vite": "5.4.19",
|
|
105
105
|
"vitest": "^1.6.0",
|
|
106
106
|
"zod-to-ts": "github:amritk/zod-to-ts#build",
|
|
107
|
-
"@scalar/build-tooling": "0.2.
|
|
108
|
-
"@scalar/openapi-parser": "0.
|
|
107
|
+
"@scalar/build-tooling": "0.2.1",
|
|
108
|
+
"@scalar/openapi-parser": "0.13.0",
|
|
109
109
|
"@scalar/openapi-types": "0.3.1"
|
|
110
110
|
},
|
|
111
111
|
"scripts": {
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { operationSchema } from "./operation.js";
|
|
3
|
-
describe("operationSchema", () => {
|
|
4
|
-
describe("x-scalar-stability", () => {
|
|
5
|
-
it("parses deprecated", () => {
|
|
6
|
-
expect(
|
|
7
|
-
operationSchema.parse({
|
|
8
|
-
"x-scalar-stability": "deprecated"
|
|
9
|
-
})
|
|
10
|
-
).toMatchObject({
|
|
11
|
-
"x-scalar-stability": "deprecated"
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
it("parses experimental", () => {
|
|
15
|
-
expect(
|
|
16
|
-
operationSchema.parse({
|
|
17
|
-
"x-scalar-stability": "experimental"
|
|
18
|
-
})
|
|
19
|
-
).toMatchObject({
|
|
20
|
-
"x-scalar-stability": "experimental"
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
it("parses stable", () => {
|
|
24
|
-
expect(
|
|
25
|
-
operationSchema.parse({
|
|
26
|
-
"x-scalar-stability": "stable"
|
|
27
|
-
})
|
|
28
|
-
).toMatchObject({
|
|
29
|
-
"x-scalar-stability": "stable"
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
it("parses unknown", () => {
|
|
33
|
-
expect(
|
|
34
|
-
operationSchema.parse({
|
|
35
|
-
"x-scalar-stability": "unknown"
|
|
36
|
-
})
|
|
37
|
-
).toMatchObject({
|
|
38
|
-
"x-scalar-stability": void 0
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
//# sourceMappingURL=operation.test.js.map
|