@kubb/swagger-ts 1.13.0 → 1.14.0-canary.20231020T164558
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/index.cjs +78 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -44
- package/dist/index.d.ts +33 -44
- package/dist/index.js +78 -60
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
2
|
import { PluginFactoryOptions, SchemaGenerator, PluginContext, KubbFile } from '@kubb/core';
|
3
|
-
import { SkipBy, ResolvePathOptions, OpenAPIV3, Refs, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OasBuilder, FileResolver, ResolveProps, UseResolveProps } from '@kubb/swagger';
|
3
|
+
import { SkipBy, OverrideBy, ResolvePathOptions, OpenAPIV3, Refs, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OasBuilder, FileResolver, ResolveProps, UseResolveProps } from '@kubb/swagger';
|
4
4
|
import ts from 'typescript';
|
5
|
-
import { Options as Options$
|
5
|
+
import { Options as Options$4 } from 'change-case';
|
6
6
|
|
7
|
-
type Options$
|
7
|
+
type Options$3 = {
|
8
8
|
/**
|
9
9
|
* Relative path to save the TypeScript types.
|
10
10
|
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
11
|
-
* @default '
|
11
|
+
* @default 'types'
|
12
12
|
*/
|
13
13
|
output?: string;
|
14
14
|
/**
|
@@ -28,7 +28,14 @@ type Options$2 = {
|
|
28
28
|
*/
|
29
29
|
output?: string;
|
30
30
|
};
|
31
|
-
|
31
|
+
/**
|
32
|
+
* Array containing skipBy paramaters to exclude/skip tags/operations/methods/paths.
|
33
|
+
*/
|
34
|
+
skipBy?: Array<SkipBy>;
|
35
|
+
/**
|
36
|
+
* Array containing overrideBy paramaters to override `options` based on tags/operations/methods/paths.
|
37
|
+
*/
|
38
|
+
overrideBy?: Array<OverrideBy<Options$3>>;
|
32
39
|
/**
|
33
40
|
* Choose to use `enum` or `as const` for enums
|
34
41
|
* @default 'asConst'
|
@@ -58,70 +65,52 @@ type FileMeta = {
|
|
58
65
|
pluginName?: string;
|
59
66
|
tag?: string;
|
60
67
|
};
|
61
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$
|
68
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false, unknown, ResolvePathOptions>;
|
62
69
|
|
63
70
|
declare const pluginName: PluginOptions['name'];
|
64
|
-
declare const definePlugin: (options: Options$
|
71
|
+
declare const definePlugin: (options: Options$3) => _kubb_core.KubbUserPlugin<PluginOptions>;
|
65
72
|
|
66
|
-
type Options$
|
73
|
+
type Options$2 = {
|
67
74
|
withJSDocs?: boolean;
|
68
75
|
resolveName: PluginContext['resolveName'];
|
69
76
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
70
77
|
dateType: 'string' | 'date';
|
71
78
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
72
79
|
};
|
73
|
-
declare class TypeGenerator extends SchemaGenerator<Options$
|
80
|
+
declare class TypeGenerator extends SchemaGenerator<Options$2, OpenAPIV3.SchemaObject, ts.Node[]> {
|
81
|
+
#private;
|
74
82
|
static usedEnumNames: Record<string, number>;
|
75
83
|
refs: Refs;
|
76
84
|
extraNodes: ts.Node[];
|
77
85
|
aliases: ts.TypeAliasDeclaration[];
|
78
86
|
usedAliasNames: Record<string, number>;
|
79
|
-
caseOptions: Options$
|
80
|
-
constructor(options?: Options$
|
87
|
+
caseOptions: Options$4;
|
88
|
+
constructor(options?: Options$2);
|
81
89
|
build({ schema, baseName, description, keysToOmit, }: {
|
82
90
|
schema: OpenAPIV3.SchemaObject;
|
83
91
|
baseName: string;
|
84
92
|
description?: string;
|
85
93
|
keysToOmit?: string[];
|
86
94
|
}): ts.Node[];
|
87
|
-
/**
|
88
|
-
* Creates a type node from a given schema.
|
89
|
-
* Delegates to getBaseTypeFromSchema internally and
|
90
|
-
* optionally adds a union with null.
|
91
|
-
*/
|
92
|
-
private getTypeFromSchema;
|
93
|
-
/**
|
94
|
-
* Recursively creates a type literal with the given props.
|
95
|
-
*/
|
96
|
-
private getTypeFromProperties;
|
97
|
-
/**
|
98
|
-
* Create a type alias for the schema referenced by the given ReferenceObject
|
99
|
-
*/
|
100
|
-
private getRefAlias;
|
101
|
-
/**
|
102
|
-
* This is the very core of the OpenAPI to TS conversion - it takes a
|
103
|
-
* schema and returns the appropriate type.
|
104
|
-
*/
|
105
|
-
private getBaseTypeFromSchema;
|
106
95
|
}
|
107
96
|
|
108
|
-
type Options = {
|
97
|
+
type Options$1 = {
|
109
98
|
mode: KubbFile.Mode;
|
110
|
-
enumType: NonNullable<Options$
|
111
|
-
dateType: NonNullable<Options$
|
112
|
-
optionalType: NonNullable<Options$
|
99
|
+
enumType: NonNullable<Options$3['enumType']>;
|
100
|
+
dateType: NonNullable<Options$3['dateType']>;
|
101
|
+
optionalType: NonNullable<Options$3['optionalType']>;
|
113
102
|
};
|
114
|
-
declare class OperationGenerator extends OperationGenerator$1<Options> {
|
103
|
+
declare class OperationGenerator extends OperationGenerator$1<Options$1> {
|
115
104
|
resolve(operation: Operation): Resolver;
|
116
105
|
all(): Promise<KubbFile.File | null>;
|
117
|
-
get(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
118
|
-
post(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
119
|
-
put(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
120
|
-
patch(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
121
|
-
delete(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
106
|
+
get(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
107
|
+
post(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
108
|
+
put(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
109
|
+
patch(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
110
|
+
delete(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
122
111
|
}
|
123
112
|
|
124
|
-
type
|
113
|
+
type Options = {
|
125
114
|
resolveName: PluginContext['resolveName'];
|
126
115
|
fileResolver?: FileResolver;
|
127
116
|
withJSDocs?: boolean;
|
@@ -130,8 +119,8 @@ type Config = {
|
|
130
119
|
dateType: 'string' | 'date';
|
131
120
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
132
121
|
};
|
133
|
-
declare class TypeBuilder extends OasBuilder<
|
134
|
-
configure(
|
122
|
+
declare class TypeBuilder extends OasBuilder<Options, never> {
|
123
|
+
configure(options?: Options): this;
|
135
124
|
print(name?: string): string;
|
136
125
|
}
|
137
126
|
|
@@ -156,4 +145,4 @@ type Props = UseResolveProps & {
|
|
156
145
|
};
|
157
146
|
declare function useResolve(props?: Props): Resolver;
|
158
147
|
|
159
|
-
export { FileMeta, OperationGenerator, Options$
|
148
|
+
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
package/dist/index.d.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
2
|
import { PluginFactoryOptions, SchemaGenerator, PluginContext, KubbFile } from '@kubb/core';
|
3
|
-
import { SkipBy, ResolvePathOptions, OpenAPIV3, Refs, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OasBuilder, FileResolver, ResolveProps, UseResolveProps } from '@kubb/swagger';
|
3
|
+
import { SkipBy, OverrideBy, ResolvePathOptions, OpenAPIV3, Refs, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OasBuilder, FileResolver, ResolveProps, UseResolveProps } from '@kubb/swagger';
|
4
4
|
import ts from 'typescript';
|
5
|
-
import { Options as Options$
|
5
|
+
import { Options as Options$4 } from 'change-case';
|
6
6
|
|
7
|
-
type Options$
|
7
|
+
type Options$3 = {
|
8
8
|
/**
|
9
9
|
* Relative path to save the TypeScript types.
|
10
10
|
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
11
|
-
* @default '
|
11
|
+
* @default 'types'
|
12
12
|
*/
|
13
13
|
output?: string;
|
14
14
|
/**
|
@@ -28,7 +28,14 @@ type Options$2 = {
|
|
28
28
|
*/
|
29
29
|
output?: string;
|
30
30
|
};
|
31
|
-
|
31
|
+
/**
|
32
|
+
* Array containing skipBy paramaters to exclude/skip tags/operations/methods/paths.
|
33
|
+
*/
|
34
|
+
skipBy?: Array<SkipBy>;
|
35
|
+
/**
|
36
|
+
* Array containing overrideBy paramaters to override `options` based on tags/operations/methods/paths.
|
37
|
+
*/
|
38
|
+
overrideBy?: Array<OverrideBy<Options$3>>;
|
32
39
|
/**
|
33
40
|
* Choose to use `enum` or `as const` for enums
|
34
41
|
* @default 'asConst'
|
@@ -58,70 +65,52 @@ type FileMeta = {
|
|
58
65
|
pluginName?: string;
|
59
66
|
tag?: string;
|
60
67
|
};
|
61
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$
|
68
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false, unknown, ResolvePathOptions>;
|
62
69
|
|
63
70
|
declare const pluginName: PluginOptions['name'];
|
64
|
-
declare const definePlugin: (options: Options$
|
71
|
+
declare const definePlugin: (options: Options$3) => _kubb_core.KubbUserPlugin<PluginOptions>;
|
65
72
|
|
66
|
-
type Options$
|
73
|
+
type Options$2 = {
|
67
74
|
withJSDocs?: boolean;
|
68
75
|
resolveName: PluginContext['resolveName'];
|
69
76
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
70
77
|
dateType: 'string' | 'date';
|
71
78
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
72
79
|
};
|
73
|
-
declare class TypeGenerator extends SchemaGenerator<Options$
|
80
|
+
declare class TypeGenerator extends SchemaGenerator<Options$2, OpenAPIV3.SchemaObject, ts.Node[]> {
|
81
|
+
#private;
|
74
82
|
static usedEnumNames: Record<string, number>;
|
75
83
|
refs: Refs;
|
76
84
|
extraNodes: ts.Node[];
|
77
85
|
aliases: ts.TypeAliasDeclaration[];
|
78
86
|
usedAliasNames: Record<string, number>;
|
79
|
-
caseOptions: Options$
|
80
|
-
constructor(options?: Options$
|
87
|
+
caseOptions: Options$4;
|
88
|
+
constructor(options?: Options$2);
|
81
89
|
build({ schema, baseName, description, keysToOmit, }: {
|
82
90
|
schema: OpenAPIV3.SchemaObject;
|
83
91
|
baseName: string;
|
84
92
|
description?: string;
|
85
93
|
keysToOmit?: string[];
|
86
94
|
}): ts.Node[];
|
87
|
-
/**
|
88
|
-
* Creates a type node from a given schema.
|
89
|
-
* Delegates to getBaseTypeFromSchema internally and
|
90
|
-
* optionally adds a union with null.
|
91
|
-
*/
|
92
|
-
private getTypeFromSchema;
|
93
|
-
/**
|
94
|
-
* Recursively creates a type literal with the given props.
|
95
|
-
*/
|
96
|
-
private getTypeFromProperties;
|
97
|
-
/**
|
98
|
-
* Create a type alias for the schema referenced by the given ReferenceObject
|
99
|
-
*/
|
100
|
-
private getRefAlias;
|
101
|
-
/**
|
102
|
-
* This is the very core of the OpenAPI to TS conversion - it takes a
|
103
|
-
* schema and returns the appropriate type.
|
104
|
-
*/
|
105
|
-
private getBaseTypeFromSchema;
|
106
95
|
}
|
107
96
|
|
108
|
-
type Options = {
|
97
|
+
type Options$1 = {
|
109
98
|
mode: KubbFile.Mode;
|
110
|
-
enumType: NonNullable<Options$
|
111
|
-
dateType: NonNullable<Options$
|
112
|
-
optionalType: NonNullable<Options$
|
99
|
+
enumType: NonNullable<Options$3['enumType']>;
|
100
|
+
dateType: NonNullable<Options$3['dateType']>;
|
101
|
+
optionalType: NonNullable<Options$3['optionalType']>;
|
113
102
|
};
|
114
|
-
declare class OperationGenerator extends OperationGenerator$1<Options> {
|
103
|
+
declare class OperationGenerator extends OperationGenerator$1<Options$1> {
|
115
104
|
resolve(operation: Operation): Resolver;
|
116
105
|
all(): Promise<KubbFile.File | null>;
|
117
|
-
get(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
118
|
-
post(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
119
|
-
put(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
120
|
-
patch(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
121
|
-
delete(operation: Operation, schemas: OperationSchemas): Promise<KubbFile.File<FileMeta> | null>;
|
106
|
+
get(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
107
|
+
post(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
108
|
+
put(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
109
|
+
patch(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
110
|
+
delete(operation: Operation, schemas: OperationSchemas, options: Options$1): Promise<KubbFile.File<FileMeta> | null>;
|
122
111
|
}
|
123
112
|
|
124
|
-
type
|
113
|
+
type Options = {
|
125
114
|
resolveName: PluginContext['resolveName'];
|
126
115
|
fileResolver?: FileResolver;
|
127
116
|
withJSDocs?: boolean;
|
@@ -130,8 +119,8 @@ type Config = {
|
|
130
119
|
dateType: 'string' | 'date';
|
131
120
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
132
121
|
};
|
133
|
-
declare class TypeBuilder extends OasBuilder<
|
134
|
-
configure(
|
122
|
+
declare class TypeBuilder extends OasBuilder<Options, never> {
|
123
|
+
configure(options?: Options): this;
|
135
124
|
print(name?: string): string;
|
136
125
|
}
|
137
126
|
|
@@ -156,4 +145,4 @@ type Props = UseResolveProps & {
|
|
156
145
|
};
|
157
146
|
declare function useResolve(props?: Props): Resolver;
|
158
147
|
|
159
|
-
export { FileMeta, OperationGenerator, Options$
|
148
|
+
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
package/dist/index.js
CHANGED
@@ -47,7 +47,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
47
47
|
keysToOmit
|
48
48
|
}) {
|
49
49
|
const nodes = [];
|
50
|
-
const type = this
|
50
|
+
const type = this.#getTypeFromSchema(schema, baseName);
|
51
51
|
if (!type) {
|
52
52
|
return this.extraNodes;
|
53
53
|
}
|
@@ -78,8 +78,8 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
78
78
|
* Delegates to getBaseTypeFromSchema internally and
|
79
79
|
* optionally adds a union with null.
|
80
80
|
*/
|
81
|
-
getTypeFromSchema(schema, name) {
|
82
|
-
const type = this
|
81
|
+
#getTypeFromSchema(schema, name) {
|
82
|
+
const type = this.#getBaseTypeFromSchema(schema, name);
|
83
83
|
if (!type) {
|
84
84
|
return null;
|
85
85
|
}
|
@@ -91,7 +91,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
91
91
|
/**
|
92
92
|
* Recursively creates a type literal with the given props.
|
93
93
|
*/
|
94
|
-
getTypeFromProperties(baseSchema, baseName) {
|
94
|
+
#getTypeFromProperties(baseSchema, baseName) {
|
95
95
|
const { optionalType } = this.options;
|
96
96
|
const properties = baseSchema?.properties || {};
|
97
97
|
const required = baseSchema?.required;
|
@@ -99,7 +99,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
99
99
|
const members = Object.keys(properties).map((name) => {
|
100
100
|
const schema = properties[name];
|
101
101
|
const isRequired = required && required.includes(name);
|
102
|
-
let type = this
|
102
|
+
let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ""} ${name}`, pluginName }));
|
103
103
|
if (!type) {
|
104
104
|
return null;
|
105
105
|
}
|
@@ -128,7 +128,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
128
128
|
return propertySignature;
|
129
129
|
});
|
130
130
|
if (additionalProperties) {
|
131
|
-
const type = additionalProperties === true ? keywordTypeNodes.any : this
|
131
|
+
const type = additionalProperties === true ? keywordTypeNodes.any : this.#getTypeFromSchema(additionalProperties);
|
132
132
|
if (type) {
|
133
133
|
members.push(createIndexSignature(type));
|
134
134
|
}
|
@@ -138,7 +138,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
138
138
|
/**
|
139
139
|
* Create a type alias for the schema referenced by the given ReferenceObject
|
140
140
|
*/
|
141
|
-
getRefAlias(obj, baseName) {
|
141
|
+
#getRefAlias(obj, baseName) {
|
142
142
|
const { $ref } = obj;
|
143
143
|
let ref = this.refs[$ref];
|
144
144
|
if (ref) {
|
@@ -156,26 +156,26 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
156
156
|
* This is the very core of the OpenAPI to TS conversion - it takes a
|
157
157
|
* schema and returns the appropriate type.
|
158
158
|
*/
|
159
|
-
getBaseTypeFromSchema(schema, baseName) {
|
159
|
+
#getBaseTypeFromSchema(schema, baseName) {
|
160
160
|
if (!schema) {
|
161
161
|
return keywordTypeNodes.any;
|
162
162
|
}
|
163
163
|
if (isReference(schema)) {
|
164
|
-
return this
|
164
|
+
return this.#getRefAlias(schema, baseName);
|
165
165
|
}
|
166
166
|
if (schema.oneOf) {
|
167
167
|
const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
|
168
168
|
const union = createUnionDeclaration({
|
169
169
|
withParentheses: true,
|
170
170
|
nodes: schema.oneOf.map((item) => {
|
171
|
-
return this
|
171
|
+
return this.#getBaseTypeFromSchema(item);
|
172
172
|
}).filter((item) => {
|
173
173
|
return item && item !== keywordTypeNodes.any;
|
174
174
|
})
|
175
175
|
});
|
176
176
|
if (schemaWithoutOneOf.properties) {
|
177
177
|
return createIntersectionDeclaration({
|
178
|
-
nodes: [this
|
178
|
+
nodes: [this.#getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
179
179
|
});
|
180
180
|
}
|
181
181
|
return union;
|
@@ -185,14 +185,14 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
185
185
|
const union = createUnionDeclaration({
|
186
186
|
withParentheses: true,
|
187
187
|
nodes: schema.anyOf.map((item) => {
|
188
|
-
return this
|
188
|
+
return this.#getBaseTypeFromSchema(item);
|
189
189
|
}).filter((item) => {
|
190
190
|
return item && item !== keywordTypeNodes.any;
|
191
191
|
})
|
192
192
|
});
|
193
193
|
if (schemaWithoutAnyOf.properties) {
|
194
194
|
return createIntersectionDeclaration({
|
195
|
-
nodes: [this
|
195
|
+
nodes: [this.#getBaseTypeFromSchema(schemaWithoutAnyOf, baseName), union].filter(Boolean)
|
196
196
|
});
|
197
197
|
}
|
198
198
|
return union;
|
@@ -202,14 +202,14 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
202
202
|
const and = createIntersectionDeclaration({
|
203
203
|
withParentheses: true,
|
204
204
|
nodes: schema.allOf.map((item) => {
|
205
|
-
return this
|
205
|
+
return this.#getBaseTypeFromSchema(item);
|
206
206
|
}).filter((item) => {
|
207
207
|
return item && item !== keywordTypeNodes.any;
|
208
208
|
})
|
209
209
|
});
|
210
210
|
if (schemaWithoutAllOf.properties) {
|
211
211
|
return createIntersectionDeclaration({
|
212
|
-
nodes: [this
|
212
|
+
nodes: [this.#getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
213
213
|
});
|
214
214
|
}
|
215
215
|
return and;
|
@@ -240,7 +240,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
240
240
|
});
|
241
241
|
}
|
242
242
|
if ("items" in schema) {
|
243
|
-
const node = this
|
243
|
+
const node = this.#getTypeFromSchema(schema.items, baseName);
|
244
244
|
if (node) {
|
245
245
|
return factory2.createArrayTypeNode(node);
|
246
246
|
}
|
@@ -249,19 +249,19 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
249
249
|
const prefixItems = schema.prefixItems;
|
250
250
|
return createTupleDeclaration({
|
251
251
|
nodes: prefixItems.map((item) => {
|
252
|
-
return this
|
252
|
+
return this.#getBaseTypeFromSchema(item, void 0);
|
253
253
|
})
|
254
254
|
});
|
255
255
|
}
|
256
256
|
if (schema.properties || schema.additionalProperties) {
|
257
|
-
return this
|
257
|
+
return this.#getTypeFromProperties(schema, baseName);
|
258
258
|
}
|
259
259
|
if (schema.type) {
|
260
260
|
if (Array.isArray(schema.type)) {
|
261
261
|
const [type, nullable] = schema.type;
|
262
262
|
return createUnionDeclaration({
|
263
263
|
nodes: [
|
264
|
-
this
|
264
|
+
this.#getBaseTypeFromSchema(
|
265
265
|
{
|
266
266
|
...schema,
|
267
267
|
type
|
@@ -297,10 +297,12 @@ function refsSorter(a, b) {
|
|
297
297
|
return 0;
|
298
298
|
}
|
299
299
|
var TypeBuilder = class extends OasBuilder {
|
300
|
-
configure(
|
301
|
-
|
302
|
-
|
303
|
-
|
300
|
+
configure(options) {
|
301
|
+
if (options) {
|
302
|
+
this.options = options;
|
303
|
+
}
|
304
|
+
if (this.options.fileResolver) {
|
305
|
+
this.options.withImports = true;
|
304
306
|
}
|
305
307
|
return this;
|
306
308
|
}
|
@@ -308,11 +310,11 @@ var TypeBuilder = class extends OasBuilder {
|
|
308
310
|
const codes = [];
|
309
311
|
const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(nameSorter).map((operationSchema) => {
|
310
312
|
const generator = new TypeGenerator({
|
311
|
-
withJSDocs: this.
|
312
|
-
resolveName: this.
|
313
|
-
enumType: this.
|
314
|
-
dateType: this.
|
315
|
-
optionalType: this.
|
313
|
+
withJSDocs: this.options.withJSDocs,
|
314
|
+
resolveName: this.options.resolveName,
|
315
|
+
enumType: this.options.enumType,
|
316
|
+
dateType: this.options.dateType,
|
317
|
+
optionalType: this.options.optionalType
|
316
318
|
});
|
317
319
|
const sources = generator.build({
|
318
320
|
schema: operationSchema.schema,
|
@@ -331,8 +333,8 @@ var TypeBuilder = class extends OasBuilder {
|
|
331
333
|
generated.forEach((item) => {
|
332
334
|
codes.push(print(item.sources));
|
333
335
|
});
|
334
|
-
if (this.
|
335
|
-
const importsGenerator = new ImportsGenerator({ fileResolver: this.
|
336
|
+
if (this.options.withImports) {
|
337
|
+
const importsGenerator = new ImportsGenerator({ fileResolver: this.options.fileResolver });
|
336
338
|
const importMeta = importsGenerator.build(generated.map((item) => item.import));
|
337
339
|
if (importMeta) {
|
338
340
|
const nodes = importMeta.map((item) => {
|
@@ -350,7 +352,7 @@ var TypeBuilder = class extends OasBuilder {
|
|
350
352
|
};
|
351
353
|
var OperationGenerator = class extends OperationGenerator$1 {
|
352
354
|
resolve(operation) {
|
353
|
-
const { pluginManager } = this.
|
355
|
+
const { pluginManager } = this.context;
|
354
356
|
return resolve$1({
|
355
357
|
operation,
|
356
358
|
resolveName: pluginManager.resolveName,
|
@@ -361,8 +363,9 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
361
363
|
async all() {
|
362
364
|
return null;
|
363
365
|
}
|
364
|
-
async get(operation, schemas) {
|
365
|
-
const {
|
366
|
+
async get(operation, schemas, options) {
|
367
|
+
const { mode, enumType, dateType, optionalType } = options;
|
368
|
+
const { pluginManager } = this.context;
|
366
369
|
const type = this.resolve(operation);
|
367
370
|
const fileResolver = (name) => {
|
368
371
|
const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
@@ -372,14 +375,14 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
372
375
|
});
|
373
376
|
return getRelativePath(root, resolvedTypeId);
|
374
377
|
};
|
375
|
-
const source = new TypeBuilder(
|
378
|
+
const source = new TypeBuilder({
|
376
379
|
fileResolver: mode === "file" ? void 0 : fileResolver,
|
377
380
|
withJSDocs: true,
|
378
381
|
resolveName: pluginManager.resolveName,
|
379
382
|
enumType,
|
380
383
|
optionalType,
|
381
384
|
dateType
|
382
|
-
}).print();
|
385
|
+
}).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
|
383
386
|
return {
|
384
387
|
path: type.path,
|
385
388
|
baseName: type.baseName,
|
@@ -390,8 +393,9 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
390
393
|
}
|
391
394
|
};
|
392
395
|
}
|
393
|
-
async post(operation, schemas) {
|
394
|
-
const {
|
396
|
+
async post(operation, schemas, options) {
|
397
|
+
const { mode, enumType, dateType, optionalType } = options;
|
398
|
+
const { pluginManager } = this.context;
|
395
399
|
const type = this.resolve(operation);
|
396
400
|
const fileResolver = (name) => {
|
397
401
|
const root = pluginManager.resolvePath({ baseName: type.baseName, pluginName, options: { tag: operation.getTags()[0]?.name } });
|
@@ -401,14 +405,14 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
401
405
|
});
|
402
406
|
return getRelativePath(root, resolvedTypeId);
|
403
407
|
};
|
404
|
-
const source = new TypeBuilder(
|
408
|
+
const source = new TypeBuilder({
|
405
409
|
fileResolver: mode === "file" ? void 0 : fileResolver,
|
406
410
|
withJSDocs: true,
|
407
411
|
resolveName: pluginManager.resolveName,
|
408
412
|
enumType,
|
409
413
|
optionalType,
|
410
414
|
dateType
|
411
|
-
}).print();
|
415
|
+
}).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
|
412
416
|
return {
|
413
417
|
path: type.path,
|
414
418
|
baseName: type.baseName,
|
@@ -419,21 +423,30 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
419
423
|
}
|
420
424
|
};
|
421
425
|
}
|
422
|
-
async put(operation, schemas) {
|
423
|
-
return this.post(operation, schemas);
|
426
|
+
async put(operation, schemas, options) {
|
427
|
+
return this.post(operation, schemas, options);
|
424
428
|
}
|
425
|
-
async patch(operation, schemas) {
|
426
|
-
return this.post(operation, schemas);
|
429
|
+
async patch(operation, schemas, options) {
|
430
|
+
return this.post(operation, schemas, options);
|
427
431
|
}
|
428
|
-
async delete(operation, schemas) {
|
429
|
-
return this.post(operation, schemas);
|
432
|
+
async delete(operation, schemas, options) {
|
433
|
+
return this.post(operation, schemas, options);
|
430
434
|
}
|
431
435
|
};
|
432
436
|
|
433
437
|
// src/plugin.ts
|
434
438
|
var pluginName = "swagger-ts";
|
435
439
|
var definePlugin = createPlugin((options) => {
|
436
|
-
const {
|
440
|
+
const {
|
441
|
+
output = "types",
|
442
|
+
groupBy,
|
443
|
+
skipBy = [],
|
444
|
+
overrideBy = [],
|
445
|
+
enumType = "asConst",
|
446
|
+
dateType = "string",
|
447
|
+
optionalType = "questionToken",
|
448
|
+
transformers = {}
|
449
|
+
} = options;
|
437
450
|
const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`;
|
438
451
|
let pluginsOptions;
|
439
452
|
return {
|
@@ -473,7 +486,7 @@ var definePlugin = createPlugin((options) => {
|
|
473
486
|
const root = pathParser.resolve(this.config.root, this.config.output.path);
|
474
487
|
const mode = getPathMode(pathParser.resolve(root, output));
|
475
488
|
if (mode === "directory") {
|
476
|
-
const builder = await new TypeBuilder(
|
489
|
+
const builder = await new TypeBuilder({
|
477
490
|
resolveName: (params) => this.resolveName({ pluginName, ...params }),
|
478
491
|
fileResolver: (name) => {
|
479
492
|
const resolvedTypeId = this.resolvePath({
|
@@ -487,7 +500,7 @@ var definePlugin = createPlugin((options) => {
|
|
487
500
|
enumType,
|
488
501
|
dateType,
|
489
502
|
optionalType
|
490
|
-
});
|
503
|
+
}).configure();
|
491
504
|
Object.entries(schemas).forEach(([name, schema]) => {
|
492
505
|
return builder.add({
|
493
506
|
schema,
|
@@ -512,13 +525,13 @@ var definePlugin = createPlugin((options) => {
|
|
512
525
|
await Promise.all(promises);
|
513
526
|
}
|
514
527
|
if (mode === "file") {
|
515
|
-
const builder = new TypeBuilder(
|
528
|
+
const builder = new TypeBuilder({
|
516
529
|
resolveName: (params) => this.resolveName({ pluginName, ...params }),
|
517
530
|
withJSDocs: true,
|
518
531
|
enumType,
|
519
532
|
dateType,
|
520
533
|
optionalType
|
521
|
-
});
|
534
|
+
}).configure();
|
522
535
|
Object.entries(schemas).forEach(([name, schema]) => {
|
523
536
|
return builder.add({
|
524
537
|
schema,
|
@@ -538,16 +551,21 @@ var definePlugin = createPlugin((options) => {
|
|
538
551
|
}
|
539
552
|
});
|
540
553
|
}
|
541
|
-
const operationGenerator = new OperationGenerator(
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
554
|
+
const operationGenerator = new OperationGenerator(
|
555
|
+
{
|
556
|
+
mode,
|
557
|
+
enumType,
|
558
|
+
dateType,
|
559
|
+
optionalType
|
560
|
+
},
|
561
|
+
{
|
562
|
+
oas,
|
563
|
+
pluginManager: this.pluginManager,
|
564
|
+
contentType: swaggerPlugin.api.contentType,
|
565
|
+
skipBy,
|
566
|
+
overrideBy
|
567
|
+
}
|
568
|
+
);
|
551
569
|
const files = await operationGenerator.build();
|
552
570
|
await this.addFile(...files);
|
553
571
|
},
|