@scalar/oas-utils 0.2.72 → 0.2.74
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 +15 -0
- package/dist/helpers/makeUrlAbsolute.d.ts +1 -1
- package/dist/helpers/makeUrlAbsolute.d.ts.map +1 -1
- package/dist/helpers/makeUrlAbsolute.js +4 -5
- package/dist/transforms/import-spec.d.ts +10 -5
- package/dist/transforms/import-spec.d.ts.map +1 -1
- package/dist/transforms/import-spec.js +20 -5
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @scalar/oas-utils
|
|
2
2
|
|
|
3
|
+
## 0.2.74
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ac55d0f: chore: add time logging for the workspace store
|
|
8
|
+
- Updated dependencies [0c07766]
|
|
9
|
+
- @scalar/themes@0.9.48
|
|
10
|
+
|
|
11
|
+
## 0.2.73
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 82f7c35: fix: rollback proxy
|
|
16
|
+
- 3421489: fix: remove examples from request payload before parsing
|
|
17
|
+
|
|
3
18
|
## 0.2.72
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pass an URL or a relative URL and get an absolute URL
|
|
3
3
|
*/
|
|
4
|
-
export declare const makeUrlAbsolute: (url?: string
|
|
4
|
+
export declare const makeUrlAbsolute: (url?: string) => string | undefined;
|
|
5
5
|
//# sourceMappingURL=makeUrlAbsolute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeUrlAbsolute.d.ts","sourceRoot":"","sources":["../../src/helpers/makeUrlAbsolute.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,SAAU,MAAM,
|
|
1
|
+
{"version":3,"file":"makeUrlAbsolute.d.ts","sourceRoot":"","sources":["../../src/helpers/makeUrlAbsolute.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,SAAU,MAAM,uBAqB3C,CAAA"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pass an URL or a relative URL and get an absolute URL
|
|
3
3
|
*/
|
|
4
|
-
const makeUrlAbsolute = (url
|
|
4
|
+
const makeUrlAbsolute = (url) => {
|
|
5
5
|
if (!url ||
|
|
6
6
|
url.startsWith('http://') ||
|
|
7
7
|
url.startsWith('https://') ||
|
|
8
|
-
|
|
8
|
+
typeof window === 'undefined')
|
|
9
9
|
return url;
|
|
10
|
-
|
|
11
|
-
const base = baseUrl || window.location.href;
|
|
10
|
+
const baseUrl = window.location.href;
|
|
12
11
|
// Remove any query parameters or hash from the base URL
|
|
13
|
-
const cleanBaseUrl =
|
|
12
|
+
const cleanBaseUrl = baseUrl.split('?')[0]?.split('#')[0];
|
|
14
13
|
// For base URLs with a path component, we want to remove the last path segment
|
|
15
14
|
// if it doesn't end with a slash
|
|
16
15
|
const normalizedBaseUrl = cleanBaseUrl?.endsWith('/')
|
|
@@ -15,12 +15,17 @@ export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' |
|
|
|
15
15
|
setCollectionSecurity?: boolean;
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* The imported entities maintain a close mapping to the original OpenAPI specification to enable:
|
|
21
|
+
* - Bi-directional translation between spec and workspace entities
|
|
22
|
+
* - Preservation of specification details and structure
|
|
23
|
+
* - Accurate representation of relationships between components
|
|
24
|
+
*
|
|
25
|
+
* Relationships between entities are maintained through unique identifiers (UIDs) which allow:
|
|
26
|
+
* - Flexible organization at different levels (workspace, collection, request)
|
|
27
|
+
* - Proper linking between related components
|
|
28
|
+
* - Easy lookup and reference of dependent entities
|
|
24
29
|
*/
|
|
25
30
|
export declare function importSpecToWorkspace(spec: string | UnknownObject, { authentication, baseServerURL, documentUrl, servers: overloadServers, setCollectionSecurity, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{
|
|
26
31
|
error: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAOT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,0BAA0B,EAIhC,MAAM,0BAA0B,CAAA;AAIjC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAwDxD,2DAA2D;AAC3D,eAAO,MAAM,iBAAiB,WACpB,cAAc,SACf,sBAAsB,CAAC,gBAAgB,CAAC,KAC9C,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,0BAA0B,CAgC5D,CAAA;AAED,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAAgB,MAAM,GAAG,aAAa;
|
|
1
|
+
{"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,cAAc,EAGnB,KAAK,MAAM,EACX,KAAK,GAAG,EAOT,MAAM,iBA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MAAM,EAAE,CAAA;IACjB,IAAI,EAAE,GAAG,EAAE,CAAA;IACX,eAAe,EAAE,cAAc,EAAE,CAAA;CAClC,GACD;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,cAAc,EAAE,MAAM,EAAE,CAAA;CAAE,CAC5C,CA8SA"}
|
|
@@ -86,18 +86,25 @@ const getBaseAuthValues = (scheme, auth) => {
|
|
|
86
86
|
};
|
|
87
87
|
/** Takes a string or object and parses it into an openapi spec compliant schema */
|
|
88
88
|
const parseSchema = async (spec) => {
|
|
89
|
+
// TODO: Plugins for URLs and files with the proxy is missing here.
|
|
90
|
+
// @see packages/api-reference/src/helpers/parse.ts
|
|
89
91
|
const { filesystem } = await load(spec);
|
|
90
92
|
const { specification } = upgrade(filesystem);
|
|
91
93
|
const { schema, errors = [] } = await dereference(specification);
|
|
92
94
|
return { schema: schema, errors };
|
|
93
95
|
};
|
|
94
96
|
/**
|
|
95
|
-
*
|
|
97
|
+
* Imports an OpenAPI document and converts it to workspace entities (Collection, Request, Server, etc.)
|
|
96
98
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
99
|
+
* The imported entities maintain a close mapping to the original OpenAPI specification to enable:
|
|
100
|
+
* - Bi-directional translation between spec and workspace entities
|
|
101
|
+
* - Preservation of specification details and structure
|
|
102
|
+
* - Accurate representation of relationships between components
|
|
103
|
+
*
|
|
104
|
+
* Relationships between entities are maintained through unique identifiers (UIDs) which allow:
|
|
105
|
+
* - Flexible organization at different levels (workspace, collection, request)
|
|
106
|
+
* - Proper linking between related components
|
|
107
|
+
* - Easy lookup and reference of dependent entities
|
|
101
108
|
*/
|
|
102
109
|
async function importSpecToWorkspace(spec, { authentication, baseServerURL, documentUrl, servers: overloadServers, setCollectionSecurity = false, watchMode = false, } = {}) {
|
|
103
110
|
const { schema, errors } = await parseSchema(spec);
|
|
@@ -106,6 +113,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
106
113
|
return { importWarnings, error: true };
|
|
107
114
|
// ---------------------------------------------------------------------------
|
|
108
115
|
// Some entities will be broken out as individual lists for modification in the workspace
|
|
116
|
+
const start = performance.now();
|
|
109
117
|
const requests = [];
|
|
110
118
|
// Grab the base server URL for relative servers
|
|
111
119
|
const backupBaseServerUrl = typeof window !== 'undefined' ? window.location.origin : 'http://localhost';
|
|
@@ -213,6 +221,11 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
213
221
|
],
|
|
214
222
|
servers: [...pathServers, ...operationServers].map((s) => s.uid),
|
|
215
223
|
};
|
|
224
|
+
// Remove any examples from the request payload as they conflict with our examples property and are not valid
|
|
225
|
+
if (requestPayload.examples) {
|
|
226
|
+
console.warn('[@scalar/api-client] operation.examples is not a valid openapi property');
|
|
227
|
+
delete requestPayload.examples;
|
|
228
|
+
}
|
|
216
229
|
// Add list of UIDs to associate security schemes
|
|
217
230
|
// As per the spec if there is operation level security we ignore the top level requirements
|
|
218
231
|
if (operationSecurity?.length)
|
|
@@ -319,6 +332,8 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
|
|
|
319
332
|
},
|
|
320
333
|
securitySchemes: securitySchemes.map((s) => s.uid),
|
|
321
334
|
});
|
|
335
|
+
const end = performance.now();
|
|
336
|
+
console.log(`workspace: ${Math.round(end - start)} ms`);
|
|
322
337
|
/**
|
|
323
338
|
* Servers and requests will be saved in top level maps and indexed via UID to
|
|
324
339
|
* maintain specification relationships
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"specification",
|
|
17
17
|
"yaml"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.2.
|
|
19
|
+
"version": "0.2.74",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=18"
|
|
22
22
|
},
|
|
@@ -107,17 +107,17 @@
|
|
|
107
107
|
"yaml": "^2.4.5",
|
|
108
108
|
"zod": "^3.23.8",
|
|
109
109
|
"@scalar/object-utils": "1.1.12",
|
|
110
|
-
"@scalar/
|
|
111
|
-
"@scalar/
|
|
112
|
-
"@scalar/
|
|
110
|
+
"@scalar/openapi-types": "0.1.5",
|
|
111
|
+
"@scalar/themes": "0.9.48",
|
|
112
|
+
"@scalar/types": "0.0.19"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
115
|
"type-fest": "^4.20.0",
|
|
116
116
|
"vite": "^5.4.9",
|
|
117
117
|
"vitest": "^1.6.0",
|
|
118
118
|
"zod-to-ts": "^1.2.0",
|
|
119
|
-
"@scalar/build-tooling": "0.1.12",
|
|
120
119
|
"@scalar/openapi-parser": "0.8.9",
|
|
120
|
+
"@scalar/build-tooling": "0.1.12",
|
|
121
121
|
"@scalar/openapi-types": "0.1.5"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|