Skip to content

Commit

Permalink
Fix/zod mapper (#903)
Browse files Browse the repository at this point in the history
* chore: cleanup

* chore: extra schemas test cases

* chore: correct use of mapper

* chore: fix test
  • Loading branch information
stijnvanhulle authored Mar 31, 2024
1 parent 897dab0 commit 0b61a8c
Show file tree
Hide file tree
Showing 57 changed files with 663 additions and 749 deletions.
96 changes: 5 additions & 91 deletions e2e/kubb.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const baseConfig = {
},
plugins: [
createSwagger({
output: {
path: 'schemas',
},
output: false,
validate: true,
}),
createSwagger({
Expand All @@ -57,140 +55,56 @@ const baseConfig = {
createSwaggerTS({
output: {
path: 'models/ts',
extName: '.js',
exportType: false,
},
group: {
type: 'tag',
},
enumType: 'asPascalConst',
enumSuffix: 'enum',
dateType: 'date',
override: [
{
type: 'operationId',
pattern: 'findPetsByStatus',
options: {
enumType: 'enum',
},
},
],
}),
createSwaggerTanstackQuery({
output: {
path: './clients/hooks',
exportAs: 'hooks',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
override: [
{
type: 'tag',
pattern: 'pet',
options: {
infinite: {
queryParam: 'test',
initialPageParam: '0',
},
mutate: {
methods: ['post', 'put', 'delete'],
variablesType: 'mutate',
},
},
},
],
group: { type: 'tag' },
client: {
importPath: '../../../../tanstack-query-client.ts',
mutate: {
variablesType: 'mutate',
methods: ['post', 'put', 'delete'],
},
infinite: {},
dataReturnType: 'full',
parser: 'zod',
}),
createSwaggerSwr({
output: {
path: './clients/swr',
exportAs: 'swrHooks',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
client: {
importPath: '../../../../swr-client.ts',
},
dataReturnType: 'full',
}),
createSwaggerClient({
output: {
path: './clients/axios',
exportAs: 'clients',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag', output: './clients/axios/{{tag}}Service' },
client: {
importPath: '../../../../axios-client.ts',
},
dataReturnType: 'full',
pathParamsType: 'object',
}),
createSwaggerZod({
output: {
path: './zod',
exportAs: 'zod',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
dateType: 'date',
typed: true,
}),
createSwaggerZodios({
output: {
path: 'zodios.ts',
exportAs: 'zodios',
},
}),
createSwaggerFaker({
output: {
path: 'mocks',
exportAs: 'faker',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
dateType: 'date',
}),
createSwaggerMsw({
output: {
path: 'msw',
exportAs: 'msw',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
}),
],
Expand Down
3 changes: 3 additions & 0 deletions examples/advanced/configs/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ export default defineConfig(async () => {
],
group: { type: 'tag' },
dateType: 'date',
mapper: {
status: `faker.helpers.arrayElement(['working', 'idle']) as any`,
},
}),
createSwaggerMsw({
output: {
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createAddPetRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function createAddPetRequest(override: NonNullable<Partial<AddPetRequest>
category: createCategory(),
photoUrls: faker.helpers.arrayElements([faker.string.alpha()]) as any,
tags: faker.helpers.arrayElements([createTagTag()]) as any,
status: faker.helpers.arrayElement<any>(['available', 'pending', 'sold']),
status: faker.helpers.arrayElement(['working', 'idle']) as any,
},
...override,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function createOrder(override: NonNullable<Partial<Order>> = {}): NonNull
orderType: faker.helpers.arrayElement<any>(['foo', 'bar']),
type: faker.string.alpha(),
shipDate: faker.date.anytime(),
status: faker.helpers.arrayElement<any>(['placed', 'approved', 'delivered']),
status: faker.helpers.arrayElement(['working', 'idle']) as any,
http_status: faker.helpers.arrayElement<any>(['ok', 'not_found']),
complete: faker.datatype.boolean(),
},
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createPet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function createPet(override: NonNullable<Partial<Pet>> = {}): NonNullable
category: createCategory(),
photoUrls: faker.helpers.arrayElements([faker.string.alpha()]) as any,
tags: faker.helpers.arrayElements([createTagTag()]) as any,
status: faker.helpers.arrayElement<any>(['available', 'pending', 'sold']),
status: faker.helpers.arrayElement(['working', 'idle']) as any,
},
...override,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createPet } from '../createPet'

export function createFindPetsByStatusQueryParams(override: NonNullable<Partial<FindPetsByStatusQueryParams>> = {}): NonNullable<FindPetsByStatusQueryParams> {
return {
...{ status: faker.helpers.arrayElement<any>(['available', 'pending', 'sold']) },
...{ status: faker.helpers.arrayElement(['working', 'idle']) as any },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createUpdatePetWithFormQueryParams(
override: NonNullable<Partial<UpdatePetWithFormQueryParams>> = {},
): NonNullable<UpdatePetWithFormQueryParams> {
return {
...{ name: faker.string.alpha(), status: faker.string.alpha() },
...{ name: faker.string.alpha(), status: faker.helpers.arrayElement(['working', 'idle']) as any },
...override,
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/faker/kubb.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ module.exports = defineConfig(async () => {
return undefined
},
},
// mapper: {
// productName: 'faker.commerce.productName',
// },
mapper: {
message: 'faker.commerce.productName()',
},
include: [
{
type: 'operationId',
Expand Down
2 changes: 1 addition & 1 deletion examples/faker/src/gen/customMocks/createApiResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ApiResponse } from '../models/ApiResponse'

export function createApiResponse(override: NonNullable<Partial<ApiResponse>> = {}): NonNullable<ApiResponse> {
return {
...{ code: faker.number.int(), type: faker.string.alpha(), message: faker.string.alpha() },
...{ code: faker.number.int(), type: faker.string.alpha(), message: faker.commerce.productName() },
...override,
}
}
2 changes: 1 addition & 1 deletion examples/faker/src/gen/customMocks/createUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function createUser(override: NonNullable<Partial<User>> = {}): NonNullab
password: faker.string.alpha(),
phone: faker.string.alpha(),
userStatus: faker.number.int(),
nationalityCode: faker.helpers.arrayElement([faker.string.alpha(), faker.helpers.fromRegExp(/^[A-Z]{2}$/)]),
nationalityCode: faker.helpers.arrayElement<any>([faker.string.alpha(), faker.helpers.fromRegExp(/^[A-Z]{2}$/)]),
},
...override,
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lint": "bun biome lint ./packages",
"lint:case": "npx case-police --fix",
"lint:ci": "bun biome lint ./packages",
"lint:fix": "bun biome lint --apply ./packages && bun run lint:case",
"lint:fix": "bun biome lint --apply-unsafe ./packages && bun run lint:case",
"lint:turbo": "turbo run lint",
"release": "changeset publish",
"release:canary": "changeset publish --no-git-tag",
Expand Down
16 changes: 2 additions & 14 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"name": "@kubb/cli",
"version": "2.12.0",
"description": "Generator cli",
"keywords": [
"typescript",
"plugins",
"kubb",
"codegen",
"cli"
],
"keywords": ["typescript", "plugins", "kubb", "codegen", "cli"],
"repository": {
"type": "git",
"url": "git://github.com/kubb-project/kubb.git",
Expand All @@ -31,13 +25,7 @@
"bin": {
"kubb": "bin/kubb.cjs"
},
"files": [
"src",
"dist",
"bin",
"!/**/**.test.**",
"!/**/__tests__/**"
],
"files": ["src", "dist", "bin", "!/**/**.test.**", "!/**/__tests__/**"],
"scripts": {
"build": "tsup",
"clean": "npx rimraf ./dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/mocks/hellowWorld.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const hallo = 'world'
export const hallo = 'world'
37 changes: 7 additions & 30 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
"name": "@kubb/core",
"version": "2.12.0",
"description": "Generator core",
"keywords": [
"typescript",
"plugins",
"kubb",
"codegen"
],
"keywords": ["typescript", "plugins", "kubb", "codegen"],
"repository": {
"type": "git",
"url": "git://github.com/kubb-project/kubb.git",
Expand Down Expand Up @@ -59,32 +54,14 @@
"types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"utils": [
"./dist/utils.d.ts"
],
"transformers": [
"./dist/transformers.d.ts"
],
"logger": [
"./dist/logger.d.ts"
],
"fs": [
"./dist/fs.d.ts"
],
"mocks": [
"./dist/mocks.d.ts"
]
"utils": ["./dist/utils.d.ts"],
"transformers": ["./dist/transformers.d.ts"],
"logger": ["./dist/logger.d.ts"],
"fs": ["./dist/fs.d.ts"],
"mocks": ["./dist/mocks.d.ts"]
}
},
"files": [
"src",
"dist",
"*.d.ts",
"*.d.cts",
"schema.json",
"!/**/**.test.**",
"!/**/__tests__/**"
],
"files": ["src", "dist", "*.d.ts", "*.d.cts", "schema.json", "!/**/**.test.**", "!/**/__tests__/**"],
"scripts": {
"build": "tsup",
"clean": "npx rimraf ./dist",
Expand Down
16 changes: 2 additions & 14 deletions packages/kubb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
"name": "kubb",
"version": "2.0.0-beta.2",
"description": "OpenAPI to TypeScript, React-Query, Zod, Zodios, Faker.js, MSW and Axios.",
"keywords": [
"typescript",
"plugins",
"kubb",
"codegen",
"cli"
],
"keywords": ["typescript", "plugins", "kubb", "codegen", "cli"],
"repository": {
"type": "git",
"url": "git://github.com/kubb-project/kubb.git",
Expand All @@ -24,13 +18,7 @@
"bin": {
"kubb": "bin/kubb.js"
},
"files": [
"src",
"dist",
"bin",
"!/**/**.test.**",
"!/**/__tests__/**"
],
"files": ["src", "dist", "bin", "!/**/**.test.**", "!/**/__tests__/**"],
"scripts": {
"build": "tsup",
"clean": "npx rimraf ./dist",
Expand Down
Loading

0 comments on commit 0b61a8c

Please sign in to comment.