Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support banner with context for Oas #1510

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/nine-onions-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@kubb/plugin-svelte-query": minor
"@kubb/plugin-react-query": minor
"@kubb/plugin-solid-query": minor
"@kubb/plugin-vue-query": minor
"@kubb/plugin-client": minor
"@kubb/plugin-faker": minor
"@kubb/plugin-redoc": minor
"@kubb/plugin-msw": minor
"@kubb/plugin-oas": minor
"@kubb/plugin-swr": minor
"@kubb/plugin-zod": minor
"@kubb/plugin-ts": minor
"@kubb/core": minor
---

support banner with context for Oas
13 changes: 13 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ title: Changelog

# Changelog

## 3.5.0
- [`core`](/plugins/core): support banner with context for Oas
```typescript
pluginTs({
output: {
path: 'models',
banner(oas) {
return `// version: ${oas.api.info.version}`
},
},
}),
```

## 3.4.6
- [`core`](/plugins/core): ignore acronyms when doing casing switch to pascal or camelcase

Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-faker/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-msw/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### handlers
Expand Down
16 changes: 8 additions & 8 deletions docs/plugins/plugin-oas/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ Define what needs to be exported, here you can also disable the export of barrel
#### output.banner
Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Required: | `false` |
| | |
|----------:|:---------------------------------|
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Required: | `false` |
| | |
|----------:|:--------|
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### validate

Expand Down
8 changes: 4 additions & 4 deletions docs/plugins/plugin-react-query/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |
## Installation

Expand Down Expand Up @@ -139,15 +139,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-solid-query/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-svelte-query/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-swr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-ts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |


Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-vue-query/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
4 changes: 2 additions & 2 deletions docs/plugins/plugin-zod/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ Add a banner text in the beginning of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

#### output.footer
Add a footer text at the end of every file.

| | |
|----------:|:--------------------------------------|
| Type: | `string` |
| Type: | `string \| (oas: Oas) => string` |
| Required: | `false` |

### group
Expand Down
11 changes: 10 additions & 1 deletion examples/client/src/generators/clientStaticGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { PluginClient } from '@kubb/plugin-client'
import { Client } from '@kubb/plugin-client/components'
import { createReactGenerator } from '@kubb/plugin-oas'
import { useOperationManager } from '@kubb/plugin-oas/hooks'
import { useOas } from '@kubb/plugin-oas/hooks'
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
import { pluginTsName } from '@kubb/plugin-ts'
import { File, useApp } from '@kubb/react'

Expand All @@ -14,6 +16,7 @@ export const clientStaticGenerator = createReactGenerator<PluginClient>({
options: { output },
},
} = useApp<PluginClient>()
const oas = useOas()
const { getSchemas, getName, getFile } = useOperationManager()

const client = {
Expand All @@ -27,7 +30,13 @@ export const clientStaticGenerator = createReactGenerator<PluginClient>({
}

return (
<File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta} banner={output?.banner} footer={output?.footer}>
<File
baseName={client.file.baseName}
path={client.file.path}
meta={client.file.meta}
banner={getBanner({ oas, output })}
footer={getFooter({ oas, output })}
>
<File.Import name={'client'} path={options.importPath} />
<File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />
<File.Import
Expand Down
3 changes: 3 additions & 0 deletions examples/react-query/kubb.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export const config = {
pluginTs({
output: {
path: 'models',
banner(oas) {
return `// version: ${oas.api.info.version}`
},
},
}),
pluginReactQuery({
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/AddPet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { AddPetRequest } from './AddPetRequest.ts'
import type { Pet } from './Pet.ts'

Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/AddPetRequest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { Category } from './Category.ts'
import type { Tag } from './Tag.ts'

Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/Address.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

export type Address = {
/**
* @type string | undefined
Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/ApiResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

export type ApiResponse = {
/**
* @type integer | undefined, int32
Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/Category.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

export type Category = {
/**
* @type integer | undefined, int64
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/CreateUser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { User } from './User.ts'

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { User } from './User.ts'

/**
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/Customer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { Address } from './Address.ts'

export type Customer = {
Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/DeleteOrder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

export type DeleteOrderPathParams = {
/**
* @description ID of the order that needs to be deleted
Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/DeletePet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

export type DeletePetPathParams = {
/**
* @description Pet id to delete
Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/DeleteUser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

export type DeleteUserPathParams = {
/**
* @description The name that needs to be deleted
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/FindPetsByStatus.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { Pet } from './Pet.ts'

export const findPetsByStatusQueryParamsStatusEnum = {
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/FindPetsByTags.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { Pet } from './Pet.ts'

export type FindPetsByTagsQueryParams = {
Expand Down
2 changes: 2 additions & 0 deletions examples/react-query/src/gen/models/GetInventory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version: 1.0.11

/**
* @description successful operation
*/
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/GetOrderById.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { Order } from './Order.ts'

export type GetOrderByIdPathParams = {
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/GetPetById.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { Pet } from './Pet.ts'

export type GetPetByIdPathParams = {
Expand Down
1 change: 1 addition & 0 deletions examples/react-query/src/gen/models/GetUserByName.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// version: 1.0.11
import type { User } from './User.ts'

export type GetUserByNamePathParams = {
Expand Down
Loading
Loading