@kubb/swagger-ts 2.0.0-beta.1 → 2.0.0-beta.10
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/components.cjs +3993 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +163 -0
- package/dist/components.d.ts +163 -0
- package/dist/components.js +3969 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +3561 -289
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +426 -13
- package/dist/index.d.ts +426 -13
- package/dist/index.js +3563 -292
- package/dist/index.js.map +1 -1
- package/dist/oas.d.ts +381 -0
- package/dist/oas.js +5 -0
- package/dist/oas.js.map +1 -0
- package/package.json +21 -7
- package/src/OperationGenerator.tsx +62 -0
- package/src/TypeBuilder.ts +58 -0
- package/src/{generators/TypeGenerator.ts → TypeGenerator.ts} +78 -68
- package/src/components/Mutation.tsx +137 -0
- package/src/components/Oas.tsx +84 -0
- package/src/components/Query.tsx +136 -0
- package/src/components/index.ts +3 -0
- package/src/oas/index.ts +7 -0
- package/src/oas/infer.ts +58 -0
- package/src/oas/mappers.ts +93 -0
- package/src/oas/model.ts +38 -0
- package/src/oas/requestParams.ts +170 -0
- package/src/oas/response.ts +39 -0
- package/src/oas/security.ts +158 -0
- package/src/plugin.ts +52 -107
- package/src/types.ts +41 -13
- package/src/builders/TypeBuilder.ts +0 -94
- package/src/builders/index.ts +0 -1
- package/src/generators/OperationGenerator.ts +0 -213
- package/src/generators/index.ts +0 -2
@@ -0,0 +1,163 @@
|
|
1
|
+
import { ResolvePathOptions, Exclude, Include, Override, AppMeta as AppMeta$1, OasBuilder, OasTypes } from '@kubb/swagger';
|
2
|
+
import { PluginFactoryOptions, KubbFile, ResolveNameParams } from '@kubb/core';
|
3
|
+
import { ReactNode } from 'react';
|
4
|
+
|
5
|
+
type Options = {
|
6
|
+
output?: {
|
7
|
+
/**
|
8
|
+
* Relative path to save the TypeScript types.
|
9
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
10
|
+
* @default 'types'
|
11
|
+
*/
|
12
|
+
path: string;
|
13
|
+
/**
|
14
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
15
|
+
*/
|
16
|
+
exportAs?: string;
|
17
|
+
/**
|
18
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
19
|
+
*/
|
20
|
+
extName?: KubbFile.Extname;
|
21
|
+
/**
|
22
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
23
|
+
* @default `'barrel'`
|
24
|
+
*/
|
25
|
+
exportType?: 'barrel' | false;
|
26
|
+
};
|
27
|
+
/**
|
28
|
+
* Group the TypeScript types based on the provided name.
|
29
|
+
*/
|
30
|
+
group?: {
|
31
|
+
/**
|
32
|
+
* Tag will group based on the operation tag inside the Swagger file.
|
33
|
+
*/
|
34
|
+
type: 'tag';
|
35
|
+
/**
|
36
|
+
* Relative path to save the grouped TypeScript Types.
|
37
|
+
*
|
38
|
+
* `{{tag}}` will be replaced by the current tagName.
|
39
|
+
* @example `${output}/{{tag}}Controller` => `models/PetController`
|
40
|
+
* @default `${output}/{{tag}}Controller`
|
41
|
+
*/
|
42
|
+
output?: string;
|
43
|
+
};
|
44
|
+
/**
|
45
|
+
* Array containing exclude paramaters to exclude/skip tags/operations/methods/paths.
|
46
|
+
*/
|
47
|
+
exclude?: Array<Exclude>;
|
48
|
+
/**
|
49
|
+
* Array containing include paramaters to include tags/operations/methods/paths.
|
50
|
+
*/
|
51
|
+
include?: Array<Include>;
|
52
|
+
/**
|
53
|
+
* Array containing override paramaters to override `options` based on tags/operations/methods/paths.
|
54
|
+
*/
|
55
|
+
override?: Array<Override<Options>>;
|
56
|
+
/**
|
57
|
+
* Choose to use `enum` or `as const` for enums
|
58
|
+
* @default 'asConst'
|
59
|
+
*/
|
60
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst';
|
61
|
+
/**
|
62
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
63
|
+
* @default 'string'
|
64
|
+
*/
|
65
|
+
dateType?: 'string' | 'date';
|
66
|
+
/**
|
67
|
+
* Choose what to use as mode for an optional value.
|
68
|
+
* @examples 'questionToken': type?: string
|
69
|
+
* @examples 'undefined': type: string | undefined
|
70
|
+
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
71
|
+
* @default 'questionToken'
|
72
|
+
*/
|
73
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
74
|
+
transformers?: {
|
75
|
+
/**
|
76
|
+
* Customize the names based on the type that is provided by the plugin.
|
77
|
+
*/
|
78
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
79
|
+
};
|
80
|
+
/**
|
81
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/swagger-ts/oas'`
|
82
|
+
*/
|
83
|
+
oasType?: 'infer' | false;
|
84
|
+
};
|
85
|
+
type ResolvedOptions = {
|
86
|
+
enumType: NonNullable<Options['enumType']>;
|
87
|
+
dateType: NonNullable<Options['dateType']>;
|
88
|
+
optionalType: NonNullable<Options['optionalType']>;
|
89
|
+
transformers: NonNullable<Options['transformers']>;
|
90
|
+
oasType: NonNullable<Options['oasType']>;
|
91
|
+
usedEnumNames: Record<string, number>;
|
92
|
+
};
|
93
|
+
type AppMeta = AppMeta$1;
|
94
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions, AppMeta>;
|
95
|
+
declare module '@kubb/core' {
|
96
|
+
interface _Register {
|
97
|
+
['@kubb/swagger-ts']: PluginOptions;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
declare class TypeBuilder extends OasBuilder<PluginOptions['resolvedOptions']> {
|
102
|
+
build(name?: string): Required<Pick<KubbFile.File, 'imports' | 'source'>>;
|
103
|
+
}
|
104
|
+
|
105
|
+
type Props$2 = {
|
106
|
+
builder: TypeBuilder;
|
107
|
+
};
|
108
|
+
declare function Mutation({ builder, }: Props$2): ReactNode;
|
109
|
+
declare namespace Mutation {
|
110
|
+
var File: ({ mode }: FileProps$2) => ReactNode;
|
111
|
+
}
|
112
|
+
type FileProps$2 = {
|
113
|
+
mode: KubbFile.Mode;
|
114
|
+
};
|
115
|
+
|
116
|
+
type TemplateProps = {
|
117
|
+
/**
|
118
|
+
* Name of the function
|
119
|
+
*/
|
120
|
+
name: string;
|
121
|
+
typeName: string;
|
122
|
+
api: OasTypes.OASDocument;
|
123
|
+
};
|
124
|
+
declare function Template({ name, typeName, api, }: TemplateProps): ReactNode;
|
125
|
+
declare const defaultTemplates: {
|
126
|
+
readonly default: typeof Template;
|
127
|
+
};
|
128
|
+
type Props$1 = {
|
129
|
+
name: string;
|
130
|
+
typeName: string;
|
131
|
+
/**
|
132
|
+
* This will make it possible to override the default behaviour.
|
133
|
+
*/
|
134
|
+
Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
|
135
|
+
};
|
136
|
+
declare function Oas({ name, typeName, Template, }: Props$1): ReactNode;
|
137
|
+
declare namespace Oas {
|
138
|
+
var File: ({ name, typeName, templates }: FileProps$1) => ReactNode;
|
139
|
+
var templates: {
|
140
|
+
readonly default: typeof Template;
|
141
|
+
};
|
142
|
+
}
|
143
|
+
type FileProps$1 = {
|
144
|
+
name: string;
|
145
|
+
typeName: string;
|
146
|
+
/**
|
147
|
+
* This will make it possible to override the default behaviour.
|
148
|
+
*/
|
149
|
+
templates?: typeof defaultTemplates;
|
150
|
+
};
|
151
|
+
|
152
|
+
type Props = {
|
153
|
+
builder: TypeBuilder;
|
154
|
+
};
|
155
|
+
declare function Query({ builder, }: Props): ReactNode;
|
156
|
+
declare namespace Query {
|
157
|
+
var File: ({ mode }: FileProps) => ReactNode;
|
158
|
+
}
|
159
|
+
type FileProps = {
|
160
|
+
mode: KubbFile.Mode;
|
161
|
+
};
|
162
|
+
|
163
|
+
export { Mutation, Oas, Query };
|
@@ -0,0 +1,163 @@
|
|
1
|
+
import { ResolvePathOptions, Exclude, Include, Override, AppMeta as AppMeta$1, OasBuilder, OasTypes } from '@kubb/swagger';
|
2
|
+
import { PluginFactoryOptions, KubbFile, ResolveNameParams } from '@kubb/core';
|
3
|
+
import { ReactNode } from 'react';
|
4
|
+
|
5
|
+
type Options = {
|
6
|
+
output?: {
|
7
|
+
/**
|
8
|
+
* Relative path to save the TypeScript types.
|
9
|
+
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
10
|
+
* @default 'types'
|
11
|
+
*/
|
12
|
+
path: string;
|
13
|
+
/**
|
14
|
+
* Name to be used for the `export * as {{exportAs}} from './'`
|
15
|
+
*/
|
16
|
+
exportAs?: string;
|
17
|
+
/**
|
18
|
+
* Add an extension to the generated imports and exports, default it will not use an extension
|
19
|
+
*/
|
20
|
+
extName?: KubbFile.Extname;
|
21
|
+
/**
|
22
|
+
* Define what needs to exported, here you can also disable the export of barrel files
|
23
|
+
* @default `'barrel'`
|
24
|
+
*/
|
25
|
+
exportType?: 'barrel' | false;
|
26
|
+
};
|
27
|
+
/**
|
28
|
+
* Group the TypeScript types based on the provided name.
|
29
|
+
*/
|
30
|
+
group?: {
|
31
|
+
/**
|
32
|
+
* Tag will group based on the operation tag inside the Swagger file.
|
33
|
+
*/
|
34
|
+
type: 'tag';
|
35
|
+
/**
|
36
|
+
* Relative path to save the grouped TypeScript Types.
|
37
|
+
*
|
38
|
+
* `{{tag}}` will be replaced by the current tagName.
|
39
|
+
* @example `${output}/{{tag}}Controller` => `models/PetController`
|
40
|
+
* @default `${output}/{{tag}}Controller`
|
41
|
+
*/
|
42
|
+
output?: string;
|
43
|
+
};
|
44
|
+
/**
|
45
|
+
* Array containing exclude paramaters to exclude/skip tags/operations/methods/paths.
|
46
|
+
*/
|
47
|
+
exclude?: Array<Exclude>;
|
48
|
+
/**
|
49
|
+
* Array containing include paramaters to include tags/operations/methods/paths.
|
50
|
+
*/
|
51
|
+
include?: Array<Include>;
|
52
|
+
/**
|
53
|
+
* Array containing override paramaters to override `options` based on tags/operations/methods/paths.
|
54
|
+
*/
|
55
|
+
override?: Array<Override<Options>>;
|
56
|
+
/**
|
57
|
+
* Choose to use `enum` or `as const` for enums
|
58
|
+
* @default 'asConst'
|
59
|
+
*/
|
60
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst';
|
61
|
+
/**
|
62
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
63
|
+
* @default 'string'
|
64
|
+
*/
|
65
|
+
dateType?: 'string' | 'date';
|
66
|
+
/**
|
67
|
+
* Choose what to use as mode for an optional value.
|
68
|
+
* @examples 'questionToken': type?: string
|
69
|
+
* @examples 'undefined': type: string | undefined
|
70
|
+
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
71
|
+
* @default 'questionToken'
|
72
|
+
*/
|
73
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
74
|
+
transformers?: {
|
75
|
+
/**
|
76
|
+
* Customize the names based on the type that is provided by the plugin.
|
77
|
+
*/
|
78
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
79
|
+
};
|
80
|
+
/**
|
81
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/swagger-ts/oas'`
|
82
|
+
*/
|
83
|
+
oasType?: 'infer' | false;
|
84
|
+
};
|
85
|
+
type ResolvedOptions = {
|
86
|
+
enumType: NonNullable<Options['enumType']>;
|
87
|
+
dateType: NonNullable<Options['dateType']>;
|
88
|
+
optionalType: NonNullable<Options['optionalType']>;
|
89
|
+
transformers: NonNullable<Options['transformers']>;
|
90
|
+
oasType: NonNullable<Options['oasType']>;
|
91
|
+
usedEnumNames: Record<string, number>;
|
92
|
+
};
|
93
|
+
type AppMeta = AppMeta$1;
|
94
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options, ResolvedOptions, never, ResolvePathOptions, AppMeta>;
|
95
|
+
declare module '@kubb/core' {
|
96
|
+
interface _Register {
|
97
|
+
['@kubb/swagger-ts']: PluginOptions;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
declare class TypeBuilder extends OasBuilder<PluginOptions['resolvedOptions']> {
|
102
|
+
build(name?: string): Required<Pick<KubbFile.File, 'imports' | 'source'>>;
|
103
|
+
}
|
104
|
+
|
105
|
+
type Props$2 = {
|
106
|
+
builder: TypeBuilder;
|
107
|
+
};
|
108
|
+
declare function Mutation({ builder, }: Props$2): ReactNode;
|
109
|
+
declare namespace Mutation {
|
110
|
+
var File: ({ mode }: FileProps$2) => ReactNode;
|
111
|
+
}
|
112
|
+
type FileProps$2 = {
|
113
|
+
mode: KubbFile.Mode;
|
114
|
+
};
|
115
|
+
|
116
|
+
type TemplateProps = {
|
117
|
+
/**
|
118
|
+
* Name of the function
|
119
|
+
*/
|
120
|
+
name: string;
|
121
|
+
typeName: string;
|
122
|
+
api: OasTypes.OASDocument;
|
123
|
+
};
|
124
|
+
declare function Template({ name, typeName, api, }: TemplateProps): ReactNode;
|
125
|
+
declare const defaultTemplates: {
|
126
|
+
readonly default: typeof Template;
|
127
|
+
};
|
128
|
+
type Props$1 = {
|
129
|
+
name: string;
|
130
|
+
typeName: string;
|
131
|
+
/**
|
132
|
+
* This will make it possible to override the default behaviour.
|
133
|
+
*/
|
134
|
+
Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
|
135
|
+
};
|
136
|
+
declare function Oas({ name, typeName, Template, }: Props$1): ReactNode;
|
137
|
+
declare namespace Oas {
|
138
|
+
var File: ({ name, typeName, templates }: FileProps$1) => ReactNode;
|
139
|
+
var templates: {
|
140
|
+
readonly default: typeof Template;
|
141
|
+
};
|
142
|
+
}
|
143
|
+
type FileProps$1 = {
|
144
|
+
name: string;
|
145
|
+
typeName: string;
|
146
|
+
/**
|
147
|
+
* This will make it possible to override the default behaviour.
|
148
|
+
*/
|
149
|
+
templates?: typeof defaultTemplates;
|
150
|
+
};
|
151
|
+
|
152
|
+
type Props = {
|
153
|
+
builder: TypeBuilder;
|
154
|
+
};
|
155
|
+
declare function Query({ builder, }: Props): ReactNode;
|
156
|
+
declare namespace Query {
|
157
|
+
var File: ({ mode }: FileProps) => ReactNode;
|
158
|
+
}
|
159
|
+
type FileProps = {
|
160
|
+
mode: KubbFile.Mode;
|
161
|
+
};
|
162
|
+
|
163
|
+
export { Mutation, Oas, Query };
|