Skip to content

Commit

Permalink
feat: use of Query and Mutation omponent for swagger-faker
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Nov 24, 2023
1 parent 4a132b1 commit 21e9376
Show file tree
Hide file tree
Showing 114 changed files with 486 additions and 667 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-needles-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/swagger-faker": minor
---

feat: use of Query and Mutation omponent for swagger-faker
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default [
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-argument': 'warn',
'unused-imports/no-unused-vars': 'off',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { faker } from '@faker-js/faker'

import { createAddPetRequest } from '../createAddPetRequest'
import { createPet } from '../createPet'
import { AddPet405 } from '../../models/ts/petController/AddPet'
import { AddPetMutationRequest } from '../../models/ts/petController/AddPet'
import { AddPetMutationResponse } from '../../models/ts/petController/AddPet'
import { AddPet405, AddPetMutationRequest, AddPetMutationResponse } from '../../models/ts/petController/AddPet'

export function createAddPet405(): NonNullable<AddPet405> {
return { 'code': faker.number.float({}), 'message': faker.string.alpha() }
}

/**
* @description Create a new pet in the store
*/

export function createAddPetMutationRequest(): NonNullable<AddPetMutationRequest> {
return createAddPetRequest()
}

/**
* @description Successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { faker } from '@faker-js/faker'

import { DeletePet400 } from '../../models/ts/petController/DeletePet'
import { DeletePetHeaderParams } from '../../models/ts/petController/DeletePet'
import { DeletePetMutationResponse } from '../../models/ts/petController/DeletePet'
import { DeletePetPathParams } from '../../models/ts/petController/DeletePet'
import { DeletePet400, DeletePetHeaderParams, DeletePetMutationResponse, DeletePetPathParams } from '../../models/ts/petController/DeletePet'

/**
* @description Invalid pet value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { faker } from '@faker-js/faker'

import { createPet } from '../createPet'
import { FindPetsByStatus400 } from '../../models/ts/petController/FindPetsByStatus'
import { FindPetsByStatusQueryParams } from '../../models/ts/petController/FindPetsByStatus'
import { FindPetsByStatusQueryResponse } from '../../models/ts/petController/FindPetsByStatus'
import { FindPetsByStatus400, FindPetsByStatusQueryParams, FindPetsByStatusQueryResponse } from '../../models/ts/petController/FindPetsByStatus'

/**
* @description Invalid status value
Expand All @@ -16,7 +13,6 @@ export function createFindPetsByStatus400(): NonNullable<FindPetsByStatus400> {
export function createFindPetsByStatusQueryParams(): NonNullable<FindPetsByStatusQueryParams> {
return { 'status': faker.helpers.arrayElement<any>([`available`, `pending`, `sold`]) }
}

/**
* @description successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { faker } from '@faker-js/faker'

import { createPet } from '../createPet'
import { FindPetsByTags400 } from '../../models/ts/petController/FindPetsByTags'
import { FindPetsByTagsHeaderParams } from '../../models/ts/petController/FindPetsByTags'
import { FindPetsByTagsQueryParams } from '../../models/ts/petController/FindPetsByTags'
import { FindPetsByTagsQueryResponse } from '../../models/ts/petController/FindPetsByTags'
import {
FindPetsByTags400,
FindPetsByTagsHeaderParams,
FindPetsByTagsQueryParams,
FindPetsByTagsQueryResponse,
} from '../../models/ts/petController/FindPetsByTags'

/**
* @description Invalid tag value
Expand All @@ -21,7 +22,6 @@ export function createFindPetsByTagsHeaderParams(): NonNullable<FindPetsByTagsHe
export function createFindPetsByTagsQueryParams(): NonNullable<FindPetsByTagsQueryParams> {
return { 'tags': faker.helpers.arrayElements([faker.string.alpha()]) as any, 'page': faker.string.alpha(), 'pageSize': faker.string.alpha() }
}

/**
* @description successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { faker } from '@faker-js/faker'

import { createPet } from '../createPet'
import { GetPetById400 } from '../../models/ts/petController/GetPetById'
import { GetPetById404 } from '../../models/ts/petController/GetPetById'
import { GetPetByIdPathParams } from '../../models/ts/petController/GetPetById'
import { GetPetByIdQueryResponse } from '../../models/ts/petController/GetPetById'
import { GetPetById400, GetPetById404, GetPetByIdPathParams, GetPetByIdQueryResponse } from '../../models/ts/petController/GetPetById'

/**
* @description Invalid ID supplied
Expand All @@ -13,7 +9,6 @@ import { GetPetByIdQueryResponse } from '../../models/ts/petController/GetPetByI
export function createGetPetById400(): NonNullable<GetPetById400> {
return undefined
}

/**
* @description Pet not found
*/
Expand All @@ -25,7 +20,6 @@ export function createGetPetById404(): NonNullable<GetPetById404> {
export function createGetPetByIdPathParams(): NonNullable<GetPetByIdPathParams> {
return { 'petId': faker.number.float({}) }
}

/**
* @description successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { createPet } from '../createPet'
import { UpdatePet400 } from '../../models/ts/petController/UpdatePet'
import { UpdatePet404 } from '../../models/ts/petController/UpdatePet'
import { UpdatePet405 } from '../../models/ts/petController/UpdatePet'
import { UpdatePetMutationRequest } from '../../models/ts/petController/UpdatePet'
import { UpdatePetMutationResponse } from '../../models/ts/petController/UpdatePet'
import { UpdatePet400, UpdatePet404, UpdatePet405, UpdatePetMutationRequest, UpdatePetMutationResponse } from '../../models/ts/petController/UpdatePet'

/**
* @description Invalid ID supplied
Expand All @@ -12,31 +8,27 @@ import { UpdatePetMutationResponse } from '../../models/ts/petController/UpdateP
export function createUpdatePet400(): NonNullable<UpdatePet400> {
return undefined
}

/**
* @description Pet not found
*/

export function createUpdatePet404(): NonNullable<UpdatePet404> {
return undefined
}

/**
* @description Validation exception
*/

export function createUpdatePet405(): NonNullable<UpdatePet405> {
return undefined
}

/**
* @description Update an existent pet in the store
*/

export function createUpdatePetMutationRequest(): NonNullable<UpdatePetMutationRequest> {
return createPet()
}

/**
* @description Successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { faker } from '@faker-js/faker'

import { UpdatePetWithForm405 } from '../../models/ts/petController/UpdatePetWithForm'
import { UpdatePetWithFormMutationResponse } from '../../models/ts/petController/UpdatePetWithForm'
import { UpdatePetWithFormPathParams } from '../../models/ts/petController/UpdatePetWithForm'
import { UpdatePetWithFormQueryParams } from '../../models/ts/petController/UpdatePetWithForm'
import {
UpdatePetWithForm405,
UpdatePetWithFormMutationResponse,
UpdatePetWithFormPathParams,
UpdatePetWithFormQueryParams,
} from '../../models/ts/petController/UpdatePetWithForm'

/**
* @description Invalid input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { faker } from '@faker-js/faker'

import { createApiResponse } from '../createApiResponse'
import { UploadFileMutationRequest } from '../../models/ts/petController/UploadFile'
import { UploadFilePathParams } from '../../models/ts/petController/UploadFile'
import { UploadFileQueryParams } from '../../models/ts/petController/UploadFile'
import { UploadFileMutationResponse } from '../../models/ts/petController/UploadFile'
import { UploadFileMutationRequest, UploadFileMutationResponse, UploadFilePathParams, UploadFileQueryParams } from '../../models/ts/petController/UploadFile'

export function createUploadFileMutationRequest(): NonNullable<UploadFileMutationRequest> {
return faker.string.alpha()
Expand All @@ -17,7 +13,6 @@ export function createUploadFilePathParams(): NonNullable<UploadFilePathParams>
export function createUploadFileQueryParams(): NonNullable<UploadFileQueryParams> {
return { 'additionalMetadata': faker.string.alpha() }
}

/**
* @description successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { faker } from '@faker-js/faker'

import { createPetNotFound } from '../createPetNotFound'
import { CreatePets201 } from '../../models/ts/petsController/CreatePets'
import { CreatePetsHeaderParams } from '../../models/ts/petsController/CreatePets'
import { CreatePetsMutationRequest } from '../../models/ts/petsController/CreatePets'
import { CreatePetsMutationResponse } from '../../models/ts/petsController/CreatePets'
import { CreatePetsPathParams } from '../../models/ts/petsController/CreatePets'
import { CreatePetsQueryParams } from '../../models/ts/petsController/CreatePets'
import { CreatePetsError } from '../../models/ts/petsController/CreatePets'
import {
CreatePets201,
CreatePetsError,
CreatePetsHeaderParams,
CreatePetsMutationRequest,
CreatePetsMutationResponse,
CreatePetsPathParams,
CreatePetsQueryParams,
} from '../../models/ts/petsController/CreatePets'

/**
* @description Null response
Expand Down Expand Up @@ -36,7 +37,6 @@ export function createCreatePetsPathParams(): NonNullable<CreatePetsPathParams>
export function createCreatePetsQueryParams(): NonNullable<CreatePetsQueryParams> {
return { 'offset': faker.number.float({}) }
}

/**
* @description unexpected error
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { createUser } from '../createUser'
import { CreateUserMutationResponse } from '../../models/ts/userController/CreateUser'
import { CreateUserError } from '../../models/ts/userController/CreateUser'
import { CreateUserMutationRequest } from '../../models/ts/userController/CreateUser'
import { CreateUserError, CreateUserMutationRequest, CreateUserMutationResponse } from '../../models/ts/userController/CreateUser'

export function createCreateUserMutationResponse(): NonNullable<CreateUserMutationResponse> {
return undefined
}

/**
* @description successful operation
*/

export function createCreateUserError(): NonNullable<CreateUserError> {
return createUser()
}

/**
* @description Created user object
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { faker } from '@faker-js/faker'

import { createUser } from '../createUser'
import { CreateUsersWithListInputError } from '../../models/ts/userController/CreateUsersWithListInput'
import { CreateUsersWithListInputMutationRequest } from '../../models/ts/userController/CreateUsersWithListInput'
import { CreateUsersWithListInputMutationResponse } from '../../models/ts/userController/CreateUsersWithListInput'
import {
CreateUsersWithListInputError,
CreateUsersWithListInputMutationRequest,
CreateUsersWithListInputMutationResponse,
} from '../../models/ts/userController/CreateUsersWithListInput'

/**
* @description successful operation
Expand All @@ -16,7 +17,6 @@ export function createCreateUsersWithListInputError(): NonNullable<CreateUsersWi
export function createCreateUsersWithListInputMutationRequest(): NonNullable<CreateUsersWithListInputMutationRequest> {
return faker.helpers.arrayElements([createUser()]) as any
}

/**
* @description Successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { faker } from '@faker-js/faker'

import { DeleteUser400 } from '../../models/ts/userController/DeleteUser'
import { DeleteUser404 } from '../../models/ts/userController/DeleteUser'
import { DeleteUserMutationResponse } from '../../models/ts/userController/DeleteUser'
import { DeleteUserPathParams } from '../../models/ts/userController/DeleteUser'
import { DeleteUser400, DeleteUser404, DeleteUserMutationResponse, DeleteUserPathParams } from '../../models/ts/userController/DeleteUser'

/**
* @description Invalid username supplied
Expand All @@ -12,7 +8,6 @@ import { DeleteUserPathParams } from '../../models/ts/userController/DeleteUser'
export function createDeleteUser400(): NonNullable<DeleteUser400> {
return undefined
}

/**
* @description User not found
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { faker } from '@faker-js/faker'

import { createUser } from '../createUser'
import { GetUserByName400 } from '../../models/ts/userController/GetUserByName'
import { GetUserByName404 } from '../../models/ts/userController/GetUserByName'
import { GetUserByNamePathParams } from '../../models/ts/userController/GetUserByName'
import { GetUserByNameQueryResponse } from '../../models/ts/userController/GetUserByName'
import { GetUserByName400, GetUserByName404, GetUserByNamePathParams, GetUserByNameQueryResponse } from '../../models/ts/userController/GetUserByName'

/**
* @description Invalid username supplied
Expand All @@ -13,7 +9,6 @@ import { GetUserByNameQueryResponse } from '../../models/ts/userController/GetUs
export function createGetUserByName400(): NonNullable<GetUserByName400> {
return undefined
}

/**
* @description User not found
*/
Expand All @@ -25,7 +20,6 @@ export function createGetUserByName404(): NonNullable<GetUserByName404> {
export function createGetUserByNamePathParams(): NonNullable<GetUserByNamePathParams> {
return { 'username': faker.string.alpha() }
}

/**
* @description successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { faker } from '@faker-js/faker'

import { LoginUser400 } from '../../models/ts/userController/LoginUser'
import { LoginUserQueryParams } from '../../models/ts/userController/LoginUser'
import { LoginUserQueryResponse } from '../../models/ts/userController/LoginUser'
import { LoginUser400, LoginUserQueryParams, LoginUserQueryResponse } from '../../models/ts/userController/LoginUser'

/**
* @description Invalid username/password supplied
Expand All @@ -15,7 +12,6 @@ export function createLoginUser400(): NonNullable<LoginUser400> {
export function createLoginUserQueryParams(): NonNullable<LoginUserQueryParams> {
return { 'username': faker.string.alpha(), 'password': faker.internet.password() }
}

/**
* @description successful operation
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { LogoutUserError } from '../../models/ts/userController/LogoutUser'
import { LogoutUserQueryResponse } from '../../models/ts/userController/LogoutUser'
import { LogoutUserError, LogoutUserQueryResponse } from '../../models/ts/userController/LogoutUser'

/**
* @description successful operation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { faker } from '@faker-js/faker'

import { createUser } from '../createUser'
import { UpdateUserError } from '../../models/ts/userController/UpdateUser'
import { UpdateUserMutationResponse } from '../../models/ts/userController/UpdateUser'
import { UpdateUserPathParams } from '../../models/ts/userController/UpdateUser'
import { UpdateUserMutationRequest } from '../../models/ts/userController/UpdateUser'
import { UpdateUserError, UpdateUserMutationRequest, UpdateUserMutationResponse, UpdateUserPathParams } from '../../models/ts/userController/UpdateUser'

/**
* @description successful operation
Expand All @@ -21,7 +17,6 @@ export function createUpdateUserMutationResponse(): NonNullable<UpdateUserMutati
export function createUpdateUserPathParams(): NonNullable<UpdateUserPathParams> {
return { 'username': faker.string.alpha() }
}

/**
* @description Update an existent user in the store
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import client from '@kubb/swagger-client/client'
import axios from 'axios'
import type { ResponseConfig } from '@kubb/swagger-client/client'
Expand Down
3 changes: 1 addition & 2 deletions examples/faker/src/gen/mocks/createAddress.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { faker } from '@faker-js/faker'

import { Address } from '../models/Address'
import { faker } from '@faker-js/faker'

export function createAddress(): NonNullable<Address> {
return {
Expand Down
3 changes: 1 addition & 2 deletions examples/faker/src/gen/mocks/createApiResponse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { faker } from '@faker-js/faker'

import { ApiResponse } from '../models/ApiResponse'
import { faker } from '@faker-js/faker'

export function createApiResponse(): NonNullable<ApiResponse> {
return { code: faker.number.float({}), type: faker.string.alpha(), message: faker.string.alpha() }
Expand Down
3 changes: 1 addition & 2 deletions examples/faker/src/gen/mocks/createCategory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { faker } from '@faker-js/faker'

import { Category } from '../models/Category'
import { faker } from '@faker-js/faker'

export function createCategory(): NonNullable<Category> {
return { id: faker.number.float({}), name: faker.string.alpha() }
Expand Down
Loading

0 comments on commit 21e9376

Please sign in to comment.