@kubb/adapter-oas 5.0.0-beta.7 → 5.0.0-beta.8
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/dist/index.cjs +10 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/factory.ts +1 -4
- package/src/refs.ts +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/adapter-oas",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.8",
|
|
4
4
|
"description": "OpenAPI and Swagger adapter for Kubb. Parses and validates OAS 2.0/3.x specifications into a @kubb/ast RootNode for downstream code generation plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"oas": "^32.1.18",
|
|
48
48
|
"oas-normalize": "^16.0.4",
|
|
49
49
|
"swagger2openapi": "^7.0.8",
|
|
50
|
-
"@kubb/core": "5.0.0-beta.
|
|
50
|
+
"@kubb/core": "5.0.0-beta.8"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/swagger2openapi": "^7.0.4",
|
package/src/factory.ts
CHANGED
|
@@ -74,10 +74,7 @@ export async function parseDocument(pathOrApi: string | Document, { canBundle =
|
|
|
74
74
|
* ```
|
|
75
75
|
*/
|
|
76
76
|
export async function mergeDocuments(pathOrApi: Array<string | Document>): Promise<Document> {
|
|
77
|
-
const documents:
|
|
78
|
-
for (const p of pathOrApi) {
|
|
79
|
-
documents.push(await parseDocument(p, { enablePaths: false, canBundle: false }))
|
|
80
|
-
}
|
|
77
|
+
const documents = await Promise.all(pathOrApi.map((p) => parseDocument(p, { enablePaths: false, canBundle: false })))
|
|
81
78
|
|
|
82
79
|
if (documents.length === 0) {
|
|
83
80
|
throw new Error('No OAS documents provided for merging.')
|
package/src/refs.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { isReference } from './guards.ts'
|
|
2
2
|
import type { Document } from './types.ts'
|
|
3
3
|
|
|
4
|
+
const _refCache = new WeakMap<Document, Map<string, unknown>>()
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* Resolves a local JSON pointer reference from a document.
|
|
6
8
|
*
|
|
@@ -23,6 +25,17 @@ export function resolveRef<T = unknown>(document: Document, $ref: string): T | n
|
|
|
23
25
|
} else {
|
|
24
26
|
return null
|
|
25
27
|
}
|
|
28
|
+
|
|
29
|
+
let docCache = _refCache.get(document)
|
|
30
|
+
if (!docCache) {
|
|
31
|
+
docCache = new Map()
|
|
32
|
+
_refCache.set(document, docCache)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (docCache.has($ref)) {
|
|
36
|
+
return docCache.get($ref) as T
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
const current = $ref
|
|
27
40
|
.split('/')
|
|
28
41
|
.filter(Boolean)
|
|
@@ -31,6 +44,8 @@ export function resolveRef<T = unknown>(document: Document, $ref: string): T | n
|
|
|
31
44
|
if (!current) {
|
|
32
45
|
throw new Error(`Could not find a definition for ${origRef}.`)
|
|
33
46
|
}
|
|
47
|
+
|
|
48
|
+
docCache.set($ref, current)
|
|
34
49
|
return current as T
|
|
35
50
|
}
|
|
36
51
|
|