@kubb/adapter-oas 5.0.0-beta.25 → 5.0.0-beta.26
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.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter.ts +2 -2
- package/src/discriminator.ts +1 -1
- package/src/parser.ts +3 -3
- package/src/resolvers.ts +8 -8
- package/src/stream.ts +5 -5
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.26",
|
|
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.
|
|
46
|
+
"@redocly/openapi-core": "^2.31.2",
|
|
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.26"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/swagger2openapi": "^7.0.4",
|
package/src/adapter.ts
CHANGED
|
@@ -153,8 +153,8 @@ export const adapterOas = createAdapter<AdapterOas>((options) => {
|
|
|
153
153
|
async parse(source) {
|
|
154
154
|
const streamNode = await createStream(source)
|
|
155
155
|
|
|
156
|
-
const collect = async <T>(iter: AsyncIterable<T>): Promise<T
|
|
157
|
-
const out: T
|
|
156
|
+
const collect = async <T>(iter: AsyncIterable<T>): Promise<Array<T>> => {
|
|
157
|
+
const out: Array<T> = []
|
|
158
158
|
for await (const item of iter) out.push(item)
|
|
159
159
|
return out
|
|
160
160
|
}
|
package/src/discriminator.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type DiscriminatorTarget = {
|
|
|
14
14
|
* small pre-parsed subset of schemas (only the discriminator parents) rather than on all
|
|
15
15
|
* schemas at once.
|
|
16
16
|
*/
|
|
17
|
-
export function buildDiscriminatorChildMap(schemas: ast.SchemaNode
|
|
17
|
+
export function buildDiscriminatorChildMap(schemas: Array<ast.SchemaNode>): Map<string, DiscriminatorTarget> {
|
|
18
18
|
const childMap = new Map<string, DiscriminatorTarget>()
|
|
19
19
|
|
|
20
20
|
for (const schema of schemas) {
|
package/src/parser.ts
CHANGED
|
@@ -770,7 +770,7 @@ export function createSchemaParser(ctx: OasParserContext) {
|
|
|
770
770
|
}
|
|
771
771
|
|
|
772
772
|
if (Array.isArray(schema.type) && schema.type.length > 1) {
|
|
773
|
-
const nonNullTypes = schema.type.filter((t) => t !== 'null') as string
|
|
773
|
+
const nonNullTypes = schema.type.filter((t) => t !== 'null') as Array<string>
|
|
774
774
|
const arrayNullable = schema.type.includes('null') || nullable || undefined
|
|
775
775
|
|
|
776
776
|
if (nonNullTypes.length > 1) {
|
|
@@ -871,10 +871,10 @@ 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
|
|
874
|
+
function collectPropertyKeysByFlag(schema: SchemaObject | null, flag: 'readOnly' | 'writeOnly'): Array<string> | null {
|
|
875
875
|
if (!schema?.properties) return null
|
|
876
876
|
|
|
877
|
-
const keys: string
|
|
877
|
+
const keys: Array<string> = []
|
|
878
878
|
for (const key in schema.properties) {
|
|
879
879
|
const prop = schema.properties[key]
|
|
880
880
|
if (prop && !isReference(prop) && (prop as Record<string, unknown>)[flag]) {
|
package/src/resolvers.ts
CHANGED
|
@@ -86,7 +86,7 @@ export type OperationsOptions = {
|
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
88
|
export function getParameters(document: Document, operation: Operation): Array<ParameterObject> {
|
|
89
|
-
const resolveParams = (params: unknown
|
|
89
|
+
const resolveParams = (params: Array<unknown>): Array<ParameterObject> =>
|
|
90
90
|
params.map((p) => dereferenceWithRef(document, p)).filter((p): p is ParameterObject => !!p && typeof p === 'object' && 'in' in p && 'name' in p)
|
|
91
91
|
|
|
92
92
|
const operationParams = resolveParams(operation.schema?.parameters || [])
|
|
@@ -108,7 +108,7 @@ export function getParameters(document: Document, operation: Operation): Array<P
|
|
|
108
108
|
return Array.from(paramMap.values())
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
function getResponseBody(responseBody: boolean | ResponseObject, contentType?: string): MediaTypeObject | false | [string, MediaTypeObject, ...string
|
|
111
|
+
function getResponseBody(responseBody: boolean | ResponseObject, contentType?: string): MediaTypeObject | false | [string, MediaTypeObject, ...Array<string>] {
|
|
112
112
|
if (!responseBody) return false
|
|
113
113
|
if (isReference(responseBody)) return false
|
|
114
114
|
|
|
@@ -260,7 +260,7 @@ function hasStructuralKeywords(fragment: SchemaObject): boolean {
|
|
|
260
260
|
export function flattenSchema(schema: SchemaObject | null): SchemaObject | null {
|
|
261
261
|
if (!schema?.allOf || schema.allOf.length === 0) return schema ?? null
|
|
262
262
|
|
|
263
|
-
const allOfFragments = schema.allOf as SchemaObject
|
|
263
|
+
const allOfFragments = schema.allOf as Array<SchemaObject>
|
|
264
264
|
if (allOfFragments.some((item) => isRef(item))) return schema
|
|
265
265
|
if (allOfFragments.some(hasStructuralKeywords)) return schema
|
|
266
266
|
|
|
@@ -339,13 +339,13 @@ function* collectRefs(schema: unknown): Generator<string, void, undefined> {
|
|
|
339
339
|
* ```
|
|
340
340
|
*/
|
|
341
341
|
export function sortSchemas(schemas: Record<string, SchemaObject>): Record<string, SchemaObject> {
|
|
342
|
-
const deps = new Map<string, string
|
|
342
|
+
const deps = new Map<string, Array<string>>()
|
|
343
343
|
|
|
344
344
|
for (const [name, schema] of Object.entries(schemas)) {
|
|
345
345
|
deps.set(name, [...new Set(collectRefs(schema))])
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
const sorted: string
|
|
348
|
+
const sorted: Array<string> = []
|
|
349
349
|
const visited = new Set<string>()
|
|
350
350
|
|
|
351
351
|
function visit(name: string, stack: Set<string>) {
|
|
@@ -402,7 +402,7 @@ function resolveSchemaRef(document: Document, schema: SchemaObject): SchemaObjec
|
|
|
402
402
|
export function getSchemas(document: Document, { contentType }: GetSchemasOptions): GetSchemasResult {
|
|
403
403
|
const components = document.components
|
|
404
404
|
|
|
405
|
-
const candidates: SchemaWithMetadata
|
|
405
|
+
const candidates: Array<SchemaWithMetadata> = [
|
|
406
406
|
...Object.entries((components?.schemas as Record<string, SchemaObject>) ?? {}).map(([name, schema]) => ({
|
|
407
407
|
schema: resolveSchemaRef(document, schema),
|
|
408
408
|
source: 'schemas' as const,
|
|
@@ -424,7 +424,7 @@ export function getSchemas(document: Document, { contentType }: GetSchemasOption
|
|
|
424
424
|
),
|
|
425
425
|
]
|
|
426
426
|
|
|
427
|
-
const normalizedNames = new Map<string, SchemaWithMetadata
|
|
427
|
+
const normalizedNames = new Map<string, Array<SchemaWithMetadata>>()
|
|
428
428
|
for (const item of candidates) {
|
|
429
429
|
const key = pascalCase(item.originalName)
|
|
430
430
|
const bucket = normalizedNames.get(key) ?? []
|
|
@@ -529,7 +529,7 @@ export function buildSchemaNode(schema: SchemaObject, name: string | null | unde
|
|
|
529
529
|
* // ['application/json', 'multipart/form-data']
|
|
530
530
|
* ```
|
|
531
531
|
*/
|
|
532
|
-
export function getRequestBodyContentTypes(document: Document, operation: Operation): string
|
|
532
|
+
export function getRequestBodyContentTypes(document: Document, operation: Operation): Array<string> {
|
|
533
533
|
if (operation.schema.requestBody) {
|
|
534
534
|
operation.schema.requestBody = dereferenceWithRef(document, operation.schema.requestBody)
|
|
535
535
|
}
|
package/src/stream.ts
CHANGED
|
@@ -8,8 +8,8 @@ import type { AdapterOas, Document, SchemaObject } from './types.ts'
|
|
|
8
8
|
|
|
9
9
|
export type PreScanResult = {
|
|
10
10
|
refAliasMap: Map<string, ast.SchemaNode>
|
|
11
|
-
enumNames: string
|
|
12
|
-
circularNames: string
|
|
11
|
+
enumNames: Array<string>
|
|
12
|
+
circularNames: Array<string>
|
|
13
13
|
discriminatorChildMap: Map<string, DiscriminatorTarget> | null
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -74,10 +74,10 @@ export function preScan({
|
|
|
74
74
|
parserOptions: ast.ParserOptions
|
|
75
75
|
discriminator: AdapterOas['options']['discriminator']
|
|
76
76
|
}): PreScanResult {
|
|
77
|
-
const allNodes: ast.SchemaNode
|
|
77
|
+
const allNodes: Array<ast.SchemaNode> = []
|
|
78
78
|
const refAliasMap = new Map<string, ast.SchemaNode>()
|
|
79
|
-
const enumNames: string
|
|
80
|
-
const discriminatorParentNodes: ast.SchemaNode
|
|
79
|
+
const enumNames: Array<string> = []
|
|
80
|
+
const discriminatorParentNodes: Array<ast.SchemaNode> = []
|
|
81
81
|
|
|
82
82
|
for (const [name, schema] of Object.entries(schemas)) {
|
|
83
83
|
const node = parseSchema({ schema, name }, parserOptions)
|