@kubb/adapter-oas 5.0.0-beta.13 → 5.0.0-beta.15
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 +9 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/parser.ts +3 -3
- package/src/resolvers.ts +6 -8
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.15",
|
|
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",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"registry": "https://registry.npmjs.org/"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@redocly/openapi-core": "^2.30.
|
|
46
|
+
"@redocly/openapi-core": "^2.30.5",
|
|
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.15"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/swagger2openapi": "^7.0.4",
|
package/src/parser.ts
CHANGED
|
@@ -98,7 +98,7 @@ function createSchemaParser(ctx: OasParserContext) {
|
|
|
98
98
|
* blowup — `customer` alone may be referenced from dozens of top-level schemas,
|
|
99
99
|
* each triggering a fresh recursive expansion of its entire sub-tree.
|
|
100
100
|
*
|
|
101
|
-
*
|
|
101
|
+
* Memoizing by `$ref` path reduces the overall work from O(2^depth) to O(N)
|
|
102
102
|
* where N is the number of unique schema names.
|
|
103
103
|
*/
|
|
104
104
|
const resolvedRefCache = new Map<string, ast.SchemaNode | undefined>()
|
|
@@ -245,7 +245,7 @@ function createSchemaParser(ctx: OasParserContext) {
|
|
|
245
245
|
|
|
246
246
|
return ast.createSchema({
|
|
247
247
|
type: 'intersection',
|
|
248
|
-
members: [...ast.
|
|
248
|
+
members: [...ast.mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...ast.mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))],
|
|
249
249
|
...buildSchemaNode(schema, name, nullable, defaultValue),
|
|
250
250
|
})
|
|
251
251
|
}
|
|
@@ -1009,7 +1009,7 @@ export function parseOas(
|
|
|
1009
1009
|
const baseOas = new BaseOas(document)
|
|
1010
1010
|
const paths = baseOas.getPaths()
|
|
1011
1011
|
|
|
1012
|
-
const operations: Array<ast.OperationNode> = Object.entries(paths).flatMap(([
|
|
1012
|
+
const operations: Array<ast.OperationNode> = Object.entries(paths).flatMap(([, methods]) =>
|
|
1013
1013
|
Object.entries(methods)
|
|
1014
1014
|
.map(([, operation]) => (operation ? _parseOperation(mergedOptions, operation) : null))
|
|
1015
1015
|
.filter((op): op is ast.OperationNode => op !== null),
|
package/src/resolvers.ts
CHANGED
|
@@ -305,10 +305,10 @@ export function extractSchemaFromContent(content: Record<string, unknown> | unde
|
|
|
305
305
|
/**
|
|
306
306
|
* Walks a schema tree and collects the names of all `#/components/schemas/<name>` `$ref`s.
|
|
307
307
|
*/
|
|
308
|
-
function collectRefs(schema: unknown
|
|
308
|
+
function* collectRefs(schema: unknown): Generator<string, void, undefined> {
|
|
309
309
|
if (Array.isArray(schema)) {
|
|
310
|
-
for (const item of schema) collectRefs(item
|
|
311
|
-
return
|
|
310
|
+
for (const item of schema) yield* collectRefs(item)
|
|
311
|
+
return
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
if (schema && typeof schema === 'object') {
|
|
@@ -317,15 +317,13 @@ function collectRefs(schema: unknown, refs = new Set<string>()): Set<string> {
|
|
|
317
317
|
if (key === '$ref' && typeof value === 'string') {
|
|
318
318
|
if (value.startsWith(SCHEMA_REF_PREFIX)) {
|
|
319
319
|
const name = value.slice(SCHEMA_REF_PREFIX.length)
|
|
320
|
-
if (name)
|
|
320
|
+
if (name) yield name
|
|
321
321
|
}
|
|
322
322
|
} else {
|
|
323
|
-
collectRefs(value
|
|
323
|
+
yield* collectRefs(value)
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
}
|
|
327
|
-
|
|
328
|
-
return refs
|
|
329
327
|
}
|
|
330
328
|
|
|
331
329
|
/**
|
|
@@ -344,7 +342,7 @@ export function sortSchemas(schemas: Record<string, SchemaObject>): Record<strin
|
|
|
344
342
|
const deps = new Map<string, string[]>()
|
|
345
343
|
|
|
346
344
|
for (const [name, schema] of Object.entries(schemas)) {
|
|
347
|
-
deps.set(name,
|
|
345
|
+
deps.set(name, [...new Set(collectRefs(schema))])
|
|
348
346
|
}
|
|
349
347
|
|
|
350
348
|
const sorted: string[] = []
|