Skip to content

Commit

Permalink
Merge branch 'main' into chore/operationRefactor
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Mar 9, 2024
2 parents 0b3755a + e2eed44 commit ee0f9d6
Show file tree
Hide file tree
Showing 19 changed files with 249 additions and 155 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: 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
6 changes: 3 additions & 3 deletions examples/advanced/src/gen/models/ts/AddPetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Category } from './Category'
import type { TagTag } from './tag/Tag'

export const AddPetRequestStatus = {
export const AddPetRequestStatusEnum = {
'available': 'available',
'pending': 'pending',
'sold': 'sold',
} as const
export type AddPetRequestStatus = (typeof AddPetRequestStatus)[keyof typeof AddPetRequestStatus]
export type AddPetRequestStatusEnum = (typeof AddPetRequestStatusEnum)[keyof typeof AddPetRequestStatusEnum]
export type AddPetRequest = {
/**
* @type integer | undefined int64
Expand All @@ -31,5 +31,5 @@ export type AddPetRequest = {
* @description pet status in the store
* @type string | undefined
*/
status?: AddPetRequestStatus
status?: AddPetRequestStatusEnum
}
Loading

0 comments on commit ee0f9d6

Please sign in to comment.