@@ -10,7 +10,7 @@ import { pluginKey } from './plugin.ts'
10
10
import type { PluginManager } from '@kubb/core'
11
11
import type { ts } from '@kubb/parser'
12
12
import type { ImportMeta , Refs } from '@kubb/swagger'
13
- import type { Oas , OasTypes , OpenAPIV3 , OpenAPIV3_1 } from '@kubb/swagger/oas'
13
+ import type { Oas , OpenAPIV3 , OpenAPIV3_1 , SchemaObject } from '@kubb/swagger/oas'
14
14
import type { PluginOptions } from './types.ts'
15
15
16
16
// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398
@@ -38,7 +38,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
38
38
description,
39
39
keysToOmit,
40
40
} : {
41
- schema : OasTypes . SchemaObject
41
+ schema : SchemaObject
42
42
baseName : string
43
43
description ?: string
44
44
optional ?: boolean
@@ -88,7 +88,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
88
88
* Delegates to getBaseTypeFromSchema internally and
89
89
* optionally adds a union with null.
90
90
*/
91
- getTypeFromSchema ( schema ?: OasTypes . SchemaObject & { 'x-nullable' : boolean } , name ?: string ) : ts . TypeNode | null {
91
+ getTypeFromSchema ( schema ?: SchemaObject , name ?: string ) : ts . TypeNode | null {
92
92
const type = this . #getBaseTypeFromSchema( schema , name )
93
93
94
94
if ( ! type ) {
@@ -107,14 +107,14 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
107
107
/**
108
108
* Recursively creates a type literal with the given props.
109
109
*/
110
- #getTypeFromProperties( baseSchema ?: OasTypes . SchemaObject , baseName ?: string ) : ts . TypeNode | null {
110
+ #getTypeFromProperties( baseSchema ?: SchemaObject , baseName ?: string ) : ts . TypeNode | null {
111
111
const { optionalType } = this . options
112
112
const properties = baseSchema ?. properties || { }
113
113
const required = baseSchema ?. required
114
114
const additionalProperties = baseSchema ?. additionalProperties
115
115
116
116
const members : Array < ts . TypeElement | null > = Object . keys ( properties ) . map ( ( name ) => {
117
- const schema = properties [ name ] as OasTypes . SchemaObject
117
+ const schema = properties [ name ] as SchemaObject
118
118
119
119
const isRequired = Array . isArray ( required ) ? required . includes ( name ) : ! ! required
120
120
let type = this . getTypeFromSchema ( schema , this . context . pluginManager . resolveName ( { name : `${ baseName || '' } ${ name } ` , pluginKey, type : 'type' } ) )
@@ -146,7 +146,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
146
146
} )
147
147
} )
148
148
if ( additionalProperties ) {
149
- const type = additionalProperties === true ? this . #unknownReturn : this . getTypeFromSchema ( additionalProperties as OasTypes . SchemaObject )
149
+ const type = additionalProperties === true ? this . #unknownReturn : this . getTypeFromSchema ( additionalProperties as SchemaObject )
150
150
151
151
if ( type ) {
152
152
members . push ( factory . createIndexSignature ( type ) )
@@ -186,7 +186,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
186
186
return factory . createTypeReferenceNode ( ref . propertyName , undefined )
187
187
}
188
188
189
- #getParsedSchema( schema ?: OasTypes . SchemaObject ) {
189
+ #getParsedSchema( schema ?: SchemaObject ) {
190
190
const parsedSchema = getSchemaFactory ( this . context . oas ) ( schema )
191
191
return parsedSchema
192
192
}
@@ -196,7 +196,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
196
196
* schema and returns the appropriate type.
197
197
*/
198
198
#getBaseTypeFromSchema(
199
- _schema : OasTypes . SchemaObject | undefined ,
199
+ _schema : SchemaObject | undefined ,
200
200
baseName ?: string ,
201
201
) : ts . TypeNode | null {
202
202
const { schema, version } = this . #getParsedSchema( _schema )
@@ -211,13 +211,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
211
211
212
212
if ( schema . oneOf ) {
213
213
// union
214
- const schemaWithoutOneOf = { ...schema , oneOf : undefined } as OasTypes . SchemaObject
214
+ const schemaWithoutOneOf = { ...schema , oneOf : undefined } as SchemaObject
215
215
216
216
const union = factory . createUnionDeclaration ( {
217
217
withParentheses : true ,
218
218
nodes : schema . oneOf
219
219
. map ( ( item ) => {
220
- return item && this . getTypeFromSchema ( item as OasTypes . SchemaObject )
220
+ return item && this . getTypeFromSchema ( item as SchemaObject )
221
221
} )
222
222
. filter ( ( item ) => {
223
223
return item && item !== this . #unknownReturn
@@ -234,13 +234,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
234
234
}
235
235
236
236
if ( schema . anyOf ) {
237
- const schemaWithoutAnyOf = { ...schema , anyOf : undefined } as OasTypes . SchemaObject
237
+ const schemaWithoutAnyOf = { ...schema , anyOf : undefined } as SchemaObject
238
238
239
239
const union = factory . createUnionDeclaration ( {
240
240
withParentheses : true ,
241
241
nodes : schema . anyOf
242
242
. map ( ( item ) => {
243
- return item && this . getTypeFromSchema ( item as OasTypes . SchemaObject )
243
+ return item && this . getTypeFromSchema ( item as SchemaObject )
244
244
} )
245
245
. filter ( ( item ) => {
246
246
return item && item !== this . #unknownReturn
@@ -257,13 +257,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
257
257
}
258
258
if ( schema . allOf ) {
259
259
// intersection/add
260
- const schemaWithoutAllOf = { ...schema , allOf : undefined } as OasTypes . SchemaObject
260
+ const schemaWithoutAllOf = { ...schema , allOf : undefined } as SchemaObject
261
261
262
262
const and = factory . createIntersectionDeclaration ( {
263
263
withParentheses : true ,
264
264
nodes : schema . allOf
265
265
. map ( ( item ) => {
266
- return item && this . getTypeFromSchema ( item as OasTypes . SchemaObject )
266
+ return item && this . getTypeFromSchema ( item as SchemaObject )
267
267
} )
268
268
. filter ( ( item ) => {
269
269
return item && item !== this . #unknownReturn
@@ -318,7 +318,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
318
318
319
319
if ( 'items' in schema ) {
320
320
// items -> array
321
- const node = this . getTypeFromSchema ( schema . items as OasTypes . SchemaObject , baseName )
321
+ const node = this . getTypeFromSchema ( schema . items as SchemaObject , baseName )
322
322
if ( node ) {
323
323
return factory . createArrayTypeNode ( node )
324
324
}
@@ -330,7 +330,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
330
330
*/
331
331
332
332
if ( 'prefixItems' in schema ) {
333
- const prefixItems = schema . prefixItems as OasTypes . SchemaObject [ ]
333
+ const prefixItems = schema . prefixItems as SchemaObject [ ]
334
334
335
335
return factory . createTupleDeclaration ( {
336
336
nodes : prefixItems . map ( ( item ) => {
0 commit comments