From 004e104231034af0e4159600eba9084ef4af9a5e Mon Sep 17 00:00:00 2001 From: Stijn Van Hulle Date: Fri, 24 Nov 2023 18:12:47 +0100 Subject: [PATCH] chore(zod): example for mapper --- examples/faker/kubb.config.js | 51 ++++++++++++++----- .../src/gen/customMocks/createAddress.ts | 12 +++++ .../createApiResponse.ts | 2 +- .../{mocks => customMocks}/createCategory.ts | 2 +- .../{mocks => customMocks}/createCustomer.ts | 2 +- .../faker/src/gen/customMocks/createOrder.ts | 13 +++++ .../faker/src/gen/customMocks/createPet.ts | 15 ++++++ .../gen/{mocks => customMocks}/createTag.ts | 2 +- .../createUpdatePet.ts | 4 +- .../createUpdatePetWithForm.ts | 6 +-- .../faker/src/gen/customMocks/createUser.ts | 15 ++++++ .../{mocks => customMocks}/createUserArray.ts | 0 .../src/gen/{mocks => customMocks}/index.ts | 5 +- examples/faker/src/gen/index.ts | 2 +- examples/faker/src/gen/mocks/createAddress.ts | 12 ----- examples/faker/src/gen/mocks/createOrder.ts | 13 ----- examples/faker/src/gen/mocks/createPet.ts | 15 ------ examples/faker/src/gen/mocks/createUser.ts | 15 ------ .../src/gen/mocks/petMocks/createAddPet.ts | 24 --------- .../src/gen/mocks/petMocks/createDeletePet.ts | 22 -------- .../mocks/petMocks/createFindPetsByStatus.ts | 22 -------- .../mocks/petMocks/createFindPetsByTags.ts | 22 -------- .../gen/mocks/petMocks/createGetPetById.ts | 29 ----------- .../gen/mocks/petMocks/createUploadFile.ts | 22 -------- .../faker/src/gen/mocks/petMocks/index.ts | 8 --- .../gen/mocks/storeMocks/createDeleteOrder.ts | 25 --------- .../mocks/storeMocks/createGetInventory.ts | 9 ---- .../mocks/storeMocks/createGetOrderById.ts | 29 ----------- .../gen/mocks/storeMocks/createPlaceOrder.ts | 21 -------- .../faker/src/gen/mocks/storeMocks/index.ts | 4 -- .../gen/mocks/userMocks/createCreateUser.ts | 20 -------- .../createCreateUsersWithListInput.ts | 26 ---------- .../gen/mocks/userMocks/createDeleteUser.ts | 25 --------- .../mocks/userMocks/createGetUserByName.ts | 29 ----------- .../gen/mocks/userMocks/createLoginUser.ts | 21 -------- .../gen/mocks/userMocks/createLogoutUser.ts | 13 ----- .../gen/mocks/userMocks/createUpdateUser.ts | 26 ---------- .../faker/src/gen/mocks/userMocks/index.ts | 7 --- examples/faker/src/gen/models/Address.ts | 6 ++- .../faker/src/gen/models/FindPetsByStatus.ts | 6 +-- examples/faker/src/gen/models/Order.ts | 6 +-- examples/faker/src/gen/models/Pet.ts | 6 +-- packages/core/src/PluginManager.ts | 8 +-- packages/core/src/build.ts | 2 +- packages/swagger-faker/src/fakerParser.ts | 2 +- packages/swagger-faker/src/types.ts | 4 +- packages/swagger-zod/src/zodParser.ts | 2 +- .../swagger/src/utils/getGroupedByTagFiles.ts | 6 ++- 48 files changed, 131 insertions(+), 507 deletions(-) create mode 100644 examples/faker/src/gen/customMocks/createAddress.ts rename examples/faker/src/gen/{mocks => customMocks}/createApiResponse.ts (60%) rename examples/faker/src/gen/{mocks => customMocks}/createCategory.ts (65%) rename examples/faker/src/gen/{mocks => customMocks}/createCustomer.ts (58%) create mode 100644 examples/faker/src/gen/customMocks/createOrder.ts create mode 100644 examples/faker/src/gen/customMocks/createPet.ts rename examples/faker/src/gen/{mocks => customMocks}/createTag.ts (62%) rename examples/faker/src/gen/{mocks/petMocks => customMocks}/createUpdatePet.ts (87%) rename examples/faker/src/gen/{mocks/petMocks => customMocks}/createUpdatePetWithForm.ts (79%) create mode 100644 examples/faker/src/gen/customMocks/createUser.ts rename examples/faker/src/gen/{mocks => customMocks}/createUserArray.ts (100%) rename examples/faker/src/gen/{mocks => customMocks}/index.ts (66%) delete mode 100644 examples/faker/src/gen/mocks/createAddress.ts delete mode 100644 examples/faker/src/gen/mocks/createOrder.ts delete mode 100644 examples/faker/src/gen/mocks/createPet.ts delete mode 100644 examples/faker/src/gen/mocks/createUser.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/createAddPet.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/createDeletePet.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/createFindPetsByStatus.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/createFindPetsByTags.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/createGetPetById.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/createUploadFile.ts delete mode 100644 examples/faker/src/gen/mocks/petMocks/index.ts delete mode 100644 examples/faker/src/gen/mocks/storeMocks/createDeleteOrder.ts delete mode 100644 examples/faker/src/gen/mocks/storeMocks/createGetInventory.ts delete mode 100644 examples/faker/src/gen/mocks/storeMocks/createGetOrderById.ts delete mode 100644 examples/faker/src/gen/mocks/storeMocks/createPlaceOrder.ts delete mode 100644 examples/faker/src/gen/mocks/storeMocks/index.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createCreateUser.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createCreateUsersWithListInput.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createDeleteUser.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createGetUserByName.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createLoginUser.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createLogoutUser.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/createUpdateUser.ts delete mode 100644 examples/faker/src/gen/mocks/userMocks/index.ts diff --git a/examples/faker/kubb.config.js b/examples/faker/kubb.config.js index 2d4d8f284..91d92e385 100644 --- a/examples/faker/kubb.config.js +++ b/examples/faker/kubb.config.js @@ -1,5 +1,9 @@ import { defineConfig } from '@kubb/core' +import createSwagger from '@kubb/swagger' +import createSwaggerFaker from '@kubb/swagger-faker' +import createSwaggerTS from '@kubb/swagger-ts' + export default defineConfig(async () => { await setTimeout(() => { // wait for 1s, async behaviour @@ -15,23 +19,42 @@ export default defineConfig(async () => { clean: true, }, hooks: { - done: ['prettier --write "**/*.{ts,tsx}"', 'eslint --fix ./src/gen'], + // done: ['prettier --write "**/*.{ts,tsx}"', 'eslint --fix ./src/gen'], }, plugins: [ - ['@kubb/swagger', { - output: false, - }], - ['@kubb/swagger-ts', { - output: 'models', - }], - ['@kubb/swagger-faker', { - output: './mocks', - group: { type: 'tag', output: './mocks/{{tag}}Mocks' }, - }], - // ['@kubb/swagger-faker', { - // output: './mocks.ts', + createSwagger({ output: false }), + createSwaggerTS({ output: 'models' }), + // createSwaggerFaker({ + // output: './mocks', // group: { type: 'tag', output: './mocks/{{tag}}Mocks' }, - // }], + // }), + createSwaggerFaker({ + output: './customMocks', + transformers: { + schema: (_schema, baseName) => { + /* override a property with name 'name' + name: + type: string + example: doggie + */ + if (baseName === 'name') { + // see mapper where we map `productionName` to `faker.commerce.productName` + return [{ keyword: 'productName' }] + } + return undefined + }, + }, + mapper: { + 'productName': 'faker.commerce.productName', + }, + include: [ + { + type: 'operationId', + pattern: 'updatePet', + }, + ], + exclude: [], + }), ], } }) diff --git a/examples/faker/src/gen/customMocks/createAddress.ts b/examples/faker/src/gen/customMocks/createAddress.ts new file mode 100644 index 000000000..da6d3fef5 --- /dev/null +++ b/examples/faker/src/gen/customMocks/createAddress.ts @@ -0,0 +1,12 @@ +import { faker } from '@faker-js/faker' +import type { Address } from '../models/Address' + +export function createAddress(): NonNullable
{ + return { + 'street': faker.string.alpha(), + 'city': faker.string.alpha(), + 'state': faker.string.alpha(), + 'zip': faker.string.alpha(), + 'identifier': faker.helpers.arrayElements([faker.number.float({}), faker.string.alpha(), faker.helpers.arrayElement([`NW`, `NE`, `SW`, `SE`])]) as any, + } +} diff --git a/examples/faker/src/gen/mocks/createApiResponse.ts b/examples/faker/src/gen/customMocks/createApiResponse.ts similarity index 60% rename from examples/faker/src/gen/mocks/createApiResponse.ts rename to examples/faker/src/gen/customMocks/createApiResponse.ts index e635d52b4..f739b0c70 100644 --- a/examples/faker/src/gen/mocks/createApiResponse.ts +++ b/examples/faker/src/gen/customMocks/createApiResponse.ts @@ -2,5 +2,5 @@ import { faker } from '@faker-js/faker' import type { ApiResponse } from '../models/ApiResponse' export function createApiResponse(): NonNullable { - return { code: faker.number.float({}), type: faker.string.alpha(), message: faker.string.alpha() } + return { 'code': faker.number.float({}), 'type': faker.string.alpha(), 'message': faker.string.alpha() } } diff --git a/examples/faker/src/gen/mocks/createCategory.ts b/examples/faker/src/gen/customMocks/createCategory.ts similarity index 65% rename from examples/faker/src/gen/mocks/createCategory.ts rename to examples/faker/src/gen/customMocks/createCategory.ts index 96620e9d6..31a954824 100644 --- a/examples/faker/src/gen/mocks/createCategory.ts +++ b/examples/faker/src/gen/customMocks/createCategory.ts @@ -2,5 +2,5 @@ import { faker } from '@faker-js/faker' import type { Category } from '../models/Category' export function createCategory(): NonNullable { - return { id: faker.number.float({}), name: faker.string.alpha() } + return { 'id': faker.number.float({}), 'name': faker.commerce.productName() } } diff --git a/examples/faker/src/gen/mocks/createCustomer.ts b/examples/faker/src/gen/customMocks/createCustomer.ts similarity index 58% rename from examples/faker/src/gen/mocks/createCustomer.ts rename to examples/faker/src/gen/customMocks/createCustomer.ts index 109fe65cd..4e5b78d5e 100644 --- a/examples/faker/src/gen/mocks/createCustomer.ts +++ b/examples/faker/src/gen/customMocks/createCustomer.ts @@ -3,5 +3,5 @@ import { faker } from '@faker-js/faker' import type { Customer } from '../models/Customer' export function createCustomer(): NonNullable { - return { id: faker.number.float({}), username: faker.string.alpha(), address: faker.helpers.arrayElements([createAddress()]) as any } + return { 'id': faker.number.float({}), 'username': faker.string.alpha(), 'address': faker.helpers.arrayElements([createAddress()]) as any } } diff --git a/examples/faker/src/gen/customMocks/createOrder.ts b/examples/faker/src/gen/customMocks/createOrder.ts new file mode 100644 index 000000000..c86da8eae --- /dev/null +++ b/examples/faker/src/gen/customMocks/createOrder.ts @@ -0,0 +1,13 @@ +import { faker } from '@faker-js/faker' +import type { Order } from '../models/Order' + +export function createOrder(): NonNullable { + return { + 'id': faker.number.float({}), + 'petId': faker.number.float({}), + 'quantity': faker.number.float({}), + 'shipDate': faker.string.alpha(), + 'status': faker.helpers.arrayElement([`placed`, `approved`, `delivered`]), + 'complete': faker.datatype.boolean(), + } +} diff --git a/examples/faker/src/gen/customMocks/createPet.ts b/examples/faker/src/gen/customMocks/createPet.ts new file mode 100644 index 000000000..9409db17d --- /dev/null +++ b/examples/faker/src/gen/customMocks/createPet.ts @@ -0,0 +1,15 @@ +import { createCategory } from './createCategory' +import { createTag } from './createTag' +import { faker } from '@faker-js/faker' +import type { Pet } from '../models/Pet' + +export function createPet(): NonNullable { + return { + 'id': faker.number.float({}), + 'name': faker.commerce.productName(), + 'category': createCategory(), + 'photoUrls': faker.helpers.arrayElements([faker.string.alpha()]) as any, + 'tags': faker.helpers.arrayElements([createTag()]) as any, + 'status': faker.helpers.arrayElement([`available`, `pending`, `sold`]), + } +} diff --git a/examples/faker/src/gen/mocks/createTag.ts b/examples/faker/src/gen/customMocks/createTag.ts similarity index 62% rename from examples/faker/src/gen/mocks/createTag.ts rename to examples/faker/src/gen/customMocks/createTag.ts index fc6942497..b2d9cd5ad 100644 --- a/examples/faker/src/gen/mocks/createTag.ts +++ b/examples/faker/src/gen/customMocks/createTag.ts @@ -2,5 +2,5 @@ import { faker } from '@faker-js/faker' import type { Tag } from '../models/Tag' export function createTag(): NonNullable { - return { id: faker.number.float({}), name: faker.string.alpha() } + return { 'id': faker.number.float({}), 'name': faker.commerce.productName() } } diff --git a/examples/faker/src/gen/mocks/petMocks/createUpdatePet.ts b/examples/faker/src/gen/customMocks/createUpdatePet.ts similarity index 87% rename from examples/faker/src/gen/mocks/petMocks/createUpdatePet.ts rename to examples/faker/src/gen/customMocks/createUpdatePet.ts index 884ed58aa..c5db5c311 100644 --- a/examples/faker/src/gen/mocks/petMocks/createUpdatePet.ts +++ b/examples/faker/src/gen/customMocks/createUpdatePet.ts @@ -1,5 +1,5 @@ -import { createPet } from '../createPet' -import type { UpdatePet400, UpdatePet404, UpdatePet405, UpdatePetMutationRequest, UpdatePetMutationResponse } from '../../models/UpdatePet' +import { createPet } from './createPet' +import type { UpdatePet400, UpdatePet404, UpdatePet405, UpdatePetMutationRequest, UpdatePetMutationResponse } from '../models/UpdatePet' /** * @description Invalid ID supplied diff --git a/examples/faker/src/gen/mocks/petMocks/createUpdatePetWithForm.ts b/examples/faker/src/gen/customMocks/createUpdatePetWithForm.ts similarity index 79% rename from examples/faker/src/gen/mocks/petMocks/createUpdatePetWithForm.ts rename to examples/faker/src/gen/customMocks/createUpdatePetWithForm.ts index 1f984b3d4..ef23cb8e2 100644 --- a/examples/faker/src/gen/mocks/petMocks/createUpdatePetWithForm.ts +++ b/examples/faker/src/gen/customMocks/createUpdatePetWithForm.ts @@ -4,7 +4,7 @@ import type { UpdatePetWithFormMutationResponse, UpdatePetWithFormPathParams, UpdatePetWithFormQueryParams, -} from '../../models/UpdatePetWithForm' +} from '../models/UpdatePetWithForm' /** * @description Invalid input @@ -19,9 +19,9 @@ export function createUpdatePetWithFormMutationResponse(): NonNullable { - return { petId: faker.number.float({}) } + return { 'petId': faker.number.float({}) } } export function createUpdatePetWithFormQueryParams(): NonNullable { - return { name: faker.string.alpha(), status: faker.string.alpha() } + return { 'name': faker.commerce.productName(), 'status': faker.string.alpha() } } diff --git a/examples/faker/src/gen/customMocks/createUser.ts b/examples/faker/src/gen/customMocks/createUser.ts new file mode 100644 index 000000000..9d4312e9e --- /dev/null +++ b/examples/faker/src/gen/customMocks/createUser.ts @@ -0,0 +1,15 @@ +import { faker } from '@faker-js/faker' +import type { User } from '../models/User' + +export function createUser(): NonNullable { + return { + 'id': faker.number.float({}), + 'username': faker.string.alpha(), + 'firstName': faker.person.firstName(), + 'lastName': faker.person.lastName(), + 'email': faker.internet.email(), + 'password': faker.internet.password(), + 'phone': faker.phone.number(), + 'userStatus': faker.number.float({}), + } +} diff --git a/examples/faker/src/gen/mocks/createUserArray.ts b/examples/faker/src/gen/customMocks/createUserArray.ts similarity index 100% rename from examples/faker/src/gen/mocks/createUserArray.ts rename to examples/faker/src/gen/customMocks/createUserArray.ts diff --git a/examples/faker/src/gen/mocks/index.ts b/examples/faker/src/gen/customMocks/index.ts similarity index 66% rename from examples/faker/src/gen/mocks/index.ts rename to examples/faker/src/gen/customMocks/index.ts index 16f80fd65..b685ceeb8 100644 --- a/examples/faker/src/gen/mocks/index.ts +++ b/examples/faker/src/gen/customMocks/index.ts @@ -5,8 +5,7 @@ export * from './createCustomer' export * from './createOrder' export * from './createPet' export * from './createTag' +export * from './createUpdatePet' +export * from './createUpdatePetWithForm' export * from './createUser' export * from './createUserArray' -export * as petMocks from './petMocks/index' -export * as storeMocks from './storeMocks/index' -export * as userMocks from './userMocks/index' diff --git a/examples/faker/src/gen/index.ts b/examples/faker/src/gen/index.ts index 9c776fc28..b2ee2d10d 100644 --- a/examples/faker/src/gen/index.ts +++ b/examples/faker/src/gen/index.ts @@ -1,2 +1,2 @@ -export * from './mocks/index' +export * from './customMocks/index' export * from './models/index' diff --git a/examples/faker/src/gen/mocks/createAddress.ts b/examples/faker/src/gen/mocks/createAddress.ts deleted file mode 100644 index 10f7f0a37..000000000 --- a/examples/faker/src/gen/mocks/createAddress.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { Address } from '../models/Address' - -export function createAddress(): NonNullable
{ - return { - street: faker.string.alpha(), - city: faker.string.alpha(), - state: faker.string.alpha(), - zip: faker.string.alpha(), - identifier: faker.helpers.arrayElements([faker.number.float({}), faker.string.alpha(), faker.helpers.arrayElement([`NW`, `NE`, `SW`, `SE`])]) as any, - } -} diff --git a/examples/faker/src/gen/mocks/createOrder.ts b/examples/faker/src/gen/mocks/createOrder.ts deleted file mode 100644 index 342a2d7fd..000000000 --- a/examples/faker/src/gen/mocks/createOrder.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { Order } from '../models/Order' - -export function createOrder(): NonNullable { - return { - id: faker.number.float({}), - petId: faker.number.float({}), - quantity: faker.number.float({}), - shipDate: faker.string.alpha(), - status: faker.helpers.arrayElement([`placed`, `approved`, `delivered`]), - complete: faker.datatype.boolean(), - } -} diff --git a/examples/faker/src/gen/mocks/createPet.ts b/examples/faker/src/gen/mocks/createPet.ts deleted file mode 100644 index 8e833a5fa..000000000 --- a/examples/faker/src/gen/mocks/createPet.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createCategory } from './createCategory' -import { createTag } from './createTag' -import { faker } from '@faker-js/faker' -import type { Pet } from '../models/Pet' - -export function createPet(): NonNullable { - return { - id: faker.number.float({}), - name: faker.string.alpha(), - category: createCategory(), - photoUrls: faker.helpers.arrayElements([faker.string.alpha()]) as any, - tags: faker.helpers.arrayElements([createTag()]) as any, - status: faker.helpers.arrayElement([`available`, `pending`, `sold`]), - } -} diff --git a/examples/faker/src/gen/mocks/createUser.ts b/examples/faker/src/gen/mocks/createUser.ts deleted file mode 100644 index fb5b56009..000000000 --- a/examples/faker/src/gen/mocks/createUser.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { User } from '../models/User' - -export function createUser(): NonNullable { - return { - id: faker.number.float({}), - username: faker.string.alpha(), - firstName: faker.person.firstName(), - lastName: faker.person.lastName(), - email: faker.internet.email(), - password: faker.internet.password(), - phone: faker.phone.number(), - userStatus: faker.number.float({}), - } -} diff --git a/examples/faker/src/gen/mocks/petMocks/createAddPet.ts b/examples/faker/src/gen/mocks/petMocks/createAddPet.ts deleted file mode 100644 index 283205af5..000000000 --- a/examples/faker/src/gen/mocks/petMocks/createAddPet.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { createPet } from '../createPet' -import type { AddPet405, AddPetMutationRequest, AddPetMutationResponse } from '../../models/AddPet' - -/** - * @description Invalid input - */ - -export function createAddPet405(): NonNullable { - return undefined -} -/** - * @description Create a new pet in the store - */ - -export function createAddPetMutationRequest(): NonNullable { - return createPet() -} -/** - * @description Successful operation - */ - -export function createAddPetMutationResponse(): NonNullable { - return createPet() -} diff --git a/examples/faker/src/gen/mocks/petMocks/createDeletePet.ts b/examples/faker/src/gen/mocks/petMocks/createDeletePet.ts deleted file mode 100644 index 578098dec..000000000 --- a/examples/faker/src/gen/mocks/petMocks/createDeletePet.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { DeletePet400, DeletePetHeaderParams, DeletePetMutationResponse, DeletePetPathParams } from '../../models/DeletePet' - -/** - * @description Invalid pet value - */ - -export function createDeletePet400(): NonNullable { - return undefined -} - -export function createDeletePetHeaderParams(): NonNullable { - return { api_key: faker.string.alpha() } -} - -export function createDeletePetMutationResponse(): NonNullable { - return undefined -} - -export function createDeletePetPathParams(): NonNullable { - return { petId: faker.number.float({}) } -} diff --git a/examples/faker/src/gen/mocks/petMocks/createFindPetsByStatus.ts b/examples/faker/src/gen/mocks/petMocks/createFindPetsByStatus.ts deleted file mode 100644 index 78916ade9..000000000 --- a/examples/faker/src/gen/mocks/petMocks/createFindPetsByStatus.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createPet } from '../createPet' -import type { FindPetsByStatus400, FindPetsByStatusQueryParams, FindPetsByStatusQueryResponse } from '../../models/FindPetsByStatus' - -/** - * @description Invalid status value - */ - -export function createFindPetsByStatus400(): NonNullable { - return undefined -} - -export function createFindPetsByStatusQueryParams(): NonNullable { - return { status: faker.helpers.arrayElement([`available`, `pending`, `sold`]) } -} -/** - * @description successful operation - */ - -export function createFindPetsByStatusQueryResponse(): NonNullable { - return faker.helpers.arrayElements([createPet()]) as any -} diff --git a/examples/faker/src/gen/mocks/petMocks/createFindPetsByTags.ts b/examples/faker/src/gen/mocks/petMocks/createFindPetsByTags.ts deleted file mode 100644 index bf3edfd76..000000000 --- a/examples/faker/src/gen/mocks/petMocks/createFindPetsByTags.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createPet } from '../createPet' -import type { FindPetsByTags400, FindPetsByTagsQueryParams, FindPetsByTagsQueryResponse } from '../../models/FindPetsByTags' - -/** - * @description Invalid tag value - */ - -export function createFindPetsByTags400(): NonNullable { - return undefined -} - -export function createFindPetsByTagsQueryParams(): NonNullable { - return { tags: faker.helpers.arrayElements([faker.string.alpha()]) as any } -} -/** - * @description successful operation - */ - -export function createFindPetsByTagsQueryResponse(): NonNullable { - return faker.helpers.arrayElements([createPet()]) as any -} diff --git a/examples/faker/src/gen/mocks/petMocks/createGetPetById.ts b/examples/faker/src/gen/mocks/petMocks/createGetPetById.ts deleted file mode 100644 index 109231354..000000000 --- a/examples/faker/src/gen/mocks/petMocks/createGetPetById.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createPet } from '../createPet' -import type { GetPetById400, GetPetById404, GetPetByIdPathParams, GetPetByIdQueryResponse } from '../../models/GetPetById' - -/** - * @description Invalid ID supplied - */ - -export function createGetPetById400(): NonNullable { - return undefined -} -/** - * @description Pet not found - */ - -export function createGetPetById404(): NonNullable { - return undefined -} - -export function createGetPetByIdPathParams(): NonNullable { - return { petId: faker.number.float({}) } -} -/** - * @description successful operation - */ - -export function createGetPetByIdQueryResponse(): NonNullable { - return createPet() -} diff --git a/examples/faker/src/gen/mocks/petMocks/createUploadFile.ts b/examples/faker/src/gen/mocks/petMocks/createUploadFile.ts deleted file mode 100644 index 7f0579e35..000000000 --- a/examples/faker/src/gen/mocks/petMocks/createUploadFile.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createApiResponse } from '../createApiResponse' -import type { UploadFileMutationRequest, UploadFileMutationResponse, UploadFilePathParams, UploadFileQueryParams } from '../../models/UploadFile' - -export function createUploadFileMutationRequest(): NonNullable { - return faker.string.alpha() -} - -export function createUploadFilePathParams(): NonNullable { - return { petId: faker.number.float({}) } -} - -export function createUploadFileQueryParams(): NonNullable { - return { additionalMetadata: faker.string.alpha() } -} -/** - * @description successful operation - */ - -export function createUploadFileMutationResponse(): NonNullable { - return createApiResponse() -} diff --git a/examples/faker/src/gen/mocks/petMocks/index.ts b/examples/faker/src/gen/mocks/petMocks/index.ts deleted file mode 100644 index 8a70942ad..000000000 --- a/examples/faker/src/gen/mocks/petMocks/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -export * from './createAddPet' -export * from './createDeletePet' -export * from './createFindPetsByStatus' -export * from './createFindPetsByTags' -export * from './createGetPetById' -export * from './createUpdatePet' -export * from './createUpdatePetWithForm' -export * from './createUploadFile' diff --git a/examples/faker/src/gen/mocks/storeMocks/createDeleteOrder.ts b/examples/faker/src/gen/mocks/storeMocks/createDeleteOrder.ts deleted file mode 100644 index c8ad5bf7e..000000000 --- a/examples/faker/src/gen/mocks/storeMocks/createDeleteOrder.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { DeleteOrder400, DeleteOrder404, DeleteOrderMutationResponse, DeleteOrderPathParams } from '../../models/DeleteOrder' - -/** - * @description Invalid ID supplied - */ - -export function createDeleteOrder400(): NonNullable { - return undefined -} -/** - * @description Order not found - */ - -export function createDeleteOrder404(): NonNullable { - return undefined -} - -export function createDeleteOrderMutationResponse(): NonNullable { - return undefined -} - -export function createDeleteOrderPathParams(): NonNullable { - return { orderId: faker.number.float({}) } -} diff --git a/examples/faker/src/gen/mocks/storeMocks/createGetInventory.ts b/examples/faker/src/gen/mocks/storeMocks/createGetInventory.ts deleted file mode 100644 index dcc95bca3..000000000 --- a/examples/faker/src/gen/mocks/storeMocks/createGetInventory.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { GetInventoryQueryResponse } from '../../models/GetInventory' - -/** - * @description successful operation - */ - -export function createGetInventoryQueryResponse(): NonNullable { - return {} -} diff --git a/examples/faker/src/gen/mocks/storeMocks/createGetOrderById.ts b/examples/faker/src/gen/mocks/storeMocks/createGetOrderById.ts deleted file mode 100644 index 81404fcec..000000000 --- a/examples/faker/src/gen/mocks/storeMocks/createGetOrderById.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createOrder } from '../createOrder' -import type { GetOrderById400, GetOrderById404, GetOrderByIdPathParams, GetOrderByIdQueryResponse } from '../../models/GetOrderById' - -/** - * @description Invalid ID supplied - */ - -export function createGetOrderById400(): NonNullable { - return undefined -} -/** - * @description Order not found - */ - -export function createGetOrderById404(): NonNullable { - return undefined -} - -export function createGetOrderByIdPathParams(): NonNullable { - return { orderId: faker.number.float({}) } -} -/** - * @description successful operation - */ - -export function createGetOrderByIdQueryResponse(): NonNullable { - return createOrder() -} diff --git a/examples/faker/src/gen/mocks/storeMocks/createPlaceOrder.ts b/examples/faker/src/gen/mocks/storeMocks/createPlaceOrder.ts deleted file mode 100644 index 063ae3d3d..000000000 --- a/examples/faker/src/gen/mocks/storeMocks/createPlaceOrder.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { createOrder } from '../createOrder' -import type { PlaceOrder405, PlaceOrderMutationRequest, PlaceOrderMutationResponse } from '../../models/PlaceOrder' - -/** - * @description Invalid input - */ - -export function createPlaceOrder405(): NonNullable { - return undefined -} - -export function createPlaceOrderMutationRequest(): NonNullable { - return createOrder() -} -/** - * @description successful operation - */ - -export function createPlaceOrderMutationResponse(): NonNullable { - return createOrder() -} diff --git a/examples/faker/src/gen/mocks/storeMocks/index.ts b/examples/faker/src/gen/mocks/storeMocks/index.ts deleted file mode 100644 index 4caf9d2c8..000000000 --- a/examples/faker/src/gen/mocks/storeMocks/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './createDeleteOrder' -export * from './createGetInventory' -export * from './createGetOrderById' -export * from './createPlaceOrder' diff --git a/examples/faker/src/gen/mocks/userMocks/createCreateUser.ts b/examples/faker/src/gen/mocks/userMocks/createCreateUser.ts deleted file mode 100644 index d414a9fdb..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createCreateUser.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { createUser } from '../createUser' -import type { CreateUserError, CreateUserMutationRequest, CreateUserMutationResponse } from '../../models/CreateUser' - -export function createCreateUserMutationResponse(): NonNullable { - return undefined -} -/** - * @description successful operation - */ - -export function createCreateUserError(): NonNullable { - return createUser() -} -/** - * @description Created user object - */ - -export function createCreateUserMutationRequest(): NonNullable { - return createUser() -} diff --git a/examples/faker/src/gen/mocks/userMocks/createCreateUsersWithListInput.ts b/examples/faker/src/gen/mocks/userMocks/createCreateUsersWithListInput.ts deleted file mode 100644 index 8c486eafd..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createCreateUsersWithListInput.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createUser } from '../createUser' -import type { - CreateUsersWithListInputError, - CreateUsersWithListInputMutationRequest, - CreateUsersWithListInputMutationResponse, -} from '../../models/CreateUsersWithListInput' - -/** - * @description successful operation - */ - -export function createCreateUsersWithListInputError(): NonNullable { - return undefined -} - -export function createCreateUsersWithListInputMutationRequest(): NonNullable { - return faker.helpers.arrayElements([createUser()]) as any -} -/** - * @description Successful operation - */ - -export function createCreateUsersWithListInputMutationResponse(): NonNullable { - return createUser() -} diff --git a/examples/faker/src/gen/mocks/userMocks/createDeleteUser.ts b/examples/faker/src/gen/mocks/userMocks/createDeleteUser.ts deleted file mode 100644 index 87f7bc09c..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createDeleteUser.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { DeleteUser400, DeleteUser404, DeleteUserMutationResponse, DeleteUserPathParams } from '../../models/DeleteUser' - -/** - * @description Invalid username supplied - */ - -export function createDeleteUser400(): NonNullable { - return undefined -} -/** - * @description User not found - */ - -export function createDeleteUser404(): NonNullable { - return undefined -} - -export function createDeleteUserMutationResponse(): NonNullable { - return undefined -} - -export function createDeleteUserPathParams(): NonNullable { - return { username: faker.string.alpha() } -} diff --git a/examples/faker/src/gen/mocks/userMocks/createGetUserByName.ts b/examples/faker/src/gen/mocks/userMocks/createGetUserByName.ts deleted file mode 100644 index 9bcc503b8..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createGetUserByName.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createUser } from '../createUser' -import type { GetUserByName400, GetUserByName404, GetUserByNamePathParams, GetUserByNameQueryResponse } from '../../models/GetUserByName' - -/** - * @description Invalid username supplied - */ - -export function createGetUserByName400(): NonNullable { - return undefined -} -/** - * @description User not found - */ - -export function createGetUserByName404(): NonNullable { - return undefined -} - -export function createGetUserByNamePathParams(): NonNullable { - return { username: faker.string.alpha() } -} -/** - * @description successful operation - */ - -export function createGetUserByNameQueryResponse(): NonNullable { - return createUser() -} diff --git a/examples/faker/src/gen/mocks/userMocks/createLoginUser.ts b/examples/faker/src/gen/mocks/userMocks/createLoginUser.ts deleted file mode 100644 index 470c3689a..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createLoginUser.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { faker } from '@faker-js/faker' -import type { LoginUser400, LoginUserQueryParams, LoginUserQueryResponse } from '../../models/LoginUser' - -/** - * @description Invalid username/password supplied - */ - -export function createLoginUser400(): NonNullable { - return undefined -} - -export function createLoginUserQueryParams(): NonNullable { - return { username: faker.string.alpha(), password: faker.internet.password() } -} -/** - * @description successful operation - */ - -export function createLoginUserQueryResponse(): NonNullable { - return faker.string.alpha() -} diff --git a/examples/faker/src/gen/mocks/userMocks/createLogoutUser.ts b/examples/faker/src/gen/mocks/userMocks/createLogoutUser.ts deleted file mode 100644 index 2a019abdf..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createLogoutUser.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { LogoutUserError, LogoutUserQueryResponse } from '../../models/LogoutUser' - -/** - * @description successful operation - */ - -export function createLogoutUserError(): NonNullable { - return undefined -} - -export function createLogoutUserQueryResponse(): NonNullable { - return undefined -} diff --git a/examples/faker/src/gen/mocks/userMocks/createUpdateUser.ts b/examples/faker/src/gen/mocks/userMocks/createUpdateUser.ts deleted file mode 100644 index 77b20ec93..000000000 --- a/examples/faker/src/gen/mocks/userMocks/createUpdateUser.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { faker } from '@faker-js/faker' -import { createUser } from '../createUser' -import type { UpdateUserError, UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from '../../models/UpdateUser' - -/** - * @description successful operation - */ - -export function createUpdateUserError(): NonNullable { - return undefined -} - -export function createUpdateUserMutationResponse(): NonNullable { - return undefined -} - -export function createUpdateUserPathParams(): NonNullable { - return { username: faker.string.alpha() } -} -/** - * @description Update an existent user in the store - */ - -export function createUpdateUserMutationRequest(): NonNullable { - return createUser() -} diff --git a/examples/faker/src/gen/mocks/userMocks/index.ts b/examples/faker/src/gen/mocks/userMocks/index.ts deleted file mode 100644 index 00cb84b9a..000000000 --- a/examples/faker/src/gen/mocks/userMocks/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './createCreateUser' -export * from './createCreateUsersWithListInput' -export * from './createDeleteUser' -export * from './createGetUserByName' -export * from './createLoginUser' -export * from './createLogoutUser' -export * from './createUpdateUser' diff --git a/examples/faker/src/gen/models/Address.ts b/examples/faker/src/gen/models/Address.ts index ac07478d9..a6547ed5b 100644 --- a/examples/faker/src/gen/models/Address.ts +++ b/examples/faker/src/gen/models/Address.ts @@ -22,5 +22,9 @@ export type Address = { /** * @type array | undefined */ - identifier?: [number, string, 'NW' | 'NE' | 'SW' | 'SE'] + identifier?: [ + number, + string, + 'NW' | 'NE' | 'SW' | 'SE', + ] } diff --git a/examples/faker/src/gen/models/FindPetsByStatus.ts b/examples/faker/src/gen/models/FindPetsByStatus.ts index a1659b564..ee89e038f 100644 --- a/examples/faker/src/gen/models/FindPetsByStatus.ts +++ b/examples/faker/src/gen/models/FindPetsByStatus.ts @@ -6,9 +6,9 @@ import type { Pet } from './Pet' export type FindPetsByStatus400 = any | null export const findPetsByStatusQueryParamsStatus = { - available: 'available', - pending: 'pending', - sold: 'sold', + 'available': 'available', + 'pending': 'pending', + 'sold': 'sold', } as const export type FindPetsByStatusQueryParamsStatus = (typeof findPetsByStatusQueryParamsStatus)[keyof typeof findPetsByStatusQueryParamsStatus] export type FindPetsByStatusQueryParams = { diff --git a/examples/faker/src/gen/models/Order.ts b/examples/faker/src/gen/models/Order.ts index 5fde35d45..1c685ff06 100644 --- a/examples/faker/src/gen/models/Order.ts +++ b/examples/faker/src/gen/models/Order.ts @@ -1,7 +1,7 @@ export const orderStatus = { - placed: 'placed', - approved: 'approved', - delivered: 'delivered', + 'placed': 'placed', + 'approved': 'approved', + 'delivered': 'delivered', } as const export type OrderStatus = (typeof orderStatus)[keyof typeof orderStatus] export type Order = { diff --git a/examples/faker/src/gen/models/Pet.ts b/examples/faker/src/gen/models/Pet.ts index afc67d382..2655333aa 100644 --- a/examples/faker/src/gen/models/Pet.ts +++ b/examples/faker/src/gen/models/Pet.ts @@ -2,9 +2,9 @@ import type { Category } from './Category' import type { Tag } from './Tag' export const petStatus = { - available: 'available', - pending: 'pending', - sold: 'sold', + 'available': 'available', + 'pending': 'pending', + 'sold': 'sold', } as const export type PetStatus = (typeof petStatus)[keyof typeof petStatus] export type Pet = { diff --git a/packages/core/src/PluginManager.ts b/packages/core/src/PluginManager.ts index 823c81f70..b3c918a5c 100644 --- a/packages/core/src/PluginManager.ts +++ b/packages/core/src/PluginManager.ts @@ -129,7 +129,7 @@ export class PluginManager { parameters: [params.baseName, params.directory, params.options as object], }) - if (paths && paths?.length > 1) { + if (paths && paths?.length > 1 && this.logger.logLevel === LogLevel.debug) { this.logger.warn( `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough\n\nPaths: ${ JSON.stringify(paths, undefined, 2) @@ -153,7 +153,7 @@ export class PluginManager { parameters: [params.name, params.type], }) - if (names && names?.length > 1) { + if (names && names?.length > 1 && this.logger.logLevel === LogLevel.debug) { this.logger.warn( `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough\n\nNames: ${ JSON.stringify(names, undefined, 2) @@ -379,7 +379,7 @@ export class PluginManager { const plugins = [...this.plugins].filter((plugin) => plugin.name !== 'core') if (hookName) { - if (this.logger.logLevel === 'info') { + if (this.logger.logLevel === LogLevel.info) { const containsHookName = plugins.some((item) => item[hookName]) if (!containsHookName) { this.logger.warn(`No hook ${hookName} found`) @@ -435,7 +435,7 @@ export class PluginManager { const corePlugin = plugins.find((plugin) => plugin.name === 'core' && plugin[hookName]) - if (this.logger.logLevel === 'info') { + if (this.logger.logLevel === LogLevel.debug) { if (corePlugin) { this.logger.warn(`No hook '${hookName}' for pluginKey '${JSON.stringify(pluginKey)}' found, falling back on the '@kubb/core' plugin`) } else { diff --git a/packages/core/src/build.ts b/packages/core/src/build.ts index 3b4ee136f..f08ed4af9 100644 --- a/packages/core/src/build.ts +++ b/packages/core/src/build.ts @@ -116,7 +116,7 @@ async function setup(options: BuildOptions): Promise { logger.spinner.start(`💾 Writing`) } - if (logger.logLevel === 'debug') { + if (logger.logLevel === LogLevel.debug) { logger.info(`PluginKey ${pc.dim(JSON.stringify(plugin.key))} \nwith source\n\n${code}`) } } diff --git a/packages/swagger-faker/src/fakerParser.ts b/packages/swagger-faker/src/fakerParser.ts index 9ea8a1eb1..493f23141 100644 --- a/packages/swagger-faker/src/fakerParser.ts +++ b/packages/swagger-faker/src/fakerParser.ts @@ -207,7 +207,7 @@ export function parseFakerMeta(item: FakerMeta, mapper: Record string - schema?: (schema: OasTypes.SchemaObject | undefined, baseName?: string) => FakerMeta[] + schema?: (schema: OasTypes.SchemaObject | undefined, baseName?: string) => FakerMeta[] | undefined } mapper?: Record } diff --git a/packages/swagger-zod/src/zodParser.ts b/packages/swagger-zod/src/zodParser.ts index 73a9f4b94..a02843f96 100644 --- a/packages/swagger-zod/src/zodParser.ts +++ b/packages/swagger-zod/src/zodParser.ts @@ -245,7 +245,7 @@ export function parseZodMeta(item: ZodMeta, mapper: Record = return '' } - if (keyword in zodKeywords) { + if (keyword in mapper) { return `${value}(${args as string})` } diff --git a/packages/swagger/src/utils/getGroupedByTagFiles.ts b/packages/swagger/src/utils/getGroupedByTagFiles.ts index 32c82b355..eed2232cf 100644 --- a/packages/swagger/src/utils/getGroupedByTagFiles.ts +++ b/packages/swagger/src/utils/getGroupedByTagFiles.ts @@ -2,7 +2,7 @@ import path from 'node:path' import { FileManager } from '@kubb/core' import transformers from '@kubb/core/transformers' -import { getRelativePath, renderTemplate } from '@kubb/core/utils' +import { LogLevel, getRelativePath, renderTemplate } from '@kubb/core/utils' import type { KubbFile, KubbPlugin } from '@kubb/core' import type { Logger } from '@kubb/core/utils' @@ -49,7 +49,9 @@ export function getGroupedByTagFiles({ }) .map((file: KubbFile.File) => { if (!file.meta?.tag) { - logger?.warn(`Could not find a tagName for ${JSON.stringify(file, undefined, 2)}`) + if (logger?.logLevel === LogLevel.debug) { + logger?.warn(`Could not find a tagName for ${JSON.stringify(file, undefined, 2)}`) + } return }