@scalar/oas-utils 0.2.17 → 0.2.18
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 +7 -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.map +1 -1
- package/dist/transforms/import-spec.js +3 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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 };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAIA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0LnE,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'
|