openapi-ts-generator 9.24.2 → 9.31.2
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/entity.d.ts +1 -0
- package/models/enum-value.d.ts +1 -1
- 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 +2 -1
- package/models/schema-info.js +8 -9
- package/openapidoc-converter.d.ts +1 -1
- package/openapidoc-converter.js +183 -186
- package/package.json +24 -23
- package/templates/enum.ts.hbs +16 -0
- package/templates/test-object-factory.ts.hbs +1 -1
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,15 @@ 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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
isCharEnum: schemaWrapperInfo.isCharEnum || false,
|
|
52
|
+
enumValues: schemaWrapperInfo.enumValues.map((t) => typeof t === 'string' || t instanceof String
|
|
53
|
+
? t
|
|
54
|
+
: {
|
|
55
|
+
...t,
|
|
56
|
+
key: schemaWrapperInfo.isCharEnum ? t.key : +t.key,
|
|
57
|
+
}),
|
|
66
58
|
name: schemaName,
|
|
67
59
|
kebabCasedName: (0, lodash_1.kebabCase)(schemaName),
|
|
68
60
|
singularName: (0, pluralize_1.singular)(schemaName),
|
|
@@ -76,25 +68,34 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
76
68
|
}
|
|
77
69
|
}
|
|
78
70
|
return entities.filter(this.options.typeFilterCallBack || generator_options_1.defaultFilter);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
var _a;
|
|
82
|
-
var _this = this;
|
|
71
|
+
}
|
|
72
|
+
buildSchemaWrapperInfoForEnum(schemaWrapperInfo) {
|
|
83
73
|
schemaWrapperInfo.isEnum = true;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
let enumValues = [...(schemaWrapperInfo.componentSchemaObject.enum || []).map((x) => {
|
|
75
|
+
const key = this.startNumberregex.exec(x)?.at(0);
|
|
76
|
+
const name = this.endAlphaNumRegex.exec(x)?.at(0) ?? '';
|
|
77
|
+
return {
|
|
78
|
+
key: key ? +key : 0,
|
|
79
|
+
name,
|
|
80
|
+
titleName: (0, lodash_1.startCase)(name),
|
|
81
|
+
snakeCaseName: (0, lodash_1.snakeCase)(name).toUpperCase(),
|
|
82
|
+
};
|
|
83
|
+
})];
|
|
84
|
+
schemaWrapperInfo.isCharEnum = enumValues.length > 0 &&
|
|
85
|
+
enumValues
|
|
86
|
+
.filter((enumVal) => typeof enumVal !== 'string' && typeof enumVal.key === 'number')
|
|
87
|
+
.map((enumVal) => enumVal.key)
|
|
88
|
+
.every((val) => val >= 65 && val <= 90); // A-Z ASCII range
|
|
89
|
+
if (schemaWrapperInfo.isCharEnum) {
|
|
90
|
+
enumValues = enumValues.map(enumvalue => ({
|
|
91
|
+
...enumvalue,
|
|
92
|
+
key: String.fromCharCode(enumvalue.key)
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
schemaWrapperInfo.enumValues.push(...enumValues);
|
|
96
|
+
}
|
|
97
|
+
buildSchemaWrapperInfo(parentTypeName, schemaWrapperInfo) {
|
|
98
|
+
for (const propertyName in schemaWrapperInfo.componentSchemaObject.properties) {
|
|
98
99
|
if ((schemaWrapperInfo.propertySchemaObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName]).type && // NOSONAR
|
|
99
100
|
schemaWrapperInfo.propertySchemaObject.type !== 'array') {
|
|
100
101
|
schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo));
|
|
@@ -109,9 +110,9 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
}
|
|
114
|
+
convertArray(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
115
|
+
const arraySchemaObject = schemaWrapperInfo.propertySchemaObject.items;
|
|
115
116
|
if (arraySchemaObject.type) {
|
|
116
117
|
schemaWrapperInfo.valueProperties.push(this.convertArrayObjectToValuePropertyType(parentTypeName, propertyName, schemaWrapperInfo));
|
|
117
118
|
}
|
|
@@ -119,20 +120,19 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
119
120
|
schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.propertySchemaObject.items;
|
|
120
121
|
schemaWrapperInfo.referenceProperties.push(this.convertArrayObjectToReferencePropertyType(parentTypeName, propertyName, schemaWrapperInfo));
|
|
121
122
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
var initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
123
|
+
}
|
|
124
|
+
convertSchemaObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
125
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
126
|
+
const validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
127
|
+
const initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
128
128
|
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
129
129
|
: 'undefined';
|
|
130
|
-
|
|
130
|
+
const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
131
131
|
return {
|
|
132
|
-
required
|
|
132
|
+
required,
|
|
133
133
|
name: propertyName,
|
|
134
|
-
initialValue
|
|
135
|
-
initialTestValue
|
|
134
|
+
initialValue,
|
|
135
|
+
initialTestValue,
|
|
136
136
|
isArray: false,
|
|
137
137
|
snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
|
|
138
138
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
@@ -140,8 +140,8 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
140
140
|
minLength: schemaWrapperInfo.propertySchemaObject.minLength,
|
|
141
141
|
maximum: schemaWrapperInfo.propertySchemaObject.maximum,
|
|
142
142
|
minimum: schemaWrapperInfo.propertySchemaObject.minimum,
|
|
143
|
-
email:
|
|
144
|
-
uri:
|
|
143
|
+
email: schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'email',
|
|
144
|
+
uri: schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'uri',
|
|
145
145
|
minItems: schemaWrapperInfo.propertySchemaObject.minItems,
|
|
146
146
|
maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
|
|
147
147
|
description: schemaWrapperInfo.propertySchemaObject.description,
|
|
@@ -149,23 +149,23 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
149
149
|
hasMultipleValidators: validatorCount > 1,
|
|
150
150
|
hasValidators: validatorCount > 0,
|
|
151
151
|
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
}
|
|
153
|
+
convertValidator(validationValue) {
|
|
154
|
+
const exists = validationValue !== null && validationValue !== undefined;
|
|
155
155
|
return +exists;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
}
|
|
157
|
+
convertArrayObjectToValuePropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
158
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
159
|
+
const validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
160
|
+
const initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
161
161
|
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
162
162
|
: 'undefined';
|
|
163
|
-
|
|
163
|
+
const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
164
164
|
return {
|
|
165
|
-
required
|
|
165
|
+
required,
|
|
166
166
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
167
|
-
initialValue
|
|
168
|
-
initialTestValue
|
|
167
|
+
initialValue,
|
|
168
|
+
initialTestValue,
|
|
169
169
|
name: propertyName,
|
|
170
170
|
email: false,
|
|
171
171
|
uri: false,
|
|
@@ -174,23 +174,21 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
174
174
|
hasMultipleValidators: false,
|
|
175
175
|
hasValidators: validatorCount > 0,
|
|
176
176
|
};
|
|
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]);
|
|
177
|
+
}
|
|
178
|
+
getInitialValue(propertyName, schemaWrapperInfo) {
|
|
179
|
+
const typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
|
|
180
|
+
const isRequired = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
181
|
+
const refName = (schemaWrapperInfo?.componentSchemaObject?.properties?.[propertyName]).$ref;
|
|
182
|
+
const refObject = this.apiDocument.components?.schemas?.[refName];
|
|
183
|
+
const defaultValue = (schemaWrapperInfo.componentSchemaObject.default || refObject?.default || (refObject?.enum || [])[0]);
|
|
186
184
|
if (!isRequired) {
|
|
187
185
|
return 'null';
|
|
188
186
|
}
|
|
189
187
|
else if (defaultValue && refObject.enum) {
|
|
190
|
-
return
|
|
188
|
+
return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
|
|
191
189
|
}
|
|
192
190
|
else if (defaultValue) {
|
|
193
|
-
return
|
|
191
|
+
return `'${defaultValue.split(' ').pop()}'`;
|
|
194
192
|
}
|
|
195
193
|
else if (typescriptType === 'Date') {
|
|
196
194
|
return 'new Date()';
|
|
@@ -202,35 +200,33 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
202
200
|
return '0';
|
|
203
201
|
}
|
|
204
202
|
else {
|
|
205
|
-
return
|
|
203
|
+
return `''`;
|
|
206
204
|
}
|
|
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]);
|
|
205
|
+
}
|
|
206
|
+
getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
207
|
+
const typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
|
|
208
|
+
const schemaObject = schemaWrapperInfo?.componentSchemaObject?.properties?.[propertyName];
|
|
209
|
+
const maxLength = schemaWrapperInfo.propertySchemaObject.maxLength;
|
|
210
|
+
const minLength = schemaWrapperInfo.propertySchemaObject.minLength;
|
|
211
|
+
const minValue = schemaWrapperInfo.propertySchemaObject.minimum;
|
|
212
|
+
const email = schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'email';
|
|
213
|
+
const refName = schemaObject?.$ref || schemaObject.items?.$ref;
|
|
214
|
+
const refObject = this.apiDocument.components?.schemas?.[refName];
|
|
215
|
+
const defaultValue = (schemaWrapperInfo.componentSchemaObject.default || refObject?.default || (refObject?.enum || [])[0]);
|
|
220
216
|
if (defaultValue && refObject.enum && schemaObject.type === 'array') {
|
|
221
|
-
return
|
|
217
|
+
return `[${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}]`;
|
|
222
218
|
}
|
|
223
219
|
else if (defaultValue && refObject.enum) {
|
|
224
|
-
return
|
|
220
|
+
return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
|
|
225
221
|
}
|
|
226
222
|
else if (refObject) {
|
|
227
|
-
return schemaObject.type === 'array' ?
|
|
223
|
+
return schemaObject.type === 'array' ? `[]` : `undefined`;
|
|
228
224
|
}
|
|
229
225
|
else if (defaultValue) {
|
|
230
|
-
return
|
|
226
|
+
return `'${defaultValue.split(' ').pop()}'`;
|
|
231
227
|
}
|
|
232
228
|
else if (email) {
|
|
233
|
-
return
|
|
229
|
+
return `'${(0, lodash_1.kebabCase)(parentTypeName)}@email.org'`;
|
|
234
230
|
}
|
|
235
231
|
else if (typescriptType === 'Date') {
|
|
236
232
|
return 'new Date()';
|
|
@@ -239,65 +235,66 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
239
235
|
return 'false';
|
|
240
236
|
}
|
|
241
237
|
else if (typescriptType === 'number' && schemaObject.type === 'array') {
|
|
242
|
-
return minValue ?
|
|
238
|
+
return minValue ? `[${minValue}]` : '[0]';
|
|
243
239
|
}
|
|
244
240
|
else if (schemaObject.type === 'array') {
|
|
245
|
-
return defaultValue ?
|
|
241
|
+
return defaultValue ? `[${defaultValue}]` : '[]';
|
|
246
242
|
}
|
|
247
243
|
else if (typescriptType === 'number') {
|
|
248
|
-
return minValue ?
|
|
244
|
+
return minValue ? `${minValue}` : '0';
|
|
249
245
|
}
|
|
250
246
|
else {
|
|
251
|
-
|
|
247
|
+
let retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
|
|
252
248
|
while (minLength && retValue.length < minLength) {
|
|
253
|
-
retValue =
|
|
249
|
+
retValue = `${retValue}_${retValue}`;
|
|
254
250
|
}
|
|
255
|
-
return
|
|
251
|
+
return `'${maxLength ? retValue.substring(0, maxLength) : retValue}'`;
|
|
256
252
|
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
253
|
+
}
|
|
254
|
+
convertArrayObjectToReferencePropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
255
|
+
const refProperty = {
|
|
256
|
+
...this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo),
|
|
257
|
+
isArray: true,
|
|
258
|
+
};
|
|
260
259
|
refProperty.isEnumAndArray = refProperty.isEnum && refProperty.isArray;
|
|
261
260
|
return refProperty;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
var initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
261
|
+
}
|
|
262
|
+
convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo) {
|
|
263
|
+
const propertySchema = this.apiDocument.components?.schemas?.[this.parseRef(schemaWrapperInfo)];
|
|
264
|
+
const refSchema = schemaWrapperInfo?.componentSchemaObject?.properties?.[propertyName];
|
|
265
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
266
|
+
const validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
267
|
+
const initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
270
268
|
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
271
269
|
: 'undefined';
|
|
272
|
-
|
|
273
|
-
|
|
270
|
+
const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
271
|
+
const typeName = this.parseRef(schemaWrapperInfo);
|
|
274
272
|
return {
|
|
275
|
-
required
|
|
273
|
+
required,
|
|
276
274
|
name: propertyName,
|
|
277
275
|
isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
|
|
278
|
-
initialValue
|
|
279
|
-
initialTestValue
|
|
276
|
+
initialValue,
|
|
277
|
+
initialTestValue,
|
|
280
278
|
snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
|
|
281
279
|
referenceTypeName: typeName,
|
|
282
280
|
typeScriptType: typeName,
|
|
283
281
|
isArray: false,
|
|
284
|
-
isEnum: (
|
|
282
|
+
isEnum: (propertySchema?.enum ?? []).length > 0,
|
|
285
283
|
isEnumAndArray: false,
|
|
286
284
|
hasValidators: validatorCount > 0,
|
|
287
285
|
hasMultipleValidators: validatorCount > 1,
|
|
288
|
-
maxLength: refSchema
|
|
289
|
-
minLength: refSchema
|
|
290
|
-
maximum: refSchema
|
|
291
|
-
minimum: refSchema
|
|
292
|
-
minItems: refSchema
|
|
293
|
-
maxItems: refSchema
|
|
286
|
+
maxLength: refSchema?.maxLength,
|
|
287
|
+
minLength: refSchema?.minLength,
|
|
288
|
+
maximum: refSchema?.maximum,
|
|
289
|
+
minimum: refSchema?.minimum,
|
|
290
|
+
minItems: refSchema?.minItems,
|
|
291
|
+
maxItems: refSchema?.maxItems,
|
|
294
292
|
};
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
var uri = ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'uri' || false;
|
|
293
|
+
}
|
|
294
|
+
getValidatorCount(propertyName, schemaWrapperInfo) {
|
|
295
|
+
const required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
296
|
+
const email = schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'email' || false;
|
|
297
|
+
const uri = schemaWrapperInfo.propertySchemaObject.format?.toLowerCase() === 'uri' || false;
|
|
301
298
|
return (+required +
|
|
302
299
|
+email +
|
|
303
300
|
+uri +
|
|
@@ -308,11 +305,10 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
308
305
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxItems) +
|
|
309
306
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.minItems) +
|
|
310
307
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
var _a;
|
|
308
|
+
}
|
|
309
|
+
getPropertyTypeScriptType(schemaWrapperInfo) {
|
|
314
310
|
if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
|
|
315
|
-
|
|
311
|
+
const type = schemaWrapperInfo.propertySchemaObject.items.type;
|
|
316
312
|
return type === 'integer' ? 'number' : type;
|
|
317
313
|
}
|
|
318
314
|
else if (schemaWrapperInfo.propertySchemaObject.type === 'integer' && schemaWrapperInfo.propertySchemaObject.enum) {
|
|
@@ -324,11 +320,11 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
324
320
|
else if (schemaWrapperInfo.propertySchemaObject.format === 'date' || schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
|
|
325
321
|
return 'Date';
|
|
326
322
|
}
|
|
327
|
-
return
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
323
|
+
return schemaWrapperInfo.propertySchemaObject.type ?? 'string';
|
|
324
|
+
}
|
|
325
|
+
parseRef(schemaWrapperInfo) {
|
|
326
|
+
let regexResult;
|
|
327
|
+
let result = null;
|
|
332
328
|
if (schemaWrapperInfo.propertyReferenceObject.$ref &&
|
|
333
329
|
// tslint:disable-next-line: no-conditional-assignment
|
|
334
330
|
(regexResult = this.endAlphaNumRegex.exec(schemaWrapperInfo.propertyReferenceObject.$ref)) // NOSONAR
|
|
@@ -337,37 +333,38 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
337
333
|
result = schemaWrapperInfo.propertyReferenceObject.$ref;
|
|
338
334
|
}
|
|
339
335
|
return result || 'unknown';
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
336
|
+
}
|
|
337
|
+
getImportTypes(entityName, schemaWrapperInfo) {
|
|
338
|
+
const schemaProperties = (this.apiDocument.components?.schemas ?? { [entityName]: { properties: {} } })[entityName].properties ?? {};
|
|
339
|
+
const properties = Object.keys(schemaProperties).map((key) => ({
|
|
340
|
+
key,
|
|
341
|
+
...schemaProperties[key],
|
|
342
|
+
$ref: schemaProperties[key].$ref,
|
|
343
|
+
items: schemaProperties[key].items || {},
|
|
344
|
+
type: schemaProperties[key].type,
|
|
345
|
+
}));
|
|
348
346
|
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; });
|
|
347
|
+
.map((t) => t.referenceTypeName)
|
|
348
|
+
.filter((value, index, array) => array.indexOf(value) === index)
|
|
349
|
+
.map((value) => {
|
|
350
|
+
const refSchema = this.apiDocument.components?.schemas?.[value];
|
|
351
|
+
const props = properties.filter((t) => t.items.$ref === value || t.$ref === value);
|
|
355
352
|
return {
|
|
356
353
|
name: value,
|
|
357
354
|
kebabCasedTypeName: (0, lodash_1.kebabCase)(value),
|
|
358
|
-
isEnum: (
|
|
359
|
-
areAllArrays: props.every(
|
|
360
|
-
hasArrays: props.some(
|
|
355
|
+
isEnum: (refSchema?.enum ?? []).length > 0,
|
|
356
|
+
areAllArrays: props.every((val) => val.type === 'array'),
|
|
357
|
+
hasArrays: props.some((val) => val.type === 'array'),
|
|
361
358
|
isSelfReferencing: entityName === value,
|
|
362
359
|
};
|
|
363
360
|
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
361
|
+
}
|
|
362
|
+
getIsRequired(propertyName, schemaWrapperInfo) {
|
|
363
|
+
return (((schemaWrapperInfo.componentSchemaObject.required ?? []).includes(propertyName) ||
|
|
364
|
+
(schemaWrapperInfo.propertySchemaObject.nullable === undefined
|
|
365
|
+
? false
|
|
366
|
+
: !schemaWrapperInfo.propertySchemaObject.nullable)) &&
|
|
369
367
|
propertyName !== 'id');
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
}());
|
|
368
|
+
}
|
|
369
|
+
}
|
|
373
370
|
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.31.2",
|
|
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
|
}
|