@kubb/swagger-ts 2.7.2 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-4NJMZQ76.cjs → chunk-FPS6MH3R.cjs} +31 -31
- package/dist/chunk-FPS6MH3R.cjs.map +1 -0
- package/dist/{chunk-FWZBVC3N.js → chunk-XTEOVKJ6.js} +32 -32
- package/dist/chunk-XTEOVKJ6.js.map +1 -0
- package/dist/components.cjs +2 -2
- package/dist/components.d.cts +4 -4
- package/dist/components.d.ts +4 -4
- package/dist/components.js +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{types-WZh-GEfj.d.cts → types-DHrYEdS6.d.cts} +9 -3
- package/dist/{types-WZh-GEfj.d.ts → types-DHrYEdS6.d.ts} +9 -3
- package/package.json +11 -11
- package/src/OperationGenerator.tsx +29 -21
- package/src/TypeGenerator.ts +20 -20
- package/src/components/Mutation.tsx +1 -1
- package/src/components/{Oas.tsx → OasType.tsx} +5 -5
- package/src/components/Query.tsx +1 -1
- package/src/components/index.ts +1 -1
- package/src/plugin.ts +4 -2
- package/src/types.ts +10 -4
- package/dist/chunk-4NJMZQ76.cjs.map +0 -1
- package/dist/chunk-FWZBVC3N.js.map +0 -1
package/dist/components.cjs
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
var
|
5
|
+
var _chunkFPS6MH3Rcjs = require('./chunk-FPS6MH3R.cjs');
|
6
6
|
|
7
7
|
|
8
8
|
|
9
9
|
|
10
|
-
exports.Mutation =
|
10
|
+
exports.Mutation = _chunkFPS6MH3Rcjs.Mutation; exports.OasType = _chunkFPS6MH3Rcjs.OasType; exports.Query = _chunkFPS6MH3Rcjs.Query;
|
11
11
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { OasBuilder } from '@kubb/swagger';
|
2
2
|
import { KubbFile } from '@kubb/core';
|
3
|
-
import { P as PluginOptions } from './types-
|
3
|
+
import { P as PluginOptions } from './types-DHrYEdS6.cjs';
|
4
4
|
import { ReactNode } from 'react';
|
5
5
|
import { OasTypes } from '@kubb/swagger/oas';
|
6
6
|
|
@@ -39,8 +39,8 @@ type Props$1 = {
|
|
39
39
|
*/
|
40
40
|
Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
|
41
41
|
};
|
42
|
-
declare function
|
43
|
-
declare namespace
|
42
|
+
declare function OasType({ name, typeName, Template, }: Props$1): ReactNode;
|
43
|
+
declare namespace OasType {
|
44
44
|
var File: ({ name, typeName, templates }: FileProps$1) => ReactNode;
|
45
45
|
var templates: {
|
46
46
|
readonly default: typeof Template;
|
@@ -66,4 +66,4 @@ type FileProps = {
|
|
66
66
|
mode: KubbFile.Mode;
|
67
67
|
};
|
68
68
|
|
69
|
-
export { Mutation,
|
69
|
+
export { Mutation, OasType, Query };
|
package/dist/components.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { OasBuilder } from '@kubb/swagger';
|
2
2
|
import { KubbFile } from '@kubb/core';
|
3
|
-
import { P as PluginOptions } from './types-
|
3
|
+
import { P as PluginOptions } from './types-DHrYEdS6.js';
|
4
4
|
import { ReactNode } from 'react';
|
5
5
|
import { OasTypes } from '@kubb/swagger/oas';
|
6
6
|
|
@@ -39,8 +39,8 @@ type Props$1 = {
|
|
39
39
|
*/
|
40
40
|
Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
|
41
41
|
};
|
42
|
-
declare function
|
43
|
-
declare namespace
|
42
|
+
declare function OasType({ name, typeName, Template, }: Props$1): ReactNode;
|
43
|
+
declare namespace OasType {
|
44
44
|
var File: ({ name, typeName, templates }: FileProps$1) => ReactNode;
|
45
45
|
var templates: {
|
46
46
|
readonly default: typeof Template;
|
@@ -66,4 +66,4 @@ type FileProps = {
|
|
66
66
|
mode: KubbFile.Mode;
|
67
67
|
};
|
68
68
|
|
69
|
-
export { Mutation,
|
69
|
+
export { Mutation, OasType, Query };
|
package/dist/components.js
CHANGED
package/dist/index.cjs
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
var
|
5
|
+
var _chunkFPS6MH3Rcjs = require('./chunk-FPS6MH3R.cjs');
|
6
6
|
|
7
7
|
// src/index.ts
|
8
|
-
var definePluginDefault =
|
8
|
+
var definePluginDefault = _chunkFPS6MH3Rcjs.definePlugin;
|
9
9
|
var src_default = definePluginDefault;
|
10
10
|
|
11
11
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
exports.default = src_default; exports.definePlugin =
|
15
|
+
exports.default = src_default; exports.definePlugin = _chunkFPS6MH3Rcjs.definePlugin; exports.pluginKey = _chunkFPS6MH3Rcjs.pluginKey; exports.pluginName = _chunkFPS6MH3Rcjs.pluginName;
|
16
16
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
|
-
import { P as PluginOptions, O as Options } from './types-
|
3
|
-
export { F as FileMeta } from './types-
|
2
|
+
import { P as PluginOptions, O as Options } from './types-DHrYEdS6.cjs';
|
3
|
+
export { F as FileMeta } from './types-DHrYEdS6.cjs';
|
4
4
|
export { i as Oas } from './index-BKDH3fXc.cjs';
|
5
5
|
import '@kubb/swagger';
|
6
6
|
import 'hotscript';
|
package/dist/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
|
-
import { P as PluginOptions, O as Options } from './types-
|
3
|
-
export { F as FileMeta } from './types-
|
2
|
+
import { P as PluginOptions, O as Options } from './types-DHrYEdS6.js';
|
3
|
+
export { F as FileMeta } from './types-DHrYEdS6.js';
|
4
4
|
export { i as Oas } from './index-BKDH3fXc.js';
|
5
5
|
import '@kubb/swagger';
|
6
6
|
import 'hotscript';
|
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { KubbFile, ResolveNameParams, Plugin, PluginFactoryOptions } from '@kubb/core';
|
2
|
-
import { Exclude, Include, Override, ResolvePathOptions
|
2
|
+
import { Exclude, Include, Override, ResolvePathOptions } from '@kubb/swagger';
|
3
3
|
|
4
4
|
type Options = {
|
5
5
|
output?: {
|
@@ -57,6 +57,12 @@ type Options = {
|
|
57
57
|
* @default 'asConst'
|
58
58
|
*/
|
59
59
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
60
|
+
/**
|
61
|
+
* Set a suffix for the generated enums.
|
62
|
+
* @default ''
|
63
|
+
* Default will be `'enum'` in version 3 of Kubb
|
64
|
+
*/
|
65
|
+
enumSuffix?: string;
|
60
66
|
/**
|
61
67
|
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
62
68
|
* @default 'string'
|
@@ -88,6 +94,7 @@ type Options = {
|
|
88
94
|
};
|
89
95
|
type ResolvedOptions = {
|
90
96
|
enumType: NonNullable<Options['enumType']>;
|
97
|
+
enumSuffix: NonNullable<Options['enumSuffix']>;
|
91
98
|
dateType: NonNullable<Options['dateType']>;
|
92
99
|
unknownType: NonNullable<Options['unknownType']>;
|
93
100
|
optionalType: NonNullable<Options['optionalType']>;
|
@@ -100,8 +107,7 @@ type FileMeta = {
|
|
100
107
|
name?: string;
|
101
108
|
tag?: string;
|
102
109
|
};
|
103
|
-
type
|
104
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions, AppMeta>;
|
110
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
105
111
|
declare module '@kubb/core' {
|
106
112
|
interface _Register {
|
107
113
|
['@kubb/swagger-ts']: PluginOptions;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { KubbFile, ResolveNameParams, Plugin, PluginFactoryOptions } from '@kubb/core';
|
2
|
-
import { Exclude, Include, Override, ResolvePathOptions
|
2
|
+
import { Exclude, Include, Override, ResolvePathOptions } from '@kubb/swagger';
|
3
3
|
|
4
4
|
type Options = {
|
5
5
|
output?: {
|
@@ -57,6 +57,12 @@ type Options = {
|
|
57
57
|
* @default 'asConst'
|
58
58
|
*/
|
59
59
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
60
|
+
/**
|
61
|
+
* Set a suffix for the generated enums.
|
62
|
+
* @default ''
|
63
|
+
* Default will be `'enum'` in version 3 of Kubb
|
64
|
+
*/
|
65
|
+
enumSuffix?: string;
|
60
66
|
/**
|
61
67
|
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
62
68
|
* @default 'string'
|
@@ -88,6 +94,7 @@ type Options = {
|
|
88
94
|
};
|
89
95
|
type ResolvedOptions = {
|
90
96
|
enumType: NonNullable<Options['enumType']>;
|
97
|
+
enumSuffix: NonNullable<Options['enumSuffix']>;
|
91
98
|
dateType: NonNullable<Options['dateType']>;
|
92
99
|
unknownType: NonNullable<Options['unknownType']>;
|
93
100
|
optionalType: NonNullable<Options['optionalType']>;
|
@@ -100,8 +107,7 @@ type FileMeta = {
|
|
100
107
|
name?: string;
|
101
108
|
tag?: string;
|
102
109
|
};
|
103
|
-
type
|
104
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions, AppMeta>;
|
110
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
105
111
|
declare module '@kubb/core' {
|
106
112
|
interface _Register {
|
107
113
|
['@kubb/swagger-ts']: PluginOptions;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kubb/swagger-ts",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.8.1",
|
4
4
|
"description": "Generator swagger-ts",
|
5
5
|
"keywords": [
|
6
6
|
"typescript",
|
@@ -57,26 +57,26 @@
|
|
57
57
|
],
|
58
58
|
"dependencies": {
|
59
59
|
"hotscript": "^1.0.13",
|
60
|
-
"json-schema-to-ts": "^3.0.
|
60
|
+
"json-schema-to-ts": "^3.0.1",
|
61
61
|
"ts-toolbelt": "^9.6.0",
|
62
|
-
"@kubb/core": "2.
|
63
|
-
"@kubb/parser": "2.
|
64
|
-
"@kubb/react": "2.
|
65
|
-
"@kubb/swagger": "2.
|
66
|
-
"@kubb/types": "2.
|
62
|
+
"@kubb/core": "2.8.1",
|
63
|
+
"@kubb/parser": "2.8.1",
|
64
|
+
"@kubb/react": "2.8.1",
|
65
|
+
"@kubb/swagger": "2.8.1",
|
66
|
+
"@kubb/types": "2.8.1"
|
67
67
|
},
|
68
68
|
"devDependencies": {
|
69
|
-
"@types/react": "^18.2.
|
69
|
+
"@types/react": "^18.2.64",
|
70
70
|
"eslint": "^8.57.0",
|
71
71
|
"expect-type": "^0.17.3",
|
72
72
|
"react": "^18.2.0",
|
73
73
|
"tsup": "^8.0.2",
|
74
74
|
"@kubb/eslint-config": "1.1.8",
|
75
|
-
"@kubb/
|
76
|
-
"@kubb/
|
75
|
+
"@kubb/tsup-config": "1.1.8",
|
76
|
+
"@kubb/ts-config": "0.1.0"
|
77
77
|
},
|
78
78
|
"peerDependencies": {
|
79
|
-
"@kubb/react": "2.
|
79
|
+
"@kubb/react": "2.8.1"
|
80
80
|
},
|
81
81
|
"packageManager": "pnpm@8.3.0",
|
82
82
|
"engines": {
|
@@ -1,63 +1,71 @@
|
|
1
1
|
import { createRoot } from '@kubb/react'
|
2
2
|
import { OperationGenerator as Generator } from '@kubb/swagger'
|
3
|
+
import { Oas } from '@kubb/swagger/components'
|
3
4
|
|
4
5
|
import { Mutation } from './components/Mutation.tsx'
|
5
|
-
import {
|
6
|
+
import { OasType } from './components/OasType.tsx'
|
6
7
|
import { Query } from './components/Query.tsx'
|
7
8
|
|
8
9
|
import type { AppContextProps } from '@kubb/react'
|
9
|
-
import type { OperationMethodResult
|
10
|
+
import type { OperationMethodResult } from '@kubb/swagger'
|
10
11
|
import type { Operation } from '@kubb/swagger/oas'
|
11
12
|
import type { FileMeta, PluginOptions } from './types.ts'
|
12
13
|
|
13
14
|
export class OperationGenerator extends Generator<PluginOptions['resolvedOptions'], PluginOptions> {
|
14
|
-
async all(): OperationMethodResult<FileMeta> {
|
15
|
+
async all(operations: Operation[]): OperationMethodResult<FileMeta> {
|
15
16
|
const { oas, pluginManager, plugin } = this.context
|
16
17
|
|
17
|
-
|
18
|
-
return null
|
19
|
-
}
|
18
|
+
const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
|
20
19
|
|
21
|
-
const root = createRoot<AppContextProps>({ logger: pluginManager.logger })
|
22
20
|
root.render(
|
23
|
-
<Oas
|
24
|
-
|
21
|
+
<Oas oas={oas} operations={operations} getSchemas={(...props) => this.getSchemas(...props)}>
|
22
|
+
{plugin.options.oasType && <OasType.File name="oas" typeName="Oas" />}
|
23
|
+
</Oas>,
|
24
|
+
{ meta: { pluginManager, plugin } },
|
25
25
|
)
|
26
26
|
|
27
27
|
return root.files
|
28
28
|
}
|
29
29
|
|
30
|
-
async get(operation: Operation,
|
30
|
+
async get(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
|
31
31
|
const { oas, pluginManager, plugin, mode = 'directory' } = this.context
|
32
32
|
|
33
33
|
const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
|
34
34
|
root.render(
|
35
|
-
<
|
36
|
-
|
35
|
+
<Oas oas={oas} operations={[operation]} getSchemas={(...props) => this.getSchemas(...props)}>
|
36
|
+
<Oas.Operation operation={operation}>
|
37
|
+
<Query.File mode={mode} />
|
38
|
+
</Oas.Operation>
|
39
|
+
</Oas>,
|
40
|
+
{ meta: { pluginManager, plugin: { ...plugin, options } } },
|
37
41
|
)
|
38
42
|
|
39
43
|
return root.files
|
40
44
|
}
|
41
45
|
|
42
|
-
async post(operation: Operation,
|
46
|
+
async post(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
|
43
47
|
const { oas, pluginManager, plugin, mode = 'directory' } = this.context
|
44
48
|
|
45
49
|
const root = createRoot<AppContextProps<PluginOptions['appMeta']>>({ logger: pluginManager.logger })
|
46
50
|
root.render(
|
47
|
-
<
|
48
|
-
|
51
|
+
<Oas oas={oas} operations={[operation]} getSchemas={(...props) => this.getSchemas(...props)}>
|
52
|
+
<Oas.Operation operation={operation}>
|
53
|
+
<Mutation.File mode={mode} />
|
54
|
+
</Oas.Operation>
|
55
|
+
</Oas>,
|
56
|
+
{ meta: { pluginManager, plugin: { ...plugin, options } } },
|
49
57
|
)
|
50
58
|
|
51
59
|
return root.files
|
52
60
|
}
|
53
61
|
|
54
|
-
async put(operation: Operation,
|
55
|
-
return this.post(operation,
|
62
|
+
async put(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
|
63
|
+
return this.post(operation, options)
|
56
64
|
}
|
57
|
-
async patch(operation: Operation,
|
58
|
-
return this.post(operation,
|
65
|
+
async patch(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
|
66
|
+
return this.post(operation, options)
|
59
67
|
}
|
60
|
-
async delete(operation: Operation,
|
61
|
-
return this.post(operation,
|
68
|
+
async delete(operation: Operation, options: PluginOptions['resolvedOptions']): OperationMethodResult<FileMeta> {
|
69
|
+
return this.post(operation, options)
|
62
70
|
}
|
63
71
|
}
|
package/src/TypeGenerator.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Generator } from '@kubb/core'
|
2
|
-
import transformers from '@kubb/core/transformers'
|
2
|
+
import transformers, { pascalCase } from '@kubb/core/transformers'
|
3
3
|
import { getUniqueName } from '@kubb/core/utils'
|
4
4
|
import * as factory from '@kubb/parser/factory'
|
5
5
|
import { keywordTypeNodes } from '@kubb/parser/factory'
|
@@ -10,7 +10,7 @@ import { pluginKey } from './plugin.ts'
|
|
10
10
|
import type { PluginManager } from '@kubb/core'
|
11
11
|
import type { ts } from '@kubb/parser'
|
12
12
|
import type { ImportMeta, Refs } from '@kubb/swagger'
|
13
|
-
import type { Oas,
|
13
|
+
import type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/swagger/oas'
|
14
14
|
import type { PluginOptions } from './types.ts'
|
15
15
|
|
16
16
|
// based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398
|
@@ -38,7 +38,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
38
38
|
description,
|
39
39
|
keysToOmit,
|
40
40
|
}: {
|
41
|
-
schema:
|
41
|
+
schema: SchemaObject
|
42
42
|
baseName: string
|
43
43
|
description?: string
|
44
44
|
optional?: boolean
|
@@ -88,7 +88,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
88
88
|
* Delegates to getBaseTypeFromSchema internally and
|
89
89
|
* optionally adds a union with null.
|
90
90
|
*/
|
91
|
-
getTypeFromSchema(schema?:
|
91
|
+
getTypeFromSchema(schema?: SchemaObject, name?: string): ts.TypeNode | null {
|
92
92
|
const type = this.#getBaseTypeFromSchema(schema, name)
|
93
93
|
|
94
94
|
if (!type) {
|
@@ -107,14 +107,14 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
107
107
|
/**
|
108
108
|
* Recursively creates a type literal with the given props.
|
109
109
|
*/
|
110
|
-
#getTypeFromProperties(baseSchema?:
|
110
|
+
#getTypeFromProperties(baseSchema?: SchemaObject, baseName?: string): ts.TypeNode | null {
|
111
111
|
const { optionalType } = this.options
|
112
112
|
const properties = baseSchema?.properties || {}
|
113
113
|
const required = baseSchema?.required
|
114
114
|
const additionalProperties = baseSchema?.additionalProperties
|
115
115
|
|
116
116
|
const members: Array<ts.TypeElement | null> = Object.keys(properties).map((name) => {
|
117
|
-
const schema = properties[name] as
|
117
|
+
const schema = properties[name] as SchemaObject
|
118
118
|
|
119
119
|
const isRequired = Array.isArray(required) ? required.includes(name) : !!required
|
120
120
|
let type = this.getTypeFromSchema(schema, this.context.pluginManager.resolveName({ name: `${baseName || ''} ${name}`, pluginKey, type: 'type' }))
|
@@ -146,7 +146,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
146
146
|
})
|
147
147
|
})
|
148
148
|
if (additionalProperties) {
|
149
|
-
const type = additionalProperties === true ? this.#unknownReturn : this.getTypeFromSchema(additionalProperties as
|
149
|
+
const type = additionalProperties === true ? this.#unknownReturn : this.getTypeFromSchema(additionalProperties as SchemaObject)
|
150
150
|
|
151
151
|
if (type) {
|
152
152
|
members.push(factory.createIndexSignature(type))
|
@@ -186,7 +186,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
186
186
|
return factory.createTypeReferenceNode(ref.propertyName, undefined)
|
187
187
|
}
|
188
188
|
|
189
|
-
#getParsedSchema(schema?:
|
189
|
+
#getParsedSchema(schema?: SchemaObject) {
|
190
190
|
const parsedSchema = getSchemaFactory(this.context.oas)(schema)
|
191
191
|
return parsedSchema
|
192
192
|
}
|
@@ -196,7 +196,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
196
196
|
* schema and returns the appropriate type.
|
197
197
|
*/
|
198
198
|
#getBaseTypeFromSchema(
|
199
|
-
_schema:
|
199
|
+
_schema: SchemaObject | undefined,
|
200
200
|
baseName?: string,
|
201
201
|
): ts.TypeNode | null {
|
202
202
|
const { schema, version } = this.#getParsedSchema(_schema)
|
@@ -211,13 +211,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
211
211
|
|
212
212
|
if (schema.oneOf) {
|
213
213
|
// union
|
214
|
-
const schemaWithoutOneOf = { ...schema, oneOf: undefined } as
|
214
|
+
const schemaWithoutOneOf = { ...schema, oneOf: undefined } as SchemaObject
|
215
215
|
|
216
216
|
const union = factory.createUnionDeclaration({
|
217
217
|
withParentheses: true,
|
218
218
|
nodes: schema.oneOf
|
219
219
|
.map((item) => {
|
220
|
-
return item && this.getTypeFromSchema(item as
|
220
|
+
return item && this.getTypeFromSchema(item as SchemaObject)
|
221
221
|
})
|
222
222
|
.filter((item) => {
|
223
223
|
return item && item !== this.#unknownReturn
|
@@ -234,13 +234,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
234
234
|
}
|
235
235
|
|
236
236
|
if (schema.anyOf) {
|
237
|
-
const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as
|
237
|
+
const schemaWithoutAnyOf = { ...schema, anyOf: undefined } as SchemaObject
|
238
238
|
|
239
239
|
const union = factory.createUnionDeclaration({
|
240
240
|
withParentheses: true,
|
241
241
|
nodes: schema.anyOf
|
242
242
|
.map((item) => {
|
243
|
-
return item && this.getTypeFromSchema(item as
|
243
|
+
return item && this.getTypeFromSchema(item as SchemaObject)
|
244
244
|
})
|
245
245
|
.filter((item) => {
|
246
246
|
return item && item !== this.#unknownReturn
|
@@ -257,13 +257,13 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
257
257
|
}
|
258
258
|
if (schema.allOf) {
|
259
259
|
// intersection/add
|
260
|
-
const schemaWithoutAllOf = { ...schema, allOf: undefined } as
|
260
|
+
const schemaWithoutAllOf = { ...schema, allOf: undefined } as SchemaObject
|
261
261
|
|
262
262
|
const and = factory.createIntersectionDeclaration({
|
263
263
|
withParentheses: true,
|
264
264
|
nodes: schema.allOf
|
265
265
|
.map((item) => {
|
266
|
-
return item && this.getTypeFromSchema(item as
|
266
|
+
return item && this.getTypeFromSchema(item as SchemaObject)
|
267
267
|
})
|
268
268
|
.filter((item) => {
|
269
269
|
return item && item !== this.#unknownReturn
|
@@ -283,7 +283,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
283
283
|
* Enum will be defined outside the baseType(hints the baseName check)
|
284
284
|
*/
|
285
285
|
if (schema.enum && baseName) {
|
286
|
-
const enumName = getUniqueName(baseName, this.options.usedEnumNames)
|
286
|
+
const enumName = getUniqueName(pascalCase([baseName, this.options.enumSuffix].join(' ')), this.options.usedEnumNames)
|
287
287
|
|
288
288
|
let enums: [key: string, value: string | number][] = [...new Set(schema.enum)].map((key) => [key, key])
|
289
289
|
|
@@ -318,7 +318,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
318
318
|
|
319
319
|
if ('items' in schema) {
|
320
320
|
// items -> array
|
321
|
-
const node = this.getTypeFromSchema(schema.items as
|
321
|
+
const node = this.getTypeFromSchema(schema.items as SchemaObject, baseName)
|
322
322
|
if (node) {
|
323
323
|
return factory.createArrayTypeNode(node)
|
324
324
|
}
|
@@ -330,7 +330,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
330
330
|
*/
|
331
331
|
|
332
332
|
if ('prefixItems' in schema) {
|
333
|
-
const prefixItems = schema.prefixItems as
|
333
|
+
const prefixItems = schema.prefixItems as SchemaObject[]
|
334
334
|
|
335
335
|
return factory.createTupleDeclaration({
|
336
336
|
nodes: prefixItems.map((item) => {
|
@@ -342,7 +342,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
342
342
|
|
343
343
|
if (schema.properties || schema.additionalProperties) {
|
344
344
|
// properties -> literal type
|
345
|
-
return this.#getTypeFromProperties(schema, baseName)
|
345
|
+
return this.#getTypeFromProperties(schema as SchemaObject, baseName)
|
346
346
|
}
|
347
347
|
|
348
348
|
/**
|
@@ -380,7 +380,7 @@ export class TypeGenerator extends Generator<PluginOptions['resolvedOptions'], C
|
|
380
380
|
{
|
381
381
|
...schema,
|
382
382
|
type,
|
383
|
-
},
|
383
|
+
} as SchemaObject,
|
384
384
|
baseName,
|
385
385
|
),
|
386
386
|
nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,
|
@@ -107,7 +107,7 @@ Mutation.File = function({ mode }: FileProps): ReactNode {
|
|
107
107
|
|
108
108
|
const schemas = useSchemas()
|
109
109
|
const pluginManager = usePluginManager()
|
110
|
-
const oas = useOas()
|
110
|
+
const { oas } = useOas()
|
111
111
|
const file = useOperationFile()
|
112
112
|
const factoryName = useOperationName({ type: 'type' })
|
113
113
|
const operation = useOperation()
|
@@ -42,12 +42,12 @@ type Props = {
|
|
42
42
|
Template?: React.ComponentType<React.ComponentProps<typeof Template>>
|
43
43
|
}
|
44
44
|
|
45
|
-
export function
|
45
|
+
export function OasType({
|
46
46
|
name,
|
47
47
|
typeName,
|
48
48
|
Template = defaultTemplates.default,
|
49
49
|
}: Props): ReactNode {
|
50
|
-
const oas = useOas()
|
50
|
+
const { oas } = useOas()
|
51
51
|
|
52
52
|
return <Template name={name} typeName={typeName} api={oas.api} />
|
53
53
|
}
|
@@ -61,7 +61,7 @@ type FileProps = {
|
|
61
61
|
templates?: typeof defaultTemplates
|
62
62
|
}
|
63
63
|
|
64
|
-
|
64
|
+
OasType.File = function({ name, typeName, templates = defaultTemplates }: FileProps): ReactNode {
|
65
65
|
const { key: pluginKey } = usePlugin<PluginOptions>()
|
66
66
|
const file = useFile({ name, extName: '.ts', pluginKey })
|
67
67
|
|
@@ -76,11 +76,11 @@ Oas.File = function({ name, typeName, templates = defaultTemplates }: FileProps)
|
|
76
76
|
>
|
77
77
|
<File.Import name={['Infer']} path="@kubb/swagger-ts/oas" isTypeOnly />
|
78
78
|
<File.Source>
|
79
|
-
<
|
79
|
+
<OasType Template={Template} name={name} typeName={typeName} />
|
80
80
|
</File.Source>
|
81
81
|
</File>
|
82
82
|
</Editor>
|
83
83
|
)
|
84
84
|
}
|
85
85
|
|
86
|
-
|
86
|
+
OasType.templates = defaultTemplates
|
package/src/components/Query.tsx
CHANGED
@@ -108,7 +108,7 @@ Query.File = function({ mode }: FileProps): ReactNode {
|
|
108
108
|
|
109
109
|
const schemas = useSchemas()
|
110
110
|
const pluginManager = usePluginManager()
|
111
|
-
const oas = useOas()
|
111
|
+
const { oas } = useOas()
|
112
112
|
const file = useOperationFile()
|
113
113
|
const factoryName = useOperationName({ type: 'type' })
|
114
114
|
const operation = useOperation()
|
package/src/components/index.ts
CHANGED
package/src/plugin.ts
CHANGED
@@ -23,6 +23,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
23
23
|
include,
|
24
24
|
override = [],
|
25
25
|
enumType = 'asConst',
|
26
|
+
enumSuffix = '',
|
26
27
|
dateType = 'string',
|
27
28
|
unknownType = 'any',
|
28
29
|
optionalType = 'questionToken',
|
@@ -37,6 +38,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
37
38
|
transformers,
|
38
39
|
dateType,
|
39
40
|
enumType,
|
41
|
+
enumSuffix,
|
40
42
|
optionalType,
|
41
43
|
oasType,
|
42
44
|
// keep the used enumnames between TypeBuilder and OperationGenerator per plugin(pluginKey)
|
@@ -44,9 +46,9 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
44
46
|
unknownType,
|
45
47
|
},
|
46
48
|
pre: [swaggerPluginName],
|
47
|
-
resolvePath(baseName,
|
49
|
+
resolvePath(baseName, pathMode, options) {
|
48
50
|
const root = path.resolve(this.config.root, this.config.output.path)
|
49
|
-
const mode = FileManager.getMode(path.resolve(root, output.path))
|
51
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
50
52
|
|
51
53
|
if (mode === 'file') {
|
52
54
|
/**
|
package/src/types.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { KubbFile, Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
2
|
-
import type {
|
2
|
+
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/swagger'
|
3
3
|
|
4
4
|
export type Options = {
|
5
5
|
output?: {
|
@@ -57,6 +57,13 @@ export type Options = {
|
|
57
57
|
* @default 'asConst'
|
58
58
|
*/
|
59
59
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
|
60
|
+
/**
|
61
|
+
* Set a suffix for the generated enums.
|
62
|
+
* @default ''
|
63
|
+
* Default will be `'enum'` in version 3 of Kubb
|
64
|
+
*/
|
65
|
+
enumSuffix?: string
|
66
|
+
|
60
67
|
/**
|
61
68
|
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
62
69
|
* @default 'string'
|
@@ -89,6 +96,7 @@ export type Options = {
|
|
89
96
|
|
90
97
|
type ResolvedOptions = {
|
91
98
|
enumType: NonNullable<Options['enumType']>
|
99
|
+
enumSuffix: NonNullable<Options['enumSuffix']>
|
92
100
|
dateType: NonNullable<Options['dateType']>
|
93
101
|
unknownType: NonNullable<Options['unknownType']>
|
94
102
|
optionalType: NonNullable<Options['optionalType']>
|
@@ -103,9 +111,7 @@ export type FileMeta = {
|
|
103
111
|
tag?: string
|
104
112
|
}
|
105
113
|
|
106
|
-
type
|
107
|
-
|
108
|
-
export type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions, AppMeta>
|
114
|
+
export type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions>
|
109
115
|
|
110
116
|
declare module '@kubb/core' {
|
111
117
|
export interface _Register {
|