Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Nov 24, 2023
1 parent 56e6857 commit 25dbb0c
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 218 deletions.
1 change: 1 addition & 0 deletions configs/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default defineConfig({
'@kubb/eslint-config': 'packages/config/eslint/src/index.ts',
'@kubb/tsup-config': 'packages/config/tsup/src/index.ts',
'@kubb/core/utils': 'packages/core/src/utils/index.ts',
'@kubb/core/transformers': 'packages/core/src/transformers/index.ts',
'@kubb/core': 'packages/core/src/index.ts',
'@kubb/swagger/utils': 'packages/swagger/src/utils/index.ts',
'@kubb/swagger/hooks': 'packages/swagger/src/hooks/index.ts',
Expand Down
142 changes: 7 additions & 135 deletions examples/advanced/src/gen/zodios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
createPetsMutationResponseSchema,
createPetsPathParamsSchema,
createPetsQueryParamsSchema,
createPetsMutationRequestSchema,
createPetsHeaderParamsSchema,
createPetsMutationRequestSchema,
createPets201Schema,
} from './zod/petsController/createPetsSchema'
import { addPetMutationResponseSchema, addPetMutationRequestSchema, addPet405Schema } from './zod/petController/addPetSchema'
Expand Down Expand Up @@ -41,25 +41,6 @@ import {
uploadFileQueryParamsSchema,
uploadFileMutationRequestSchema,
} from './zod/petController/uploadFileSchema'
import { getInventoryQueryResponseSchema } from './zod/storeController/getInventorySchema'
import { placeOrderMutationResponseSchema, placeOrderMutationRequestSchema, placeOrder405Schema } from './zod/storeController/placeOrderSchema'
import {
placeOrderPatchMutationResponseSchema,
placeOrderPatchMutationRequestSchema,
placeOrderPatch405Schema,
} from './zod/storeController/placeOrderPatchSchema'
import {
getOrderByIdQueryResponseSchema,
getOrderByIdPathParamsSchema,
getOrderById400Schema,
getOrderById404Schema,
} from './zod/storeController/getOrderByIdSchema'
import {
deleteOrderMutationResponseSchema,
deleteOrderPathParamsSchema,
deleteOrder400Schema,
deleteOrder404Schema,
} from './zod/storeController/deleteOrderSchema'
import { createUserMutationResponseSchema, createUserMutationRequestSchema } from './zod/userController/createUserSchema'
import {
createUsersWithListInputMutationResponseSchema,
Expand Down Expand Up @@ -95,18 +76,18 @@ const endpoints = makeApi([
type: 'Query',
schema: createPetsQueryParamsSchema.shape['offset'],
},
{
name: 'CreatePetsMutationRequest',
description: ``,
type: 'Body',
schema: createPetsMutationRequestSchema,
},
{
name: 'X-EXAMPLE',
description: `Header parameters`,
type: 'Header',
schema: createPetsHeaderParamsSchema.shape['X-EXAMPLE'],
},
{
name: 'CreatePetsMutationRequest',
description: ``,
type: 'Body',
schema: createPetsMutationRequestSchema,
},
],
response: createPetsMutationResponseSchema,
errors: [
Expand Down Expand Up @@ -350,113 +331,6 @@ const endpoints = makeApi([
response: uploadFileMutationResponseSchema,
errors: [],
},
{
method: 'get',
path: '/store/inventory',
description: `Returns a map of status codes to quantities`,
requestFormat: 'json',
parameters: [],
response: getInventoryQueryResponseSchema,
errors: [],
},
{
method: 'post',
path: '/store/order',
description: `Place a new order in the store`,
requestFormat: 'json',
parameters: [
{
name: 'PlaceOrderMutationRequest',
description: ``,
type: 'Body',
schema: placeOrderMutationRequestSchema,
},
],
response: placeOrderMutationResponseSchema,
errors: [
{
status: 405,
description: `Invalid input`,
schema: placeOrder405Schema,
},
],
},
{
method: 'patch',
path: '/store/order',
description: `Place a new order in the store with patch`,
requestFormat: 'json',
parameters: [
{
name: 'PlaceOrderPatchMutationRequest',
description: ``,
type: 'Body',
schema: placeOrderPatchMutationRequestSchema,
},
],
response: placeOrderPatchMutationResponseSchema,
errors: [
{
status: 405,
description: `Invalid input`,
schema: placeOrderPatch405Schema,
},
],
},
{
method: 'get',
path: '/store/order/:orderId',
description: `For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.`,
requestFormat: 'json',
parameters: [
{
name: 'orderId',
description: `ID of order that needs to be fetched`,
type: 'Path',
schema: getOrderByIdPathParamsSchema.shape['orderId'],
},
],
response: getOrderByIdQueryResponseSchema,
errors: [
{
status: 400,
description: `Invalid ID supplied`,
schema: getOrderById400Schema,
},
{
status: 404,
description: `Order not found`,
schema: getOrderById404Schema,
},
],
},
{
method: 'delete',
path: '/store/order/:orderId',
description: `For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors`,
requestFormat: 'json',
parameters: [
{
name: 'orderId',
description: `ID of the order that needs to be deleted`,
type: 'Path',
schema: deleteOrderPathParamsSchema.shape['orderId'],
},
],
response: deleteOrderMutationResponseSchema,
errors: [
{
status: 400,
description: `Invalid ID supplied`,
schema: deleteOrder400Schema,
},
{
status: 404,
description: `Order not found`,
schema: deleteOrder404Schema,
},
],
},
{
method: 'post',
path: '/user',
Expand Down Expand Up @@ -603,7 +477,5 @@ const endpoints = makeApi([
],
},
])

export const api = new Zodios('https://petstore3.swagger.io/api/v3', endpoints)

export default api
2 changes: 0 additions & 2 deletions examples/simple-single/src/gen/models.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Category, Tag, Address, User, Pet, AddPetRequest, ApiResponse, Order } from './'

export type Address = {
/**
* @type string | undefined
Expand Down
2 changes: 0 additions & 2 deletions examples/typescript/src/gen/models.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Category, Tag, Address, User, Pet, AddPetRequest, ApiResponse, Order } from './'

export type Address = {
/**
* @type string | undefined
Expand Down
2 changes: 0 additions & 2 deletions examples/typescript/src/gen/modelsConst.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Category, Tag, Address, User, Pet, AddPetRequest, ApiResponse, Order } from './models'

export type Address = {
/**
* @type string | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default defineConfig([
{
...optionsCJS,
entry: {
utils: 'src/transformers/index.ts',
transformers: 'src/transformers/index.ts',
},
name: 'transformers',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/swagger-faker/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {

if (mode === 'file') {
const resolvedPath = this.resolvePath({ baseName: '', pluginKey: this.plugin.key })
const { source, imports = [] } = builder.build()
const { source } = builder.build()

if (!resolvedPath) {
return
Expand All @@ -123,7 +123,6 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
baseName: output as KubbFile.BaseName,
source,
imports: [
...imports.map(item => ({ ...item, root: resolvedPath })),
{
name: ['faker'],
path: '@faker-js/faker',
Expand Down
2 changes: 1 addition & 1 deletion packages/swagger-msw/src/OperationGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class OperationGenerator extends Generator<PluginOptions['resolvedOptions

const root = createRoot<AppContextProps>({ logger: pluginManager.logger })

root.render(<Handlers.File name="handelers" paths={paths} templates={this.options.templates.handlers} />, { meta: { oas, pluginManager, plugin } })
root.render(<Handlers.File name="handlers" paths={paths} templates={this.options.templates.handlers} />, { meta: { oas, pluginManager, plugin } })

return root.files
}
Expand Down
2 changes: 1 addition & 1 deletion packages/swagger-swr/src/components/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function Query({
const schemas = useSchemas()
const name = useOperationName({ type: 'function' })

const queryOptionsName = useResolveName({ name: `${factory.name}QueryOptions`, pluginKey, type: 'function' })
const queryOptionsName = useResolveName({ name: `${factory.name}QueryOptions`, pluginKey })
const generics = new FunctionParams()
const params = new FunctionParams()
const queryParams = new FunctionParams()
Expand Down
2 changes: 1 addition & 1 deletion packages/swagger-swr/src/components/QueryOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function QueryOptions({ factory, dataReturnType, Template = defaultTempla
const schemas = useSchemas()
const operation = useOperation()

const name = useResolveName({ name: `${factory.name}QueryOptions`, pluginKey, type: 'function' })
const name = useResolveName({ name: `${factory.name}QueryOptions`, pluginKey })

const generics = new FunctionParams()
const params = new FunctionParams()
Expand Down
6 changes: 2 additions & 4 deletions packages/swagger-tanstack-query/src/components/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const defaultTemplates = {
const optionsType = infinite ? importNames.queryInfinite.vue.optionsType : importNames.query.vue.optionsType

const schemas = useSchemas()
const queryOptions = useResolveName({ name: `${factory.name}QueryOptions`, pluginKey, type: 'function' })
const queryOptions = useResolveName({ name: `${factory.name}QueryOptions`, pluginKey })
const params = new FunctionParams()
const queryParams = new FunctionParams()
const client = {
Expand Down Expand Up @@ -264,7 +264,6 @@ export function Query({
const queryKey = useResolveName({
name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryKey'].filter(Boolean).join(''),
pluginKey,
type: 'function',
})
const queryKeyType = useResolveName({
name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryKey'].filter(Boolean).join(''),
Expand All @@ -273,7 +272,6 @@ export function Query({
})
const queryOptions = useResolveName({
name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryOptions'].filter(Boolean).join(''),
type: 'function',
pluginKey,
})

Expand Down Expand Up @@ -364,7 +362,7 @@ export function Query({

return (
<>
<QueryKey Template={QueryKeyTemplate} factory={factory} name={queryKey} />
<QueryKey Template={QueryKeyTemplate} factory={factory} name={queryKey} typeName={queryKeyType} />
<QueryOptions Template={QueryOptionsTemplate} factory={factory} resultType={optionsType} infinite={infinite} suspense={suspense} />
<Template
name={[name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined].filter(Boolean).join('')}
Expand Down
12 changes: 8 additions & 4 deletions packages/swagger-tanstack-query/src/components/QueryKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ type TemplateProps = {
* Name of the function
*/
name: string
/**
* TypeName of the function in PascalCase
*/
typeName: string
/**
* Parameters/options/props that need to be used
*/
Expand All @@ -34,14 +38,13 @@ type TemplateProps = {

function Template({
name,
typeName,
params,
generics,
returnType,
JSDoc,
keys,
}: TemplateProps): ReactNode {
const typeName = transformers.pascalCase(name)

return (
<>
<Function.Arrow name={name} export generics={generics} params={params} returnType={returnType} singleLine JSDoc={JSDoc}>
Expand Down Expand Up @@ -132,6 +135,7 @@ const defaultTemplates = {

type Props = {
name: string
typeName: string
factory: {
name: string
}
Expand All @@ -141,7 +145,7 @@ type Props = {
Template?: React.ComponentType<FrameworkProps>
}

export function QueryKey({ name, factory, Template = defaultTemplates.react }: Props): ReactNode {
export function QueryKey({ name, typeName, factory, Template = defaultTemplates.react }: Props): ReactNode {
const schemas = useSchemas()
const operation = useOperation()
const path = new URLPath(operation.path)
Expand All @@ -168,7 +172,7 @@ export function QueryKey({ name, factory, Template = defaultTemplates.react }: P
withQueryParams ? `...(params ? [params] : [])` : undefined,
].filter(Boolean)

return <Template name={name} params={params.toString()} keys={keys.join(', ')} context={{ factory }} />
return <Template typeName={typeName} name={name} params={params.toString()} keys={keys.join(', ')} context={{ factory }} />
}

QueryKey.templates = defaultTemplates
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ export function QueryOptions({ factory, infinite, suspense, resultType, Template

const queryKey = useResolveName({
name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryKey'].filter(Boolean).join(''),
type: 'function',
pluginKey,
})
const queryKeyType = useResolveName({
Expand All @@ -261,7 +260,6 @@ export function QueryOptions({ factory, infinite, suspense, resultType, Template
})
const queryOptions = useResolveName({
name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryOptions'].filter(Boolean).join(''),
type: 'function',
pluginKey,
})

Expand Down
8 changes: 4 additions & 4 deletions packages/swagger-ts/src/OperationGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ export class OperationGenerator extends Generator<PluginOptions['resolvedOptions
}

async get(operation: Operation, schemas: OperationSchemas, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
const { oas, pluginManager, plugin } = this.context
const { oas, pluginManager, plugin, mode = 'directory' } = this.context

const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
root.render(
<Query.File />,
<Query.File mode={mode} />,
{ meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } },
)

return root.files
}

async post(operation: Operation, schemas: OperationSchemas, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
const { oas, pluginManager, plugin } = this.context
const { oas, pluginManager, plugin, mode = 'directory' } = this.context

const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
root.render(
<Mutation.File />,
<Mutation.File mode={mode} />,
{ meta: { oas, pluginManager, plugin: { ...plugin, options }, schemas, operation } },
)

Expand Down
Loading

0 comments on commit 25dbb0c

Please sign in to comment.