openapi-ts-generator 9.24.2 → 9.28.4
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/enums/enum-helpers.d.ts +1 -1
- package/enums/enum-helpers.js +6 -9
- package/enums/enum-properties.js +1 -1
- package/enums/enum-value.d.ts +3 -3
- package/generators/barrel.generator.js +13 -34
- package/generators/base.generator.js +16 -18
- package/generators/endpoints.generator.js +23 -63
- package/generators/enum.generator.js +13 -33
- package/generators/form-group-factory.generator.js +59 -48
- package/generators/form.generator.js +14 -33
- package/generators/model-properties.generator.js +15 -33
- package/generators/model.generator.js +14 -34
- package/generators/test-object-factory.generator.js +14 -33
- package/index.js +72 -92
- package/models/generator-options.js +19 -21
- package/models/logger.js +6 -9
- package/models/nrsrx-filters.js +3 -4
- package/models/schema-info.d.ts +1 -1
- package/models/schema-info.js +7 -9
- package/openapidoc-converter.d.ts +1 -1
- package/openapidoc-converter.js +164 -180
- package/package.json +24 -23
package/openapidoc-converter.js
CHANGED
|
@@ -1,53 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.OpenApiDocConverter = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-type-conversion */
|
|
5
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
7
|
+
const generator_options_1 = require("./models/generator-options");
|
|
8
|
+
const schema_info_1 = require("./models/schema-info");
|
|
9
|
+
const pluralize_1 = require("pluralize");
|
|
10
|
+
const lodash_1 = require("lodash");
|
|
11
|
+
class OpenApiDocConverter {
|
|
12
|
+
constructor(options, apiDocument) {
|
|
21
13
|
this.options = options;
|
|
22
14
|
this.apiDocument = apiDocument;
|
|
23
15
|
this.endAlphaNumRegex = /[A-z0-9]*$/s;
|
|
24
16
|
this.startNumberregex = /^\d*/;
|
|
25
17
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return { entities
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
for (
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
convertDocument() {
|
|
19
|
+
const entities = this.convertEntities();
|
|
20
|
+
const paths = this.convertPaths();
|
|
21
|
+
return { entities, paths };
|
|
22
|
+
}
|
|
23
|
+
convertPaths() {
|
|
24
|
+
const paths = [];
|
|
25
|
+
for (const key in this.apiDocument.paths) {
|
|
26
|
+
const path = this.apiDocument.paths[key];
|
|
27
|
+
let tagLookup = path.get || path.post || path.put;
|
|
36
28
|
tagLookup = tagLookup || path.delete || path.patch;
|
|
37
|
-
|
|
29
|
+
const tag = (tagLookup?.tags || ['unknown_endpoint'])[0];
|
|
38
30
|
paths.push({
|
|
39
31
|
tag: (0, lodash_1.snakeCase)(tag),
|
|
40
32
|
endpoint: this.options.pathUrlFormattingCallBack ? this.options.pathUrlFormattingCallBack(key) : key,
|
|
41
33
|
});
|
|
42
34
|
}
|
|
43
35
|
return paths;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var schemaWrapperInfo = new schema_info_1.SchemaWrapperInfo((_c = this.apiDocument.components) === null || _c === void 0 ? void 0 : _c.schemas[schemaName]);
|
|
36
|
+
}
|
|
37
|
+
convertEntities() {
|
|
38
|
+
const entities = [];
|
|
39
|
+
for (const schemaName in this.apiDocument.components?.schemas) {
|
|
40
|
+
if (this.apiDocument.components.schemas[schemaName]) {
|
|
41
|
+
const schemaWrapperInfo = new schema_info_1.SchemaWrapperInfo(this.apiDocument.components?.schemas[schemaName]);
|
|
51
42
|
if (schemaWrapperInfo.componentSchemaObject.enum) {
|
|
52
43
|
this.buildSchemaWrapperInfoForEnum(schemaWrapperInfo);
|
|
53
44
|
}
|
|
@@ -55,14 +46,14 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
55
46
|
this.buildSchemaWrapperInfo(schemaName, schemaWrapperInfo);
|
|
56
47
|
}
|
|
57
48
|
schemaWrapperInfo.updateReferenceProperties(this.options);
|
|
58
|
-
|
|
49
|
+
const entity = {
|
|
59
50
|
isEnum: schemaWrapperInfo.isEnum,
|
|
60
|
-
enumValues: schemaWrapperInfo.enumValues.map(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
enumValues: schemaWrapperInfo.enumValues.map((t) => typeof t === 'string' || t instanceof String
|
|
52
|
+
? t
|
|
53
|
+
: {
|
|
54
|
+
...t,
|
|
55
|
+
key: t.key ?? 0,
|
|
56
|
+
}),
|
|
66
57
|
name: schemaName,
|
|
67
58
|
kebabCasedName: (0, lodash_1.kebabCase)(schemaName),
|
|
68
59
|
singularName: (0, pluralize_1.singular)(schemaName),
|
|
@@ -76,25 +67,22 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
return entities.filter(this.options.typeFilterCallBack || generator_options_1.defaultFilter);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var _a;
|
|
82
|
-
var _this = this;
|
|
70
|
+
}
|
|
71
|
+
buildSchemaWrapperInfoForEnum(schemaWrapperInfo) {
|
|
83
72
|
schemaWrapperInfo.isEnum = true;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var name = (_c = (_b = _this.endAlphaNumRegex.exec(x)) === null || _b === void 0 ? void 0 : _b.at(0)) !== null && _c !== void 0 ? _c : '';
|
|
73
|
+
schemaWrapperInfo.enumValues.push(...(schemaWrapperInfo.componentSchemaObject.enum || []).map((x) => {
|
|
74
|
+
const key = this.startNumberregex.exec(x)?.at(0);
|
|
75
|
+
const name = this.endAlphaNumRegex.exec(x)?.at(0) ?? '';
|
|
88
76
|
return {
|
|
89
77
|
key: key ? +key : 0,
|
|
90
|
-
name
|
|
78
|
+
name,
|
|
91
79
|
titleName: (0, lodash_1.startCase)(name),
|
|
92
80
|
snakeCaseName: (0, lodash_1.snakeCase)(name).toUpperCase(),
|
|
93
81
|
};
|
|
94
82
|
}));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
for (
|
|
83
|
+
}
|
|
84
|
+
buildSchemaWrapperInfo(parentTypeName, schemaWrapperInfo) {
|
|
85
|
+
for (const propertyName in schemaWrapperInfo.componentSchemaObject.properties) {
|
|
98
86
|
if ((schemaWrapperInfo.propertySchemaObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName]).type && // NOSONAR
|
|
99
87
|
schemaWrapperInfo.propertySchemaObject.type !== 'array') {
|
|
100
88
|
schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo));
|
|
@@ -109,9 +97,9 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
109
97
|
}
|
|
110
98
|
}
|
|
111
99
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
100
|
+
}
|
|
101
|
+
convertArray(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
102
|
+
const arraySchemaObject = schemaWrapperInfo.propertySchemaObject.items;
|
|
115
103
|
if (arraySchemaObject.type) {
|
|
116
104
|
schemaWrapperInfo.valueProperties.push(this.convertArrayObjectToValuePropertyType(parentTypeName, propertyName, schemaWrapperInfo));
|
|
117
105
|
}
|
|
@@ -119,20 +107,19 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
119
107
|
schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.propertySchemaObject.items;
|
|
120
108
|
schemaWrapperInfo.referenceProperties.push(this.convertArrayObjectToReferencePropertyType(parentTypeName, propertyName, schemaWrapperInfo));
|
|
121
109
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
110
|
+
}
|
|
111
|
+
convertSchemaObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
112
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
113
|
+
const validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
114
|
+
const initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
128
115
|
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
129
116
|
: 'undefined';
|
|
130
|
-
|
|
117
|
+
const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
131
118
|
return {
|
|
132
|
-
required
|
|
119
|
+
required,
|
|
133
120
|
name: propertyName,
|
|
134
|
-
initialValue
|
|
135
|
-
initialTestValue
|
|
121
|
+
initialValue,
|
|
122
|
+
initialTestValue,
|
|
136
123
|
isArray: false,
|
|
137
124
|
snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
|
|
138
125
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
@@ -140,8 +127,8 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
140
127
|
minLength: schemaWrapperInfo.propertySchemaObject.minLength,
|
|
141
128
|
maximum: schemaWrapperInfo.propertySchemaObject.maximum,
|
|
142
129
|
minimum: schemaWrapperInfo.propertySchemaObject.minimum,
|
|
143
|
-
email:
|
|
144
|
-
uri:
|
|
130
|
+
email: schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'email',
|
|
131
|
+
uri: schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'uri',
|
|
145
132
|
minItems: schemaWrapperInfo.propertySchemaObject.minItems,
|
|
146
133
|
maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
|
|
147
134
|
description: schemaWrapperInfo.propertySchemaObject.description,
|
|
@@ -149,23 +136,23 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
149
136
|
hasMultipleValidators: validatorCount > 1,
|
|
150
137
|
hasValidators: validatorCount > 0,
|
|
151
138
|
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
}
|
|
140
|
+
convertValidator(validationValue) {
|
|
141
|
+
const exists = validationValue !== null && validationValue !== undefined;
|
|
155
142
|
return +exists;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
143
|
+
}
|
|
144
|
+
convertArrayObjectToValuePropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
145
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
146
|
+
const validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
147
|
+
const initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
161
148
|
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
162
149
|
: 'undefined';
|
|
163
|
-
|
|
150
|
+
const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
164
151
|
return {
|
|
165
|
-
required
|
|
152
|
+
required,
|
|
166
153
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
167
|
-
initialValue
|
|
168
|
-
initialTestValue
|
|
154
|
+
initialValue,
|
|
155
|
+
initialTestValue,
|
|
169
156
|
name: propertyName,
|
|
170
157
|
email: false,
|
|
171
158
|
uri: false,
|
|
@@ -174,23 +161,21 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
174
161
|
hasMultipleValidators: false,
|
|
175
162
|
hasValidators: validatorCount > 0,
|
|
176
163
|
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
var refObject = (((_b = this.apiDocument.components) === null || _b === void 0 ? void 0 : _b.schemas) || {})[refName];
|
|
185
|
-
var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
|
|
164
|
+
}
|
|
165
|
+
getInitialValue(propertyName, schemaWrapperInfo) {
|
|
166
|
+
const typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
|
|
167
|
+
const isRequired = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
168
|
+
const refName = (schemaWrapperInfo?.componentSchemaObject?.properties?.[propertyName]).$ref;
|
|
169
|
+
const refObject = this.apiDocument.components?.schemas?.[refName];
|
|
170
|
+
const defaultValue = (schemaWrapperInfo.componentSchemaObject.default || refObject?.default || (refObject?.enum || [])[0]);
|
|
186
171
|
if (!isRequired) {
|
|
187
172
|
return 'null';
|
|
188
173
|
}
|
|
189
174
|
else if (defaultValue && refObject.enum) {
|
|
190
|
-
return
|
|
175
|
+
return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
|
|
191
176
|
}
|
|
192
177
|
else if (defaultValue) {
|
|
193
|
-
return
|
|
178
|
+
return `'${defaultValue.split(' ').pop()}'`;
|
|
194
179
|
}
|
|
195
180
|
else if (typescriptType === 'Date') {
|
|
196
181
|
return 'new Date()';
|
|
@@ -202,35 +187,33 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
202
187
|
return '0';
|
|
203
188
|
}
|
|
204
189
|
else {
|
|
205
|
-
return
|
|
190
|
+
return `''`;
|
|
206
191
|
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
var refObject = ((_f = (_e = this.apiDocument.components) === null || _e === void 0 ? void 0 : _e.schemas) !== null && _f !== void 0 ? _f : {})[refName];
|
|
219
|
-
var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
|
|
192
|
+
}
|
|
193
|
+
getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
194
|
+
const typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
|
|
195
|
+
const schemaObject = schemaWrapperInfo?.componentSchemaObject?.properties?.[propertyName];
|
|
196
|
+
const maxLength = schemaWrapperInfo.propertySchemaObject.maxLength;
|
|
197
|
+
const minLength = schemaWrapperInfo.propertySchemaObject.minLength;
|
|
198
|
+
const minValue = schemaWrapperInfo.propertySchemaObject.minimum;
|
|
199
|
+
const email = schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'email';
|
|
200
|
+
const refName = schemaObject?.$ref || schemaObject.items?.$ref;
|
|
201
|
+
const refObject = this.apiDocument.components?.schemas?.[refName];
|
|
202
|
+
const defaultValue = (schemaWrapperInfo.componentSchemaObject.default || refObject?.default || (refObject?.enum || [])[0]);
|
|
220
203
|
if (defaultValue && refObject.enum && schemaObject.type === 'array') {
|
|
221
|
-
return
|
|
204
|
+
return `[${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}]`;
|
|
222
205
|
}
|
|
223
206
|
else if (defaultValue && refObject.enum) {
|
|
224
|
-
return
|
|
207
|
+
return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
|
|
225
208
|
}
|
|
226
209
|
else if (refObject) {
|
|
227
|
-
return schemaObject.type === 'array' ?
|
|
210
|
+
return schemaObject.type === 'array' ? `[]` : `undefined`;
|
|
228
211
|
}
|
|
229
212
|
else if (defaultValue) {
|
|
230
|
-
return
|
|
213
|
+
return `'${defaultValue.split(' ').pop()}'`;
|
|
231
214
|
}
|
|
232
215
|
else if (email) {
|
|
233
|
-
return
|
|
216
|
+
return `'${(0, lodash_1.kebabCase)(parentTypeName)}@email.org'`;
|
|
234
217
|
}
|
|
235
218
|
else if (typescriptType === 'Date') {
|
|
236
219
|
return 'new Date()';
|
|
@@ -239,65 +222,66 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
239
222
|
return 'false';
|
|
240
223
|
}
|
|
241
224
|
else if (typescriptType === 'number' && schemaObject.type === 'array') {
|
|
242
|
-
return minValue ?
|
|
225
|
+
return minValue ? `[${minValue}]` : '[0]';
|
|
243
226
|
}
|
|
244
227
|
else if (schemaObject.type === 'array') {
|
|
245
|
-
return defaultValue ?
|
|
228
|
+
return defaultValue ? `[${defaultValue}]` : '[]';
|
|
246
229
|
}
|
|
247
230
|
else if (typescriptType === 'number') {
|
|
248
|
-
return minValue ?
|
|
231
|
+
return minValue ? `${minValue}` : '0';
|
|
249
232
|
}
|
|
250
233
|
else {
|
|
251
|
-
|
|
234
|
+
let retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
|
|
252
235
|
while (minLength && retValue.length < minLength) {
|
|
253
|
-
retValue =
|
|
236
|
+
retValue = `${retValue}_${retValue}`;
|
|
254
237
|
}
|
|
255
|
-
return
|
|
238
|
+
return `'${maxLength ? retValue.substring(0, maxLength) : retValue}'`;
|
|
256
239
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
240
|
+
}
|
|
241
|
+
convertArrayObjectToReferencePropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
242
|
+
const refProperty = {
|
|
243
|
+
...this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo),
|
|
244
|
+
isArray: true,
|
|
245
|
+
};
|
|
260
246
|
refProperty.isEnumAndArray = refProperty.isEnum && refProperty.isArray;
|
|
261
247
|
return refProperty;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
248
|
+
}
|
|
249
|
+
convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
250
|
+
const propertySchema = this.apiDocument.components?.schemas?.[this.parseRef(schemaWrapperInfo)];
|
|
251
|
+
const refSchema = schemaWrapperInfo?.componentSchemaObject?.properties?.[propertyName];
|
|
252
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
253
|
+
const validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
254
|
+
const initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
270
255
|
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
271
256
|
: 'undefined';
|
|
272
|
-
|
|
273
|
-
|
|
257
|
+
const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
258
|
+
const typeName = this.parseRef(schemaWrapperInfo);
|
|
274
259
|
return {
|
|
275
|
-
required
|
|
260
|
+
required,
|
|
276
261
|
name: propertyName,
|
|
277
262
|
isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
|
|
278
|
-
initialValue
|
|
279
|
-
initialTestValue
|
|
263
|
+
initialValue,
|
|
264
|
+
initialTestValue,
|
|
280
265
|
snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
|
|
281
266
|
referenceTypeName: typeName,
|
|
282
267
|
typeScriptType: typeName,
|
|
283
268
|
isArray: false,
|
|
284
|
-
isEnum: (
|
|
269
|
+
isEnum: (propertySchema?.enum ?? []).length > 0,
|
|
285
270
|
isEnumAndArray: false,
|
|
286
271
|
hasValidators: validatorCount > 0,
|
|
287
272
|
hasMultipleValidators: validatorCount > 1,
|
|
288
|
-
maxLength: refSchema
|
|
289
|
-
minLength: refSchema
|
|
290
|
-
maximum: refSchema
|
|
291
|
-
minimum: refSchema
|
|
292
|
-
minItems: refSchema
|
|
293
|
-
maxItems: refSchema
|
|
273
|
+
maxLength: refSchema?.maxLength,
|
|
274
|
+
minLength: refSchema?.minLength,
|
|
275
|
+
maximum: refSchema?.maximum,
|
|
276
|
+
minimum: refSchema?.minimum,
|
|
277
|
+
minItems: refSchema?.minItems,
|
|
278
|
+
maxItems: refSchema?.maxItems,
|
|
294
279
|
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
var uri = ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'uri' || false;
|
|
280
|
+
}
|
|
281
|
+
getValidatorCount(propertyName, schemaWrapperInfo) {
|
|
282
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
283
|
+
const email = schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'email' || false;
|
|
284
|
+
const uri = schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'uri' || false;
|
|
301
285
|
return (+required +
|
|
302
286
|
+email +
|
|
303
287
|
+uri +
|
|
@@ -308,11 +292,10 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
308
292
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxItems) +
|
|
309
293
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.minItems) +
|
|
310
294
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
var _a;
|
|
295
|
+
}
|
|
296
|
+
getPropertyTypeScriptType(schemaWrapperInfo) {
|
|
314
297
|
if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
|
|
315
|
-
|
|
298
|
+
const type = schemaWrapperInfo.propertySchemaObject.items.type;
|
|
316
299
|
return type === 'integer' ? 'number' : type;
|
|
317
300
|
}
|
|
318
301
|
else if (schemaWrapperInfo.propertySchemaObject.type === 'integer' && schemaWrapperInfo.propertySchemaObject.enum) {
|
|
@@ -324,11 +307,11 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
324
307
|
else if (schemaWrapperInfo.propertySchemaObject.format === 'date' || schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
|
|
325
308
|
return 'Date';
|
|
326
309
|
}
|
|
327
|
-
return
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
310
|
+
return schemaWrapperInfo.propertySchemaObject.type ?? 'string';
|
|
311
|
+
}
|
|
312
|
+
parseRef(schemaWrapperInfo) {
|
|
313
|
+
let regexResult;
|
|
314
|
+
let result = null;
|
|
332
315
|
if (schemaWrapperInfo.propertyReferenceObject.$ref &&
|
|
333
316
|
// tslint:disable-next-line: no-conditional-assignment
|
|
334
317
|
(regexResult = this.endAlphaNumRegex.exec(schemaWrapperInfo.propertyReferenceObject.$ref)) // NOSONAR
|
|
@@ -337,37 +320,38 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
337
320
|
result = schemaWrapperInfo.propertyReferenceObject.$ref;
|
|
338
321
|
}
|
|
339
322
|
return result || 'unknown';
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
323
|
+
}
|
|
324
|
+
getImportTypes(entityName, schemaWrapperInfo) {
|
|
325
|
+
const schemaProperties = (this.apiDocument.components?.schemas ?? { [entityName]: { properties: {} } })[entityName].properties ?? {};
|
|
326
|
+
const properties = Object.keys(schemaProperties).map((key) => ({
|
|
327
|
+
key,
|
|
328
|
+
...schemaProperties[key],
|
|
329
|
+
$ref: schemaProperties[key].$ref,
|
|
330
|
+
items: schemaProperties[key].items || {},
|
|
331
|
+
type: schemaProperties[key].type,
|
|
332
|
+
}));
|
|
348
333
|
return schemaWrapperInfo.referenceProperties
|
|
349
|
-
.map(
|
|
350
|
-
.filter(
|
|
351
|
-
.map(
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
var props = properties.filter(function (t) { return t.items.$ref === value || t.$ref === value; });
|
|
334
|
+
.map((t) => t.referenceTypeName)
|
|
335
|
+
.filter((value, index, array) => array.indexOf(value) === index)
|
|
336
|
+
.map((value) => {
|
|
337
|
+
const refSchema = this.apiDocument.components?.schemas?.[value];
|
|
338
|
+
const props = properties.filter((t) => t.items.$ref === value || t.$ref === value);
|
|
355
339
|
return {
|
|
356
340
|
name: value,
|
|
357
341
|
kebabCasedTypeName: (0, lodash_1.kebabCase)(value),
|
|
358
|
-
isEnum: (
|
|
359
|
-
areAllArrays: props.every(
|
|
360
|
-
hasArrays: props.some(
|
|
342
|
+
isEnum: (refSchema?.enum ?? []).length > 0,
|
|
343
|
+
areAllArrays: props.every((val) => val.type === 'array'),
|
|
344
|
+
hasArrays: props.some((val) => val.type === 'array'),
|
|
361
345
|
isSelfReferencing: entityName === value,
|
|
362
346
|
};
|
|
363
347
|
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
348
|
+
}
|
|
349
|
+
getIsRequired(propertyName, schemaWrapperInfo) {
|
|
350
|
+
return (((schemaWrapperInfo.componentSchemaObject.required ?? []).includes(propertyName) ||
|
|
351
|
+
(schemaWrapperInfo.propertySchemaObject.nullable === undefined
|
|
352
|
+
? false
|
|
353
|
+
: !schemaWrapperInfo.propertySchemaObject.nullable)) &&
|
|
369
354
|
propertyName !== 'id');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
}());
|
|
355
|
+
}
|
|
356
|
+
}
|
|
373
357
|
exports.OpenApiDocConverter = OpenApiDocConverter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-generator",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.28.4",
|
|
4
4
|
"description": "Based on swagger-ts-generator, this is a type script model generator specifically for services with OpenApi spec documentation.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -49,37 +49,38 @@
|
|
|
49
49
|
],
|
|
50
50
|
"homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@
|
|
53
|
-
"@types/
|
|
54
|
-
"@types/
|
|
52
|
+
"@eslint/js": "^9.39.2",
|
|
53
|
+
"@types/jest": "^30.0.0",
|
|
54
|
+
"@types/lodash": "^4.17.23",
|
|
55
|
+
"@types/node": "^22.19.7",
|
|
55
56
|
"@types/pluralize": "^0.0.33",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
57
|
-
"@typescript-eslint/parser": "^
|
|
58
|
-
"eslint": "
|
|
59
|
-
"eslint-config-prettier": "^
|
|
60
|
-
"eslint-
|
|
61
|
-
"eslint-plugin-import": "^2.31.0",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
|
58
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
59
|
+
"eslint": "^9.39.2",
|
|
60
|
+
"eslint-config-prettier": "^10.1.8",
|
|
61
|
+
"eslint-plugin-import": "^2.32.0",
|
|
62
62
|
"eslint-plugin-node": "^11.1.0",
|
|
63
|
-
"eslint-plugin-promise": "^
|
|
64
|
-
"jest": "^
|
|
63
|
+
"eslint-plugin-promise": "^7.2.1",
|
|
64
|
+
"jest": "^30.2.0",
|
|
65
65
|
"jest-junit": "^16.0.0",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
66
|
+
"jest-util": "^30.2.0",
|
|
67
|
+
"openapi3-ts": "^4.5.0",
|
|
68
|
+
"prettier": "^3.8.1",
|
|
68
69
|
"rxjs": "^7.6.0",
|
|
69
|
-
"ts-jest": "^29.
|
|
70
|
-
"typescript": "^
|
|
70
|
+
"ts-jest": "^29.4.6",
|
|
71
|
+
"typescript": "^5.9.3",
|
|
72
|
+
"typescript-eslint": "^8.54.0"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
|
-
"axios": ">=1.
|
|
75
|
+
"axios": ">=1.13.x",
|
|
74
76
|
"handlebars": ">=4.x",
|
|
75
|
-
"lodash": "
|
|
76
|
-
"pluralize": "
|
|
77
|
+
"lodash": "^4.17.23",
|
|
78
|
+
"pluralize": ">=8.x"
|
|
77
79
|
},
|
|
78
80
|
"peerDependencies": {
|
|
79
|
-
"axios": ">=1.x",
|
|
81
|
+
"axios": ">=1.13.x",
|
|
80
82
|
"handlebars": ">=4.x",
|
|
81
|
-
"
|
|
82
|
-
"rxjs": "*"
|
|
83
|
-
"pluralize": "^8.0.0"
|
|
83
|
+
"pluralize": ">=8.x",
|
|
84
|
+
"rxjs": "*"
|
|
84
85
|
}
|
|
85
86
|
}
|