Skip to content

Commit

Permalink
feat: use of enumSuffix
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Mar 9, 2024
1 parent cdbd6f5 commit d330ff1
Show file tree
Hide file tree
Showing 78 changed files with 2,175 additions and 2,019 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-years-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kubb/swagger-ts": minor
---

use of `enumSuffix`
36 changes: 36 additions & 0 deletions docs/plugins/swagger-ts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,42 @@ export default defineConfig({

:::

### enumSuffix

Set a suffix for the generated enums.

::: info Type

::: info

Type: `string` <br/>
Default: `''`

::: code-group

```typescript
import { defineConfig } from '@kubb/core'
import createSwagger from '@kubb/swagger'
import createSwaggerTS from '@kubb/swagger-ts'

export default defineConfig({
input: {
path: './petStore.yaml',
},
output: {
path: './src/gen',
},
plugins: [
createSwagger({ output: false }),
createSwaggerTS({
enumSuffix: 'enum',
}),
],
})
```

:::

### dateType

Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
Expand Down
255 changes: 122 additions & 133 deletions examples/advanced/configs/kubb.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { defineConfig } from '@kubb/core'
import { definePlugin as swagger } from '@kubb/swagger'
import { definePlugin as swaggerTS } from '@kubb/swagger-ts'
import { definePlugin as swaggerTanstackQuery } from '@kubb/swagger-tanstack-query'
import { definePlugin as swaggerSwr } from '@kubb/swagger-swr'
import { definePlugin as swaggerClient } from '@kubb/swagger-client'
import { definePlugin as swaggerZod } from '@kubb/swagger-zod'
import { definePlugin as swaggerZodios } from '@kubb/swagger-zodios'
import { definePlugin as swaggerFaker } from '@kubb/swagger-faker'
import { definePlugin as swaggerMsw } from '@kubb/swagger-msw'

export default defineConfig(async () => {
await setTimeout(() => {
Expand All @@ -19,161 +28,141 @@ export default defineConfig(async () => {
// done: ['npx eslint --fix ./src/gen', 'prettier --write "**/*.{ts,tsx}"', 'pnpm typecheck'],
},
plugins: [
['@kubb/swagger', {
swagger({
output: {
path: 'schemas',
},
validate: true,
}],
['@kubb/swagger', {
}),
swagger({
output: {
path: 'schemas2',
},
validate: true,
}],
[
'@kubb/swagger-ts',
{
output: {
path: 'models/ts',
extName: '.js',
},
group: {
type: 'tag',
},
enumType: 'asPascalConst',
dateType: 'date',
override: [
{
type: 'operationId',
pattern: 'findPetsByStatus',
options: {
enumType: 'enum',
},
},
],
}),
swaggerTS({
output: {
path: 'models/ts',
extName: '.js',
},
],
[
'@kubb/swagger-tanstack-query',
{
output: {
path: './clients/hooks',
exportAs: 'hooks',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
override: [
{
type: 'tag',
pattern: 'pet',
options: {
infinite: {
queryParam: 'test',
},
},
},
],
group: { type: 'tag' },
client: {
importPath: '../../../../tanstack-query-client.ts',
},
infinite: {},
dataReturnType: 'full',
parser: 'zod',
group: {
type: 'tag',
},
],
[
'@kubb/swagger-swr',
{
output: {
path: './clients/swr',
exportAs: 'swrHooks',
},
exclude: [
{
type: 'tag',
pattern: 'store',
enumType: 'asPascalConst',
enumSuffix: 'enum',
dateType: 'date',
override: [
{
type: 'operationId',
pattern: 'findPetsByStatus',
options: {
enumType: 'enum',
},
],
group: { type: 'tag' },
client: {
importPath: '../../../../swr-client.ts',
},
dataReturnType: 'full',
],
}),
swaggerTanstackQuery({
output: {
path: './clients/hooks',
exportAs: 'hooks',
},
],
[
'@kubb/swagger-client',
{
output: {
path: './clients/axios',
exportAs: 'clients',
exclude: [
{
type: 'tag',
pattern: 'store',
},
exclude: [
{
type: 'tag',
pattern: 'store',
],
override: [
{
type: 'tag',
pattern: 'pet',
options: {
infinite: {
queryParam: 'test',
initialPageParam: '0',
},
},
],
group: { type: 'tag', output: './clients/axios/{{tag}}Service' },
client: {
importPath: '../../../../axios-client.ts',
},
dataReturnType: 'full',
pathParamsType: 'object',
],
group: { type: 'tag' },
client: {
importPath: '../../../../tanstack-query-client.ts',
},
],
[
'@kubb/swagger-zod',
{
output: {
path: './zod',
exportAs: 'zod',
infinite: {},
dataReturnType: 'full',
parser: 'zod',
}),
swaggerSwr({
output: {
path: './clients/swr',
exportAs: 'swrHooks',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
dateType: 'date',
typed: true,
],
group: { type: 'tag' },
client: {
importPath: '../../../../swr-client.ts',
},
],
[
'@kubb/swagger-zodios',
{
output: {
path: 'zodios.ts',
exportAs: 'zodios',
dataReturnType: 'full',
}),
swaggerClient({
output: {
path: './clients/axios',
exportAs: 'clients',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag', output: './clients/axios/{{tag}}Service' },
client: {
importPath: '../../../../axios-client.ts',
},
],
[
'@kubb/swagger-faker',
{
output: {
path: 'mocks',
exportAs: 'faker',
dataReturnType: 'full',
pathParamsType: 'object',
}),
swaggerZod({
output: {
path: './zod',
exportAs: 'zod',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
dateType: 'date',
],
group: { type: 'tag' },
dateType: 'date',
typed: true,
}),
swaggerZodios({
output: {
path: 'zodios.ts',
exportAs: 'zodios',
},
}),
swaggerFaker({
output: {
path: 'mocks',
exportAs: 'faker',
},
],
[
'@kubb/swagger-msw',
exclude: [
{
type: 'tag',
pattern: 'store',
},
],
group: { type: 'tag' },
dateType: 'date',
}),
swaggerMsw(
{
output: {
path: 'msw',
Expand All @@ -187,7 +176,7 @@ export default defineConfig(async () => {
],
group: { type: 'tag' },
},
],
),
],
}
})
9 changes: 9 additions & 0 deletions examples/advanced/petStore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,15 @@ components:
type: integer
format: int32
example: 7
orderType:
type: string
enum:
- foo
- bar
type:
type: string
description: Order Status
example: approved
shipDate:
type: string
format: date-time
Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/clients/axios/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './operations'
export * as petService from './petService/index'
export * as petsService from './petsService/index'
export * as petService from './petService/index'
export * as userService from './userService/index'
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/clients/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * as petHooks from './petController/index'
export * as petsHooks from './petsController/index'
export * as petHooks from './petController/index'
export * as userHooks from './userController/index'
6 changes: 3 additions & 3 deletions examples/advanced/src/gen/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * as clients from './clients/axios/index'
export * from './models/ts/index.js'
export * as hooks from './clients/hooks/index'
export * as swrHooks from './clients/swr/index'
export * as clients from './clients/axios/index'
export * as zod from './zod/index'
export * as faker from './mocks/index'
export * from './models/ts/index.js'
export * as msw from './msw/index'
export * as zod from './zod/index'
2 changes: 2 additions & 0 deletions examples/advanced/src/gen/mocks/createOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export function createOrder(override: NonNullable<Partial<Order>> = {}): NonNull
'id': faker.number.float({}),
'petId': faker.number.float({}),
'quantity': faker.number.float({}),
'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`]),
Expand Down
Loading

0 comments on commit d330ff1

Please sign in to comment.