Skip to content

Commit 7a1b951

Browse files
committed
chore: fix ts
1 parent d330ff1 commit 7a1b951

File tree

11 files changed

+38
-30
lines changed

11 files changed

+38
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './operations'
2-
export * as petsService from './petsService/index'
32
export * as petService from './petService/index'
3+
export * as petsService from './petsService/index'
44
export * as userService from './userService/index'
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export * as petsHooks from './petsController/index'
21
export * as petHooks from './petController/index'
2+
export * as petsHooks from './petsController/index'
33
export * as userHooks from './userController/index'

examples/advanced/src/gen/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
export * from './models/ts/index.js'
1+
export * as clients from './clients/axios/index'
22
export * as hooks from './clients/hooks/index'
33
export * as swrHooks from './clients/swr/index'
4-
export * as clients from './clients/axios/index'
5-
export * as zod from './zod/index'
64
export * as faker from './mocks/index'
5+
export * from './models/ts/index.js'
76
export * as msw from './msw/index'
7+
export * as zod from './zod/index'

examples/advanced/src/gen/models/ts/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ export * from './Category.js'
55
export * from './Customer.js'
66
export * from './Order.js'
77
export * from './Pet.js'
8-
export * from './PetNotFound.js'
9-
export * from './User.js'
10-
export * from './UserArray.js'
118
export * from './petController/index.js'
9+
export * from './PetNotFound.js'
1210
export * from './petsController/index.js'
1311
export * from './storeController/index.js'
1412
export * from './tag/index.js'
13+
export * from './User.js'
14+
export * from './UserArray.js'
1515
export * from './userController/index.js'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './handlers'
2-
export * as petsHandlers from './petsController/index'
32
export * as petHandlers from './petController/index'
3+
export * as petsHandlers from './petsController/index'
44
export * as userHandlers from './userController/index'

examples/advanced/src/gen/zod/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ export * from './apiResponseSchema'
44
export * from './categorySchema'
55
export * from './customerSchema'
66
export * from './orderSchema'
7+
export * as petSchemas from './petController/index'
78
export * from './petNotFoundSchema'
89
export * from './petSchema'
10+
export * as petsSchemas from './petsController/index'
911
export * from './tag/index'
1012
export * from './userArraySchema'
11-
export * from './userSchema'
12-
export * as petsSchemas from './petsController/index'
13-
export * as petSchemas from './petController/index'
1413
export * as userSchemas from './userController/index'
14+
export * from './userSchema'

examples/faker/src/gen/customMocks/createUser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function createUser(override: NonNullable<Partial<User>> = {}): NonNullab
1212
'password': faker.internet.password(),
1313
'phone': faker.phone.number(),
1414
'userStatus': faker.number.float({}),
15-
'nationalityCode': faker.helpers.fromRegExp(/^[A-Z]{2}$/),
15+
'nationalityCode': faker.helpers.fromRegExp(/\/^[A-Z]{2}$\//),
1616
},
1717
...override,
1818
}

examples/faker/src/gen/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './models/index'
21
export * from './customMocks/index'
2+
export * from './models/index'

packages/swagger-ts/src/OperationGenerator.test.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('OperationGenerator', async () => {
1818
test('[GET] /pets with optionalType `questionToken`', async () => {
1919
const options: GetOperationGeneratorOptions<OperationGenerator> = {
2020
enumType: 'asConst',
21+
enumSuffix: '',
2122
dateType: 'string',
2223
optionalType: 'questionToken',
2324
usedEnumNames: {},
@@ -56,6 +57,7 @@ describe('OperationGenerator', async () => {
5657
test('[POST] /pets 201', async () => {
5758
const options: GetOperationGeneratorOptions<OperationGenerator> = {
5859
enumType: 'asConst',
60+
enumSuffix: '',
5961
dateType: 'string',
6062
optionalType: 'questionToken',
6163
usedEnumNames: {},
@@ -87,6 +89,7 @@ describe('OperationGenerator', async () => {
8789
test('[DELETE] /pet/{petId} with unknownType `any`', async () => {
8890
const options: GetOperationGeneratorOptions<OperationGenerator> = {
8991
enumType: 'asConst',
92+
enumSuffix: '',
9093
dateType: 'string',
9194
optionalType: 'questionToken',
9295
usedEnumNames: {},
@@ -117,6 +120,7 @@ describe('OperationGenerator', async () => {
117120
test('[DELETE] /pet/{petId} with unknownType `unknown`', async () => {
118121
const options: GetOperationGeneratorOptions<OperationGenerator> = {
119122
enumType: 'asConst',
123+
enumSuffix: '',
120124
dateType: 'string',
121125
optionalType: 'questionToken',
122126
usedEnumNames: {},

packages/swagger-ts/src/TypeGenerator.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { pluginKey } from './plugin.ts'
1010
import type { PluginManager } from '@kubb/core'
1111
import type { ts } from '@kubb/parser'
1212
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'
1414
import type { PluginOptions } from './types.ts'
1515

1616
// 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
3838
description,
3939
keysToOmit,
4040
}: {
41-
schema: OasTypes.SchemaObject
41+
schema: SchemaObject
4242
baseName: string
4343
description?: string
4444
optional?: boolean
@@ -88,7 +88,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
8888
* Delegates to getBaseTypeFromSchema internally and
8989
* optionally adds a union with null.
9090
*/
91-
getTypeFromSchema(schema?: OasTypes.SchemaObject & { 'x-nullable': boolean }, name?: string): ts.TypeNode | null {
91+
getTypeFromSchema(schema?: SchemaObject, name?: string): ts.TypeNode | null {
9292
const type = this.#getBaseTypeFromSchema(schema, name)
9393

9494
if (!type) {
@@ -107,14 +107,14 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
107107
/**
108108
* Recursively creates a type literal with the given props.
109109
*/
110-
#getTypeFromProperties(baseSchema?: OasTypes.SchemaObject, baseName?: string): ts.TypeNode | null {
110+
#getTypeFromProperties(baseSchema?: SchemaObject, baseName?: string): ts.TypeNode | null {
111111
const { optionalType } = this.options
112112
const properties = baseSchema?.properties || {}
113113
const required = baseSchema?.required
114114
const additionalProperties = baseSchema?.additionalProperties
115115

116116
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
118118

119119
const isRequired = Array.isArray(required) ? required.includes(name) : !!required
120120
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
146146
})
147147
})
148148
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)
150150

151151
if (type) {
152152
members.push(factory.createIndexSignature(type))
@@ -186,7 +186,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
186186
return factory.createTypeReferenceNode(ref.propertyName, undefined)
187187
}
188188

189-
#getParsedSchema(schema?: OasTypes.SchemaObject) {
189+
#getParsedSchema(schema?: SchemaObject) {
190190
const parsedSchema = getSchemaFactory(this.context.oas)(schema)
191191
return parsedSchema
192192
}
@@ -196,7 +196,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
196196
* schema and returns the appropriate type.
197197
*/
198198
#getBaseTypeFromSchema(
199-
_schema: OasTypes.SchemaObject | undefined,
199+
_schema: SchemaObject | undefined,
200200
baseName?: string,
201201
): ts.TypeNode | null {
202202
const { schema, version } = this.#getParsedSchema(_schema)
@@ -211,13 +211,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
211211

212212
if (schema.oneOf) {
213213
// union
214-
const schemaWithoutOneOf = { ...schema, oneOf: undefined } as OasTypes.SchemaObject
214+
const schemaWithoutOneOf = { ...schema, oneOf: undefined } as SchemaObject
215215

216216
const union = factory.createUnionDeclaration({
217217
withParentheses: true,
218218
nodes: schema.oneOf
219219
.map((item) => {
220-
return item && this.getTypeFromSchema(item as OasTypes.SchemaObject)
220+
return item && this.getTypeFromSchema(item as SchemaObject)
221221
})
222222
.filter((item) => {
223223
return item && item !== this.#unknownReturn
@@ -234,13 +234,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
234234
}
235235

236236
if (schema.anyOf) {
237-
const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as OasTypes.SchemaObject
237+
const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as SchemaObject
238238

239239
const union = factory.createUnionDeclaration({
240240
withParentheses: true,
241241
nodes: schema.anyOf
242242
.map((item) => {
243-
return item && this.getTypeFromSchema(item as OasTypes.SchemaObject)
243+
return item && this.getTypeFromSchema(item as SchemaObject)
244244
})
245245
.filter((item) => {
246246
return item && item !== this.#unknownReturn
@@ -257,13 +257,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
257257
}
258258
if (schema.allOf) {
259259
// intersection/add
260-
const schemaWithoutAllOf = { ...schema, allOf: undefined } as OasTypes.SchemaObject
260+
const schemaWithoutAllOf = { ...schema, allOf: undefined } as SchemaObject
261261

262262
const and = factory.createIntersectionDeclaration({
263263
withParentheses: true,
264264
nodes: schema.allOf
265265
.map((item) => {
266-
return item && this.getTypeFromSchema(item as OasTypes.SchemaObject)
266+
return item && this.getTypeFromSchema(item as SchemaObject)
267267
})
268268
.filter((item) => {
269269
return item && item !== this.#unknownReturn
@@ -318,7 +318,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
318318

319319
if ('items' in schema) {
320320
// items -> array
321-
const node = this.getTypeFromSchema(schema.items as OasTypes.SchemaObject, baseName)
321+
const node = this.getTypeFromSchema(schema.items as SchemaObject, baseName)
322322
if (node) {
323323
return factory.createArrayTypeNode(node)
324324
}
@@ -330,7 +330,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
330330
*/
331331

332332
if ('prefixItems' in schema) {
333-
const prefixItems = schema.prefixItems as OasTypes.SchemaObject[]
333+
const prefixItems = schema.prefixItems as SchemaObject[]
334334

335335
return factory.createTupleDeclaration({
336336
nodes: prefixItems.map((item) => {

packages/swagger/src/oas/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import type * as OasTypes from 'oas/types'
2+
13
// external packages
24
export type { default as Oas } from 'oas'
35
export type { Operation } from 'oas/operation'
46
export type { HttpMethods as HttpMethod } from 'oas/types'
57
export type * as OasTypes from 'oas/types'
68
export type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'
9+
10+
export type SchemaObject = OasTypes.SchemaObject & { 'x-nullable'?: boolean }

0 commit comments

Comments
 (0)