Skip to content

Commit

Permalink
chore: use of SchemaGenerator for FakerGenerator (#869)
Browse files Browse the repository at this point in the history
* fix: use of `SchemaGenerator` for `ZodGenerator`

* chore: extra checks for e2e

* chore: use of `SchemaGenerator` for `FakerGenerator`

* chore: cleanup

* chore: update examples

* chore: cleanup stringify and regex

* chore: cleanup

* chore: fix number
  • Loading branch information
stijnvanhulle authored Mar 18, 2024
1 parent 69b9e86 commit a856942
Show file tree
Hide file tree
Showing 128 changed files with 654 additions and 734 deletions.
4 changes: 2 additions & 2 deletions examples/advanced/src/gen/mocks/createAddPetRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type { AddPetRequest } from '../models/ts/AddPetRequest'
export function createAddPetRequest(override: NonNullable<Partial<AddPetRequest>> = {}): NonNullable<AddPetRequest> {
return {
...{
'id': faker.number.int({}),
'id': faker.number.int(),
'name': faker.string.alpha(),
'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<any>(['available', 'pending', 'sold']),
},
...override,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createApiResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ApiResponse } from '../models/ts/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.string.alpha() },
...override,
}
}
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Category } from '../models/ts/Category'

export function createCategory(override: NonNullable<Partial<Category>> = {}): NonNullable<Category> {
return {
...{ 'id': faker.number.int({}), 'name': faker.string.alpha() },
...{ 'id': faker.number.int(), 'name': faker.string.alpha() },
...override,
}
}
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createCustomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Customer } from '../models/ts/Customer'

export function createCustomer(override: NonNullable<Partial<Customer>> = {}): NonNullable<Customer> {
return {
...{ 'id': faker.number.int({}), 'username': faker.string.alpha(), 'address': faker.helpers.arrayElements([createAddress()]) as any },
...{ 'id': faker.number.int(), 'username': faker.string.alpha(), 'address': faker.helpers.arrayElements([createAddress()]) as any },
...override,
}
}
12 changes: 6 additions & 6 deletions examples/advanced/src/gen/mocks/createOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type { Order } from '../models/ts/Order'
export function createOrder(override: NonNullable<Partial<Order>> = {}): NonNullable<Order> {
return {
...{
'id': faker.number.int({}),
'petId': faker.number.int({}),
'quantity': faker.number.int({}),
'orderType': faker.helpers.arrayElement<any>([`foo`, `bar`]),
'id': faker.number.int(),
'petId': faker.number.int(),
'quantity': faker.number.int(),
'orderType': faker.helpers.arrayElement<any>(['foo', 'bar']),
'type': faker.string.alpha(),
'shipDate': faker.date.anytime(),
'status': faker.helpers.arrayElement<any>([`placed`, `approved`, `delivered`]),
'http_status': faker.helpers.arrayElement<any>([`ok`, `not_found`]),
'status': faker.helpers.arrayElement<any>(['placed', 'approved', 'delivered']),
'http_status': faker.helpers.arrayElement(['ok', 'not_found']) as any,
'complete': faker.datatype.boolean(),
},
...override,
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/src/gen/mocks/createPet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type { Pet } from '../models/ts/Pet'
export function createPet(override: NonNullable<Partial<Pet>> = {}): NonNullable<Pet> {
return {
...{
'id': faker.number.int({}),
'id': faker.number.int(),
'name': faker.string.alpha(),
'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<any>(['available', 'pending', 'sold']),
},
...override,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/createPetNotFound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PetNotFound } from '../models/ts/PetNotFound'

export function createPetNotFound(override: NonNullable<Partial<PetNotFound>> = {}): NonNullable<PetNotFound> {
return {
...{ 'code': faker.number.int({}), 'message': faker.string.alpha() },
...{ 'code': faker.number.int(), 'message': faker.string.alpha() },
...override,
}
}
14 changes: 7 additions & 7 deletions examples/advanced/src/gen/mocks/createUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type { User } from '../models/ts/User'
export function createUser(override: NonNullable<Partial<User>> = {}): NonNullable<User> {
return {
...{
'id': faker.number.int({}),
'id': faker.number.int(),
'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.int({}),
'firstName': faker.string.alpha(),
'lastName': faker.string.alpha(),
'email': faker.string.alpha(),
'password': faker.string.alpha(),
'phone': faker.string.alpha(),
'userStatus': faker.number.int(),
},
...override,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { AddPet200, AddPet405, AddPetMutationRequest, AddPetMutationRespons

export function createAddPet405(override: NonNullable<Partial<AddPet405>> = {}): NonNullable<AddPet405> {
return {
...{ 'code': faker.number.int({}), 'message': faker.string.alpha() },
...{ 'code': faker.number.int(), 'message': faker.string.alpha() },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createDeletePetMutationResponse(override?: NonNullable<Partial<D

export function createDeletePetPathParams(override: NonNullable<Partial<DeletePetPathParams>> = {}): NonNullable<DeletePetPathParams> {
return {
...{ 'petId': faker.number.int({}) },
...{ 'petId': faker.number.int() },
...override,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function createFindPetsByStatus400(override?: NonNullable<Partial<FindPet

export function createFindPetsByStatusQueryParams(override: NonNullable<Partial<FindPetsByStatusQueryParams>> = {}): NonNullable<FindPetsByStatusQueryParams> {
return {
...{ 'status': faker.helpers.arrayElement<any>([`available`, `pending`, `sold`]) },
...{ 'status': faker.helpers.arrayElement<any>(['available', 'pending', 'sold']) },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createFindPetsByTags400(override?: NonNullable<Partial<FindPetsB

export function createFindPetsByTagsHeaderParams(override: NonNullable<Partial<FindPetsByTagsHeaderParams>> = {}): NonNullable<FindPetsByTagsHeaderParams> {
return {
...{ 'X-EXAMPLE': faker.helpers.arrayElement<any>([`ONE`, `TWO`, `THREE`]) },
...{ 'X-EXAMPLE': faker.helpers.arrayElement<any>(['ONE', 'TWO', 'THREE']) },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function createGetPetById404(override?: NonNullable<Partial<GetPetById404

export function createGetPetByIdPathParams(override: NonNullable<Partial<GetPetByIdPathParams>> = {}): NonNullable<GetPetByIdPathParams> {
return {
...{ 'petId': faker.number.int({}) },
...{ 'petId': faker.number.int() },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function createUpdatePetWithFormMutationResponse(

export function createUpdatePetWithFormPathParams(override: NonNullable<Partial<UpdatePetWithFormPathParams>> = {}): NonNullable<UpdatePetWithFormPathParams> {
return {
...{ 'petId': faker.number.int({}) },
...{ 'petId': faker.number.int() },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createUploadFileMutationRequest(override?: NonNullable<Partial<U

export function createUploadFilePathParams(override: NonNullable<Partial<UploadFilePathParams>> = {}): NonNullable<UploadFilePathParams> {
return {
...{ 'petId': faker.number.int({}) },
...{ 'petId': faker.number.int() },
...override,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function createCreatePets201(override?: NonNullable<Partial<CreatePets201

export function createCreatePetsHeaderParams(override: NonNullable<Partial<CreatePetsHeaderParams>> = {}): NonNullable<CreatePetsHeaderParams> {
return {
...{ 'X-EXAMPLE': faker.helpers.arrayElement<any>([`ONE`, `TWO`, `THREE`]) },
...{ 'X-EXAMPLE': faker.helpers.arrayElement<any>(['ONE', 'TWO', 'THREE']) },
...override,
}
}
Expand All @@ -45,7 +45,7 @@ export function createCreatePetsPathParams(override: NonNullable<Partial<CreateP

export function createCreatePetsQueryParams(override: NonNullable<Partial<CreatePetsQueryParams>> = {}): NonNullable<CreatePetsQueryParams> {
return {
...{ 'offset': faker.number.int({}) },
...{ 'offset': faker.number.int() },
...override,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/mocks/tag/createTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { TagTag } from '../../models/ts/tag/Tag'

export function createTagTag(override: NonNullable<Partial<TagTag>> = {}): NonNullable<TagTag> {
return {
...{ 'id': faker.number.int({}), 'name': faker.string.alpha() },
...{ 'id': faker.number.int(), 'name': faker.string.alpha() },
...override,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function createLoginUser400(override?: NonNullable<Partial<LoginUser400>>

export function createLoginUserQueryParams(override: NonNullable<Partial<LoginUserQueryParams>> = {}): NonNullable<LoginUserQueryParams> {
return {
...{ 'username': faker.string.alpha(), 'password': faker.internet.password() },
...{ 'username': faker.string.alpha(), 'password': faker.string.alpha() },
...override,
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/addPetRequestSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const addPetRequestSchema = z.object({
'category': z.lazy(() => categorySchema).optional(),
'photoUrls': z.array(z.string()),
'tags': z.array(z.lazy(() => tagTagSchema)).optional(),
'status': z.enum([`available`, `pending`, `sold`]).describe(`pet status in the store`).optional(),
'status': z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(),
}) as z.ZodType<AddPetRequest>
8 changes: 4 additions & 4 deletions examples/advanced/src/gen/zod/orderSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export const orderSchema = z.object({
'id': z.number().optional(),
'petId': z.number().optional(),
'quantity': z.number().optional(),
'orderType': z.enum([`foo`, `bar`]).optional(),
'type': z.string().describe(`Order Status`).optional(),
'orderType': z.enum(['foo', 'bar']).optional(),
'type': z.string().describe('Order Status').optional(),
'shipDate': z.date().optional(),
'status': z.enum([`placed`, `approved`, `delivered`]).describe(`Order Status`).optional(),
'http_status': z.union([z.literal(200), z.literal(400)]).describe(`HTTP Status`).optional(),
'status': z.enum(['placed', 'approved', 'delivered']).describe('Order Status').optional(),
'http_status': z.union([z.literal(200), z.literal(400)]).describe('HTTP Status').optional(),
'complete': z.boolean().optional(),
}) as z.ZodType<Order>
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import { z } from 'zod'
export const deletePet400Schema = z.any()
export const deletePetHeaderParamsSchema = z.object({ 'api_key': z.string().optional() }).optional()
export const deletePetMutationResponseSchema = z.any()
export const deletePetPathParamsSchema = z.object({ 'petId': z.number().describe(`Pet id to delete`) })
export const deletePetPathParamsSchema = z.object({ 'petId': z.number().describe('Pet id to delete') })
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { petSchema } from '../petSchema'
*/
export const findPetsByStatus400Schema = z.any()
export const findPetsByStatusQueryParamsSchema = z.object({
'status': z.enum([`available`, `pending`, `sold`]).default('available').describe(`Status values that need to be considered for filter`).optional(),
'status': z.enum(['available', 'pending', 'sold']).default('available').describe('Status values that need to be considered for filter').optional(),
}).optional()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { petSchema } from '../petSchema'
* @description Invalid tag value
*/
export const findPetsByTags400Schema = z.any()
export const findPetsByTagsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum([`ONE`, `TWO`, `THREE`]).describe(`Header parameters`) })
export const findPetsByTagsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters') })
export const findPetsByTagsQueryParamsSchema = z.object({
'tags': z.array(z.string()).describe(`Tags to filter by`).optional(),
'page': z.string().describe(`to request with required page number or pagination`).optional(),
'pageSize': z.string().describe(`to request with required page size`).optional(),
'tags': z.array(z.string()).describe('Tags to filter by').optional(),
'page': z.string().describe('to request with required page number or pagination').optional(),
'pageSize': z.string().describe('to request with required page size').optional(),
}).optional()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getPetById400Schema = z.any()
* @description Pet not found
*/
export const getPetById404Schema = z.any()
export const getPetByIdPathParamsSchema = z.object({ 'petId': z.number().describe(`ID of pet to return`) })
export const getPetByIdPathParamsSchema = z.object({ 'petId': z.number().describe('ID of pet to return') })

/**
* @description successful operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { z } from 'zod'
*/
export const updatePetWithForm405Schema = z.any()
export const updatePetWithFormMutationResponseSchema = z.any()
export const updatePetWithFormPathParamsSchema = z.object({ 'petId': z.number().describe(`ID of pet that needs to be updated`) })
export const updatePetWithFormPathParamsSchema = z.object({ 'petId': z.number().describe('ID of pet that needs to be updated') })
export const updatePetWithFormQueryParamsSchema = z.object({
'name': z.string().describe(`Name of pet that needs to be updated`).optional(),
'status': z.string().describe(`Status of pet that needs to be updated`).optional(),
'name': z.string().describe('Name of pet that needs to be updated').optional(),
'status': z.string().describe('Status of pet that needs to be updated').optional(),
}).optional()
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { z } from 'zod'
import { apiResponseSchema } from '../apiResponseSchema'

export const uploadFileMutationRequestSchema = z.string()
export const uploadFilePathParamsSchema = z.object({ 'petId': z.number().describe(`ID of pet to update`) })
export const uploadFileQueryParamsSchema = z.object({ 'additionalMetadata': z.string().describe(`Additional Metadata`).optional() }).optional()
export const uploadFilePathParamsSchema = z.object({ 'petId': z.number().describe('ID of pet to update') })
export const uploadFileQueryParamsSchema = z.object({ 'additionalMetadata': z.string().describe('Additional Metadata').optional() }).optional()

/**
* @description successful operation
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/petSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const petSchema = z.object({
'category': z.lazy(() => categorySchema).optional(),
'photoUrls': z.array(z.string()),
'tags': z.array(z.lazy(() => tagTagSchema)).optional(),
'status': z.enum([`available`, `pending`, `sold`]).describe(`pet status in the store`).optional(),
'status': z.enum(['available', 'pending', 'sold']).describe('pet status in the store').optional(),
}) as z.ZodType<Pet>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { petNotFoundSchema } from '../petNotFoundSchema'
* @description Null response
*/
export const createPets201Schema = z.any()
export const createPetsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum([`ONE`, `TWO`, `THREE`]).describe(`Header parameters`) })
export const createPetsHeaderParamsSchema = z.object({ 'X-EXAMPLE': z.enum(['ONE', 'TWO', 'THREE']).describe('Header parameters') })
export const createPetsMutationRequestSchema = z.object({ 'name': z.string(), 'tag': z.string() })
export const createPetsMutationResponseSchema = z.any()
export const createPetsPathParamsSchema = z.object({ 'uuid': z.string().describe(`UUID`) })
export const createPetsQueryParamsSchema = z.object({ 'offset': z.number().describe(`Offset`).optional() }).optional()
export const createPetsPathParamsSchema = z.object({ 'uuid': z.string().describe('UUID') })
export const createPetsQueryParamsSchema = z.object({ 'offset': z.number().describe('Offset').optional() }).optional()

/**
* @description unexpected error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const deleteUser400Schema = z.any()
*/
export const deleteUser404Schema = z.any()
export const deleteUserMutationResponseSchema = z.any()
export const deleteUserPathParamsSchema = z.object({ 'username': z.string().describe(`The name that needs to be deleted`) })
export const deleteUserPathParamsSchema = z.object({ 'username': z.string().describe('The name that needs to be deleted') })
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getUserByName400Schema = z.any()
* @description User not found
*/
export const getUserByName404Schema = z.any()
export const getUserByNamePathParamsSchema = z.object({ 'username': z.string().describe(`The name that needs to be fetched. Use user1 for testing. `) })
export const getUserByNamePathParamsSchema = z.object({ 'username': z.string().describe('The name that needs to be fetched. Use user1 for testing. ') })

/**
* @description successful operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export const loginUser200Schema = z.string()
*/
export const loginUser400Schema = z.any()
export const loginUserQueryParamsSchema = z.object({
'username': z.string().describe(`The user name for login`).optional(),
'password': z.string().describe(`The password for login in clear text`).optional(),
'username': z.string().describe('The user name for login').optional(),
'password': z.string().describe('The password for login in clear text').optional(),
}).optional()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { userSchema } from '../userSchema'
*/
export const updateUserErrorSchema = z.any()
export const updateUserMutationResponseSchema = z.any()
export const updateUserPathParamsSchema = z.object({ 'username': z.string().describe(`name that need to be deleted`) })
export const updateUserPathParamsSchema = z.object({ 'username': z.string().describe('name that need to be deleted') })

/**
* @description Update an existent user in the store
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/userSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export const userSchema = z.object({
'email': z.string().optional(),
'password': z.string().optional(),
'phone': z.string().optional(),
'userStatus': z.number().describe(`User Status`).optional(),
'userStatus': z.number().describe('User Status').optional(),
}) as z.ZodType<User>
2 changes: 1 addition & 1 deletion examples/faker/src/gen/customMocks/createAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function createAddress(override: NonNullable<Partial<Address>> = {}): Non
'city': faker.string.alpha(),
'state': faker.string.alpha(),
'zip': faker.string.alpha(),
'identifier': faker.helpers.arrayElements([faker.number.int({}), faker.string.alpha(), faker.helpers.arrayElement<any>([`NW`, `NE`, `SW`, `SE`])]) as any,
'identifier': faker.helpers.arrayElements([faker.number.int(), faker.string.alpha(), faker.helpers.arrayElement<any>(['NW', 'NE', 'SW', 'SE'])]) as any,
},
...override,
}
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.string.alpha() },
...override,
}
}
2 changes: 1 addition & 1 deletion examples/faker/src/gen/customMocks/createCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Category } from '../models/Category'

export function createCategory(override: NonNullable<Partial<Category>> = {}): NonNullable<Category> {
return {
...{ 'id': faker.number.int({}), 'name': faker.commerce.productName() },
...{ 'id': faker.number.int(), 'name': faker.commerce.productName() },
...override,
}
}
2 changes: 1 addition & 1 deletion examples/faker/src/gen/customMocks/createCustomer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Customer } from '../models/Customer'

export function createCustomer(override: NonNullable<Partial<Customer>> = {}): NonNullable<Customer> {
return {
...{ 'id': faker.number.int({}), 'username': faker.string.alpha(), 'address': faker.helpers.arrayElements([createAddress()]) as any },
...{ 'id': faker.number.int(), 'username': faker.string.alpha(), 'address': faker.helpers.arrayElements([createAddress()]) as any },
...override,
}
}
Loading

0 comments on commit a856942

Please sign in to comment.