@kubb/adapter-oas 5.0.0-beta.20 → 5.0.0-beta.21
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 +11 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/adapter.ts +1 -1
- package/src/discriminator.ts +3 -3
- package/src/parser.ts +7 -7
- package/src/stream.ts +3 -3
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.21",
|
|
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.21"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/swagger2openapi": "^7.0.4",
|
package/src/adapter.ts
CHANGED
|
@@ -136,7 +136,7 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
|
|
|
136
136
|
nameMapping,
|
|
137
137
|
resolve: (schemaName) => {
|
|
138
138
|
const result = resolve(schemaName)
|
|
139
|
-
if (!result) return
|
|
139
|
+
if (!result) return null
|
|
140
140
|
|
|
141
141
|
return ast.createImport({ name: [result.name], path: result.path })
|
|
142
142
|
},
|
package/src/discriminator.ts
CHANGED
|
@@ -44,8 +44,8 @@ export function buildDiscriminatorChildMap(schemas: ast.SchemaNode[]): Map<strin
|
|
|
44
44
|
const intersectionNode = ast.narrowSchema(member, 'intersection')
|
|
45
45
|
if (!intersectionNode?.members) continue
|
|
46
46
|
|
|
47
|
-
let refNode: SchemaNodeByType['ref'] |
|
|
48
|
-
let objNode: SchemaNodeByType['object'] |
|
|
47
|
+
let refNode: SchemaNodeByType['ref'] | null = null
|
|
48
|
+
let objNode: SchemaNodeByType['object'] | null = null
|
|
49
49
|
|
|
50
50
|
for (const m of intersectionNode.members) {
|
|
51
51
|
refNode ??= ast.narrowSchema(m, 'ref')
|
|
@@ -55,7 +55,7 @@ export function buildDiscriminatorChildMap(schemas: ast.SchemaNode[]): Map<strin
|
|
|
55
55
|
if (!refNode?.name || !objNode) continue
|
|
56
56
|
|
|
57
57
|
const prop = objNode.properties.find((p) => p.name === discriminatorPropertyName)
|
|
58
|
-
const enumNode = prop ? ast.narrowSchema(prop.schema, 'enum') :
|
|
58
|
+
const enumNode = prop ? ast.narrowSchema(prop.schema, 'enum') : null
|
|
59
59
|
if (!enumNode?.enumValues?.length) continue
|
|
60
60
|
|
|
61
61
|
const enumValues = enumNode.enumValues.filter((v): v is string | number | boolean => v !== null)
|
package/src/parser.ts
CHANGED
|
@@ -111,7 +111,7 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
111
111
|
* Memoizing by `$ref` path reduces the overall work from O(2^depth) to O(N)
|
|
112
112
|
* where N is the number of unique schema names.
|
|
113
113
|
*/
|
|
114
|
-
const resolvedRefCache = new Map<string, ast.SchemaNode |
|
|
114
|
+
const resolvedRefCache = new Map<string, ast.SchemaNode | null>()
|
|
115
115
|
|
|
116
116
|
/**
|
|
117
117
|
* Converts a `$ref` schema into a `RefSchemaNode`.
|
|
@@ -122,7 +122,7 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
122
122
|
* Circular refs are detected via `resolvingRefs` and leave `schema` as `undefined`.
|
|
123
123
|
*/
|
|
124
124
|
function convertRef({ schema, name, nullable, defaultValue, rawOptions }: SchemaContext): ast.SchemaNode {
|
|
125
|
-
let resolvedSchema: ast.SchemaNode |
|
|
125
|
+
let resolvedSchema: ast.SchemaNode | null = null
|
|
126
126
|
const refPath = schema.$ref
|
|
127
127
|
if (refPath && !resolvingRefs.has(refPath)) {
|
|
128
128
|
if (!resolvedRefCache.has(refPath)) {
|
|
@@ -138,7 +138,7 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
138
138
|
}
|
|
139
139
|
resolvedRefCache.set(refPath, resolvedSchema)
|
|
140
140
|
}
|
|
141
|
-
resolvedSchema = resolvedRefCache.get(refPath)
|
|
141
|
+
resolvedSchema = resolvedRefCache.get(refPath) ?? null
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
return ast.createSchema({
|
|
@@ -646,7 +646,7 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
646
646
|
*/
|
|
647
647
|
function convertArray({ schema, name, nullable, defaultValue, rawOptions, options }: SchemaContext): ast.SchemaNode {
|
|
648
648
|
const rawItems = schema.items as SchemaObject | undefined
|
|
649
|
-
const itemName = rawItems?.enum?.length && name ? ast.enumPropName(
|
|
649
|
+
const itemName = rawItems?.enum?.length && name ? ast.enumPropName(null, name, options.enumSuffix) : undefined
|
|
650
650
|
const items = rawItems ? [parseSchema({ schema: rawItems, name: itemName }, rawOptions)] : []
|
|
651
651
|
|
|
652
652
|
return ast.createSchema({
|
|
@@ -871,8 +871,8 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
871
871
|
* Collects property names whose schema has a truthy boolean flag (`readOnly` or `writeOnly`).
|
|
872
872
|
* `$ref` entries are skipped since their flags live on the dereferenced target.
|
|
873
873
|
*/
|
|
874
|
-
function collectPropertyKeysByFlag(schema: SchemaObject | null, flag: 'readOnly' | 'writeOnly'): string[] |
|
|
875
|
-
if (!schema?.properties) return
|
|
874
|
+
function collectPropertyKeysByFlag(schema: SchemaObject | null, flag: 'readOnly' | 'writeOnly'): string[] | null {
|
|
875
|
+
if (!schema?.properties) return null
|
|
876
876
|
|
|
877
877
|
const keys: string[] = []
|
|
878
878
|
for (const key in schema.properties) {
|
|
@@ -881,7 +881,7 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
881
881
|
keys.push(key)
|
|
882
882
|
}
|
|
883
883
|
}
|
|
884
|
-
return keys.length ? keys :
|
|
884
|
+
return keys.length ? keys : null
|
|
885
885
|
}
|
|
886
886
|
|
|
887
887
|
/**
|
package/src/stream.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type PreScanResult = {
|
|
|
17
17
|
* Reads the server URL from the document's `servers` array at `serverIndex`,
|
|
18
18
|
* interpolating any `serverVariables` into the URL template.
|
|
19
19
|
*
|
|
20
|
-
* Returns `
|
|
20
|
+
* Returns `null` when `serverIndex` is omitted or out of range.
|
|
21
21
|
*
|
|
22
22
|
* @example Resolve the first server
|
|
23
23
|
* `resolveBaseUrl({ document, serverIndex: 0 })`
|
|
@@ -33,9 +33,9 @@ export function resolveBaseUrl({
|
|
|
33
33
|
document: Document
|
|
34
34
|
serverIndex?: number
|
|
35
35
|
serverVariables?: Record<string, string>
|
|
36
|
-
}): string |
|
|
36
|
+
}): string | null {
|
|
37
37
|
const server = serverIndex !== undefined ? document.servers?.at(serverIndex) : undefined
|
|
38
|
-
return server?.url ? resolveServerUrl(server, serverVariables) :
|
|
38
|
+
return server?.url ? resolveServerUrl(server, serverVariables) : null
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|