@scalar/oas-utils 0.2.17 → 0.2.19
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 +13 -0
- package/dist/entities/workspace/collection/collection.d.ts +4 -22
- package/dist/entities/workspace/collection/collection.d.ts.map +1 -1
- package/dist/entities/workspace/collection/collection.js +2 -18
- package/dist/entities/workspace/security/index.js +1 -1
- package/dist/entities/workspace/security/security-schemes.d.ts +555 -544
- package/dist/entities/workspace/security/security-schemes.d.ts.map +1 -1
- package/dist/entities/workspace/security/security-schemes.js +65 -81
- package/dist/entities/workspace/server/server.d.ts +5 -5
- package/dist/entities/workspace/spec/request-examples.d.ts +40 -40
- package/dist/entities/workspace/spec/requests.d.ts +11 -3
- package/dist/entities/workspace/spec/requests.d.ts.map +1 -1
- package/dist/entities/workspace/spec/requests.js +4 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/isValidUrl.d.ts +12 -0
- package/dist/helpers/isValidUrl.d.ts.map +1 -0
- package/dist/helpers/isValidUrl.js +20 -0
- package/dist/transforms/import-spec.d.ts +2 -5
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +3 -17
- package/package.json +1 -1
|
@@ -4,9 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
import type { RequestExample } from './request-examples.js';
|
|
5
5
|
/** A single set of populated values for a sent request */
|
|
6
6
|
export type ResponseInstance = AxiosResponse & {
|
|
7
|
-
/**
|
|
8
|
-
* Time in ms the request took
|
|
9
|
-
*/
|
|
7
|
+
/** Time in ms the request took */
|
|
10
8
|
duration: number;
|
|
11
9
|
};
|
|
12
10
|
/** A single request/response set to save to the history stack */
|
|
@@ -71,6 +69,10 @@ declare const requestSchema: z.ZodObject<{
|
|
|
71
69
|
* security requirement ({}) can be included in the array.
|
|
72
70
|
*/
|
|
73
71
|
security: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>>, "many">>;
|
|
72
|
+
/** Security schemes which have been created specifically for this request */
|
|
73
|
+
securitySchemeUids: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodDefault<z.ZodOptional<z.ZodString>>, "many">>>;
|
|
74
|
+
/** The currently selected security schemes at the request level */
|
|
75
|
+
selectedSecuritySchemeUids: z.ZodDefault<z.ZodArray<z.ZodDefault<z.ZodOptional<z.ZodString>>, "many">>;
|
|
74
76
|
/**
|
|
75
77
|
* The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the
|
|
76
78
|
* HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the
|
|
@@ -98,6 +100,8 @@ declare const requestSchema: z.ZodObject<{
|
|
|
98
100
|
isExternal: boolean;
|
|
99
101
|
collectionRef?: string | undefined;
|
|
100
102
|
} | null;
|
|
103
|
+
securitySchemeUids: string[];
|
|
104
|
+
selectedSecuritySchemeUids: string[];
|
|
101
105
|
history: any[];
|
|
102
106
|
description?: string | undefined;
|
|
103
107
|
summary?: string | undefined;
|
|
@@ -125,6 +129,8 @@ declare const requestSchema: z.ZodObject<{
|
|
|
125
129
|
collectionRef?: string | undefined;
|
|
126
130
|
} | null | undefined;
|
|
127
131
|
operationId?: string | undefined;
|
|
132
|
+
securitySchemeUids?: (string | undefined)[] | undefined;
|
|
133
|
+
selectedSecuritySchemeUids?: (string | undefined)[] | undefined;
|
|
128
134
|
requestBody?: any;
|
|
129
135
|
history?: any[] | undefined;
|
|
130
136
|
}>;
|
|
@@ -157,6 +163,8 @@ export declare const createRequest: (payload: RequestPayload) => {
|
|
|
157
163
|
isExternal: boolean;
|
|
158
164
|
collectionRef?: string | undefined;
|
|
159
165
|
} | null;
|
|
166
|
+
securitySchemeUids: string[];
|
|
167
|
+
selectedSecuritySchemeUids: string[];
|
|
160
168
|
history: any[];
|
|
161
169
|
description?: string | undefined;
|
|
162
170
|
summary?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../../src/entities/workspace/spec/requests.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAkB,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C
|
|
1
|
+
{"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../../src/entities/workspace/spec/requests.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAkB,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG;IAC7C,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,cAAc,CAAA;IACvB,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAQD,QAAA,MAAM,aAAa;;;;;;;;;;;;;;;;;IAQjB;;;OAGG;;IAEH,kDAAkD;;IAElD,mHAAmH;;IAEnH;;;;OAIG;;;;;;;;;;;;;;;;;;IAUH;;;;;;OAMG;;IAEH,6EAA6E;;IAE7E,mEAAmE;;IAEnE;;;;;OAKG;;IAEH,0CAA0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1C,CAAA;AAEF;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAAG;IACpD,YAAY,CAAC,EAAE,WAAW,CAAC,2BAA2B,CAAA;CACvD,CAAA;AACD,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAAG;IAC3D,YAAY,CAAC,EAAE,WAAW,CAAC,2BAA2B,CAAA;CACvD,CAAA;AAED,4BAA4B;AAC5B,eAAO,MAAM,aAAa,YAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;CACR,CAAA"}
|
|
@@ -46,6 +46,10 @@ const requestSchema = z.object({
|
|
|
46
46
|
* security requirement ({}) can be included in the array.
|
|
47
47
|
*/
|
|
48
48
|
security: z.array(securityRequirement).optional(),
|
|
49
|
+
/** Security schemes which have been created specifically for this request */
|
|
50
|
+
securitySchemeUids: z.array(nanoidSchema).optional().default([]),
|
|
51
|
+
/** The currently selected security schemes at the request level */
|
|
52
|
+
selectedSecuritySchemeUids: z.array(nanoidSchema).default([]),
|
|
49
53
|
/**
|
|
50
54
|
* The request body applicable for this operation. The requestBody is fully supported in HTTP methods where the
|
|
51
55
|
* HTTP 1.1 specification [RFC7231] has explicitly defined semantics for request bodies. In other cases where the
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AACvC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,2BAA2B,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA"}
|
package/dist/helpers/index.js
CHANGED
|
@@ -16,3 +16,4 @@ export { replaceVariables } from './replaceVariables.js';
|
|
|
16
16
|
export { schemaModel } from './schema-model.js';
|
|
17
17
|
export { defaultStateFactory, ssrState } from './ssrState.js';
|
|
18
18
|
export { camelToTitleWords, capitalize } from './string.js';
|
|
19
|
+
export { isValidUrl } from './isValidUrl.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string is a valid URL.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url - The string to be validated as a URL.
|
|
5
|
+
* @returns {boolean} Returns true if the string is a valid URL, false otherwise.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isValidUrl('https://www.example.com'); // returns true
|
|
9
|
+
* isValidUrl('not a url'); // returns false
|
|
10
|
+
*/
|
|
11
|
+
export declare function isValidUrl(url: string): boolean;
|
|
12
|
+
//# sourceMappingURL=isValidUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isValidUrl.d.ts","sourceRoot":"","sources":["../../src/helpers/isValidUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,WAMrC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string is a valid URL.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url - The string to be validated as a URL.
|
|
5
|
+
* @returns {boolean} Returns true if the string is a valid URL, false otherwise.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* isValidUrl('https://www.example.com'); // returns true
|
|
9
|
+
* isValidUrl('not a url'); // returns false
|
|
10
|
+
*/
|
|
11
|
+
function isValidUrl(url) {
|
|
12
|
+
try {
|
|
13
|
+
return Boolean(new URL(url));
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { isValidUrl };
|
|
@@ -17,8 +17,8 @@ export declare const importSpecToWorkspace: (spec: string | AnyObject) => Promis
|
|
|
17
17
|
url: string;
|
|
18
18
|
description?: string | undefined;
|
|
19
19
|
variables?: Record<string, {
|
|
20
|
-
default: string;
|
|
21
20
|
uid: string;
|
|
21
|
+
default: string;
|
|
22
22
|
value?: string | undefined;
|
|
23
23
|
description?: string | undefined;
|
|
24
24
|
enum?: string[] | undefined;
|
|
@@ -61,10 +61,7 @@ export declare const importSpecToWorkspace: (spec: string | AnyObject) => Promis
|
|
|
61
61
|
} | undefined;
|
|
62
62
|
} | undefined;
|
|
63
63
|
};
|
|
64
|
-
|
|
65
|
-
uid: string;
|
|
66
|
-
flowKey?: "implicit" | "password" | "clientCredentials" | "authorizationCode" | undefined;
|
|
67
|
-
}[];
|
|
64
|
+
securitySchemeDict: Record<string, string>;
|
|
68
65
|
selectedServerUid: string;
|
|
69
66
|
childUids: string[];
|
|
70
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,2BAA2B,CAAA;AAIvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAWxC,uEAAuE;AACvE,eAAO,MAAM,qBAAqB,SAAgB,MAAM,GAAG,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmKnE,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { tagObjectSchema } from '../entities/workspace/spec/spec.js';
|
|
2
|
-
import { parseJsonOrYaml } from '../helpers/parse.js';
|
|
3
2
|
import { schemaModel } from '../helpers/schema-model.js';
|
|
4
3
|
import { load, dereference } from '@scalar/openapi-parser';
|
|
5
4
|
import { createRequest } from '../entities/workspace/spec/requests.js';
|
|
@@ -17,10 +16,9 @@ const PARAM_DICTIONARY = {
|
|
|
17
16
|
const importSpecToWorkspace = async (spec) => {
|
|
18
17
|
const importWarnings = [];
|
|
19
18
|
const requests = [];
|
|
20
|
-
const parsedSpec = parseJsonOrYaml(spec);
|
|
21
19
|
// TODO: `parsedSpec` can have circular reference and will break.
|
|
22
20
|
// We always have to use the original document.
|
|
23
|
-
const { filesystem } = await load(
|
|
21
|
+
const { filesystem } = await load(spec);
|
|
24
22
|
const { schema, errors } = await dereference(filesystem);
|
|
25
23
|
if (errors?.length || !schema) {
|
|
26
24
|
console.warn('Please open an issue on https://github.com/scalar/scalar\n', 'Scalar OpenAPI Parser Warning:\n', errors);
|
|
@@ -110,8 +108,8 @@ const importSpecToWorkspace = async (spec) => {
|
|
|
110
108
|
folders.push(folder);
|
|
111
109
|
});
|
|
112
110
|
// Toss in a default server if there aren't any
|
|
113
|
-
const unparsedServers =
|
|
114
|
-
?
|
|
111
|
+
const unparsedServers = schema?.servers?.length
|
|
112
|
+
? schema.servers
|
|
115
113
|
: [
|
|
116
114
|
{
|
|
117
115
|
url: typeof window !== 'undefined'
|
|
@@ -121,17 +119,6 @@ const importSpecToWorkspace = async (spec) => {
|
|
|
121
119
|
},
|
|
122
120
|
];
|
|
123
121
|
const servers = unparsedServers.map((server) => createServer(server));
|
|
124
|
-
// Select initial security
|
|
125
|
-
const firstSecurityKey = Object.keys((schema?.components?.securitySchemes || schema?.securityDefinitions) ?? {})?.[0];
|
|
126
|
-
const firstScheme = (schema?.components?.securitySchemes ||
|
|
127
|
-
schema?.securityDefinitions)?.[firstSecurityKey ?? ''];
|
|
128
|
-
// In the case of oauth2 we need to select the flow as well
|
|
129
|
-
const flowKey = firstScheme?.type === 'oauth2'
|
|
130
|
-
? Object.keys(firstScheme.flows ?? {})[0]
|
|
131
|
-
: undefined;
|
|
132
|
-
const selectedSecuritySchemes = firstSecurityKey
|
|
133
|
-
? [{ uid: firstSecurityKey, ...(flowKey ? { flowKey } : {}) }]
|
|
134
|
-
: [];
|
|
135
122
|
const collection = createCollection({
|
|
136
123
|
spec: {
|
|
137
124
|
openapi: schema?.openapi,
|
|
@@ -141,7 +128,6 @@ const importSpecToWorkspace = async (spec) => {
|
|
|
141
128
|
serverUids: servers.map(({ uid }) => uid),
|
|
142
129
|
tags,
|
|
143
130
|
},
|
|
144
|
-
selectedSecuritySchemes,
|
|
145
131
|
selectedServerUid: servers[0].uid,
|
|
146
132
|
// We default to having all the requests in the root folder
|
|
147
133
|
childUids: folders.map(({ uid }) => uid),
|