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.
@@ -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
- var generator_options_1 = require("./models/generator-options");
16
- var schema_info_1 = require("./models/schema-info");
17
- var pluralize_1 = require("pluralize");
18
- var lodash_1 = require("lodash");
19
- var OpenApiDocConverter = /** @class */ (function () {
20
- function OpenApiDocConverter(options, apiDocument) {
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
- OpenApiDocConverter.prototype.convertDocument = function () {
27
- var entities = this.convertEntities();
28
- var paths = this.convertPaths();
29
- return { entities: entities, paths: paths };
30
- };
31
- OpenApiDocConverter.prototype.convertPaths = function () {
32
- var paths = [];
33
- for (var key in this.apiDocument.paths) {
34
- var path = this.apiDocument.paths[key] || {};
35
- var tagLookup = path.get || path.post || path.put;
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
- var tag = ((tagLookup === null || tagLookup === void 0 ? void 0 : tagLookup.tags) || ['unknown_endpoint'])[0];
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
- OpenApiDocConverter.prototype.convertEntities = function () {
46
- var _a, _b, _c;
47
- var entities = [];
48
- for (var schemaName in (_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) {
49
- if ((_b = this.apiDocument.components) === null || _b === void 0 ? void 0 : _b.schemas[schemaName]) {
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
- var entity = {
49
+ const entity = {
59
50
  isEnum: schemaWrapperInfo.isEnum,
60
- enumValues: schemaWrapperInfo.enumValues.map(function (t) {
61
- var _a;
62
- return typeof t === 'string' || t instanceof String
63
- ? t
64
- : __assign(__assign({}, t), { key: (_a = t.key) !== null && _a !== void 0 ? _a : 0 });
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
- OpenApiDocConverter.prototype.buildSchemaWrapperInfoForEnum = function (schemaWrapperInfo) {
81
- var _a;
82
- var _this = this;
70
+ }
71
+ buildSchemaWrapperInfoForEnum(schemaWrapperInfo) {
83
72
  schemaWrapperInfo.isEnum = true;
84
- (_a = schemaWrapperInfo.enumValues).push.apply(_a, (schemaWrapperInfo.componentSchemaObject.enum || []).map(function (x) {
85
- var _a, _b, _c;
86
- var key = (_a = _this.startNumberregex.exec(x)) === null || _a === void 0 ? void 0 : _a.at(0);
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: 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
- OpenApiDocConverter.prototype.buildSchemaWrapperInfo = function (parentTypeName, schemaWrapperInfo) {
97
- for (var propertyName in schemaWrapperInfo.componentSchemaObject.properties) {
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
- OpenApiDocConverter.prototype.convertArray = function (parentTypeName, propertyName, schemaWrapperInfo) {
114
- var arraySchemaObject = schemaWrapperInfo.propertySchemaObject.items;
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
- OpenApiDocConverter.prototype.convertSchemaObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
124
- var _a, _b;
125
- var required = this.getIsRequired(propertyName, schemaWrapperInfo);
126
- var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
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
- var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
117
+ const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
131
118
  return {
132
- required: required,
119
+ required,
133
120
  name: propertyName,
134
- initialValue: initialValue,
135
- initialTestValue: 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: ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email',
144
- uri: ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === '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
- OpenApiDocConverter.prototype.convertValidator = function (validationValue) {
154
- var exists = validationValue !== null && validationValue !== undefined;
139
+ }
140
+ convertValidator(validationValue) {
141
+ const exists = validationValue !== null && validationValue !== undefined;
155
142
  return +exists;
156
- };
157
- OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
158
- var required = this.getIsRequired(propertyName, schemaWrapperInfo);
159
- var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
160
- var initialValue = this.options.genAngularFormGroupsWithDefaultValues
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
- var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
150
+ const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
164
151
  return {
165
- required: required,
152
+ required,
166
153
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
167
- initialValue: initialValue,
168
- initialTestValue: 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
- OpenApiDocConverter.prototype.getInitialValue = function (propertyName, schemaWrapperInfo) {
179
- var _a, _b;
180
- var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
181
- var isRequired = this.getIsRequired(propertyName, schemaWrapperInfo);
182
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
183
- var refName = (((_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) || {})[propertyName].$ref;
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 "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
175
+ return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
191
176
  }
192
177
  else if (defaultValue) {
193
- return "'".concat(defaultValue.split(' ').pop(), "'");
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
- OpenApiDocConverter.prototype.getInitialTestValue = function (parentTypeName, propertyName, schemaWrapperInfo) {
209
- var _a, _b, _c, _d, _e, _f;
210
- var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
211
- var schemaObject = ((_b = (_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {})[propertyName];
212
- var maxLength = schemaWrapperInfo.propertySchemaObject.maxLength;
213
- var minLength = schemaWrapperInfo.propertySchemaObject.minLength;
214
- var minValue = schemaWrapperInfo.propertySchemaObject.minimum;
215
- var email = ((_c = schemaWrapperInfo.propertySchemaObject.format) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'email';
216
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
217
- var refName = (schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.$ref) || ((_d = schemaObject.items) === null || _d === void 0 ? void 0 : _d.$ref);
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 "[".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop(), "]");
204
+ return `[${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}]`;
222
205
  }
223
206
  else if (defaultValue && refObject.enum) {
224
- return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
207
+ return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
225
208
  }
226
209
  else if (refObject) {
227
- return schemaObject.type === 'array' ? "[]" : "undefined";
210
+ return schemaObject.type === 'array' ? `[]` : `undefined`;
228
211
  }
229
212
  else if (defaultValue) {
230
- return "'".concat(defaultValue.split(' ').pop(), "'");
213
+ return `'${defaultValue.split(' ').pop()}'`;
231
214
  }
232
215
  else if (email) {
233
- return "'".concat((0, lodash_1.kebabCase)(parentTypeName), "@email.org'");
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 ? "[".concat(minValue, "]") : '[0]';
225
+ return minValue ? `[${minValue}]` : '[0]';
243
226
  }
244
227
  else if (schemaObject.type === 'array') {
245
- return defaultValue ? "[".concat(defaultValue, "]") : '[]';
228
+ return defaultValue ? `[${defaultValue}]` : '[]';
246
229
  }
247
230
  else if (typescriptType === 'number') {
248
- return minValue ? "".concat(minValue) : '0';
231
+ return minValue ? `${minValue}` : '0';
249
232
  }
250
233
  else {
251
- var retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
234
+ let retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
252
235
  while (minLength && retValue.length < minLength) {
253
- retValue = "".concat(retValue, "_").concat(retValue);
236
+ retValue = `${retValue}_${retValue}`;
254
237
  }
255
- return "'".concat(maxLength ? retValue.substring(0, maxLength) : retValue, "'");
238
+ return `'${maxLength ? retValue.substring(0, maxLength) : retValue}'`;
256
239
  }
257
- };
258
- OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
259
- var refProperty = __assign(__assign({}, this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo)), { isArray: true });
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
- OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
264
- var _a, _b, _c;
265
- var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
266
- var refSchema = (((_b = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _b === void 0 ? void 0 : _b.properties) || {})[propertyName];
267
- var required = this.getIsRequired(propertyName, schemaWrapperInfo);
268
- var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
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
- var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
273
- var typeName = this.parseRef(schemaWrapperInfo);
257
+ const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
258
+ const typeName = this.parseRef(schemaWrapperInfo);
274
259
  return {
275
- required: required,
260
+ required,
276
261
  name: propertyName,
277
262
  isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
278
- initialValue: initialValue,
279
- initialTestValue: 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: ((_c = propertySchema === null || propertySchema === void 0 ? void 0 : propertySchema.enum) !== null && _c !== void 0 ? _c : []).length > 0,
269
+ isEnum: (propertySchema?.enum ?? []).length > 0,
285
270
  isEnumAndArray: false,
286
271
  hasValidators: validatorCount > 0,
287
272
  hasMultipleValidators: validatorCount > 1,
288
- maxLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxLength,
289
- minLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minLength,
290
- maximum: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maximum,
291
- minimum: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minimum,
292
- minItems: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minItems,
293
- maxItems: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxItems,
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
- OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
297
- var _a, _b;
298
- var required = this.getIsRequired(propertyName, schemaWrapperInfo);
299
- var email = ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email' || false;
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
- OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
313
- var _a;
295
+ }
296
+ getPropertyTypeScriptType(schemaWrapperInfo) {
314
297
  if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
315
- var type = schemaWrapperInfo.propertySchemaObject.items.type;
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 (_a = schemaWrapperInfo.propertySchemaObject.type) !== null && _a !== void 0 ? _a : 'string';
328
- };
329
- OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
330
- var regexResult;
331
- var result = null;
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
- OpenApiDocConverter.prototype.getImportTypes = function (entityName, schemaWrapperInfo) {
342
- var _a;
343
- var _this = this;
344
- var _b, _c, _d;
345
- var schemaProperties = (_d = ((_c = (_b = this.apiDocument.components) === null || _b === void 0 ? void 0 : _b.schemas) !== null && _c !== void 0 ? _c : (_a = {}, _a[entityName] = { properties: {} }, _a))[entityName].properties) !== null && _d !== void 0 ? _d : {};
346
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
347
- var properties = Object.keys(schemaProperties).map(function (key) { return (__assign(__assign({ key: key }, schemaProperties[key]), { $ref: schemaProperties[key].$ref, items: schemaProperties[key].items || {}, type: schemaProperties[key].type })); });
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(function (t) { return t.referenceTypeName; })
350
- .filter(function (value, index, array) { return array.indexOf(value) === index; })
351
- .map(function (value) {
352
- var _a, _b;
353
- var refSchema = (((_a = _this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[value];
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: ((_b = refSchema === null || refSchema === void 0 ? void 0 : refSchema.enum) !== null && _b !== void 0 ? _b : []).length > 0,
359
- areAllArrays: props.every(function (val) { return val.type === 'array'; }),
360
- hasArrays: props.some(function (val) { return val.type === 'array'; }),
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
- OpenApiDocConverter.prototype.getIsRequired = function (propertyName, schemaWrapperInfo) {
366
- var _a;
367
- return ((((_a = schemaWrapperInfo.componentSchemaObject.required) !== null && _a !== void 0 ? _a : []).indexOf(propertyName) > -1 ||
368
- (schemaWrapperInfo.propertySchemaObject.nullable === undefined ? false : !schemaWrapperInfo.propertySchemaObject.nullable)) &&
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
- return OpenApiDocConverter;
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.24.2",
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
- "@types/jest": "^29.5.14",
53
- "@types/lodash": "^4.17.15",
54
- "@types/node": "^20.11.21",
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": "^7.1.0",
57
- "@typescript-eslint/parser": "^7.1.0",
58
- "eslint": "8.56",
59
- "eslint-config-prettier": "^9.1.0",
60
- "eslint-config-standard": "^17.1.0",
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": "^6.6.0",
64
- "jest": "^29.7.0",
63
+ "eslint-plugin-promise": "^7.2.1",
64
+ "jest": "^30.2.0",
65
65
  "jest-junit": "^16.0.0",
66
- "openapi3-ts": "^4.4.0",
67
- "prettier": "^3.5.2",
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.2.6",
70
- "typescript": "^4.9.5"
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.12.2",
75
+ "axios": ">=1.13.x",
74
76
  "handlebars": ">=4.x",
75
- "lodash": ">=4.17.23",
76
- "pluralize": "^8.0.0"
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
- "lodash": ">=4.x",
82
- "rxjs": "*",
83
- "pluralize": "^8.0.0"
83
+ "pluralize": ">=8.x",
84
+ "rxjs": "*"
84
85
  }
85
86
  }