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.
@@ -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,15 @@ 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
+ 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
- OpenApiDocConverter.prototype.buildSchemaWrapperInfoForEnum = function (schemaWrapperInfo) {
81
- var _a;
82
- var _this = this;
71
+ }
72
+ buildSchemaWrapperInfoForEnum(schemaWrapperInfo) {
83
73
  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 : '';
88
- return {
89
- key: key ? +key : 0,
90
- name: name,
91
- titleName: (0, lodash_1.startCase)(name),
92
- snakeCaseName: (0, lodash_1.snakeCase)(name).toUpperCase(),
93
- };
94
- }));
95
- };
96
- OpenApiDocConverter.prototype.buildSchemaWrapperInfo = function (parentTypeName, schemaWrapperInfo) {
97
- for (var propertyName in schemaWrapperInfo.componentSchemaObject.properties) {
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
- OpenApiDocConverter.prototype.convertArray = function (parentTypeName, propertyName, schemaWrapperInfo) {
114
- var arraySchemaObject = schemaWrapperInfo.propertySchemaObject.items;
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
- 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
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
- var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
130
+ const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
131
131
  return {
132
- required: required,
132
+ required,
133
133
  name: propertyName,
134
- initialValue: initialValue,
135
- initialTestValue: 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: ((_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',
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
- OpenApiDocConverter.prototype.convertValidator = function (validationValue) {
154
- var exists = validationValue !== null && validationValue !== undefined;
152
+ }
153
+ convertValidator(validationValue) {
154
+ const exists = validationValue !== null && validationValue !== undefined;
155
155
  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
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
- var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
163
+ const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
164
164
  return {
165
- required: required,
165
+ required,
166
166
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
167
- initialValue: initialValue,
168
- initialTestValue: 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
- 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]);
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 "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
188
+ return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
191
189
  }
192
190
  else if (defaultValue) {
193
- return "'".concat(defaultValue.split(' ').pop(), "'");
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
- 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]);
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 "[".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop(), "]");
217
+ return `[${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}]`;
222
218
  }
223
219
  else if (defaultValue && refObject.enum) {
224
- return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
220
+ return `${schemaWrapperInfo.propertyReferenceObject['$ref']}.${defaultValue.split(' ').pop()}`;
225
221
  }
226
222
  else if (refObject) {
227
- return schemaObject.type === 'array' ? "[]" : "undefined";
223
+ return schemaObject.type === 'array' ? `[]` : `undefined`;
228
224
  }
229
225
  else if (defaultValue) {
230
- return "'".concat(defaultValue.split(' ').pop(), "'");
226
+ return `'${defaultValue.split(' ').pop()}'`;
231
227
  }
232
228
  else if (email) {
233
- return "'".concat((0, lodash_1.kebabCase)(parentTypeName), "@email.org'");
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 ? "[".concat(minValue, "]") : '[0]';
238
+ return minValue ? `[${minValue}]` : '[0]';
243
239
  }
244
240
  else if (schemaObject.type === 'array') {
245
- return defaultValue ? "[".concat(defaultValue, "]") : '[]';
241
+ return defaultValue ? `[${defaultValue}]` : '[]';
246
242
  }
247
243
  else if (typescriptType === 'number') {
248
- return minValue ? "".concat(minValue) : '0';
244
+ return minValue ? `${minValue}` : '0';
249
245
  }
250
246
  else {
251
- var retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
247
+ let retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
252
248
  while (minLength && retValue.length < minLength) {
253
- retValue = "".concat(retValue, "_").concat(retValue);
249
+ retValue = `${retValue}_${retValue}`;
254
250
  }
255
- return "'".concat(maxLength ? retValue.substring(0, maxLength) : retValue, "'");
251
+ return `'${maxLength ? retValue.substring(0, maxLength) : retValue}'`;
256
252
  }
257
- };
258
- OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
259
- var refProperty = __assign(__assign({}, this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo)), { isArray: true });
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
- 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
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
- var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
273
- var typeName = this.parseRef(schemaWrapperInfo);
270
+ const initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
271
+ const typeName = this.parseRef(schemaWrapperInfo);
274
272
  return {
275
- required: required,
273
+ required,
276
274
  name: propertyName,
277
275
  isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
278
- initialValue: initialValue,
279
- initialTestValue: 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: ((_c = propertySchema === null || propertySchema === void 0 ? void 0 : propertySchema.enum) !== null && _c !== void 0 ? _c : []).length > 0,
282
+ isEnum: (propertySchema?.enum ?? []).length > 0,
285
283
  isEnumAndArray: false,
286
284
  hasValidators: validatorCount > 0,
287
285
  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,
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
- 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;
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
- OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
313
- var _a;
308
+ }
309
+ getPropertyTypeScriptType(schemaWrapperInfo) {
314
310
  if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
315
- var type = schemaWrapperInfo.propertySchemaObject.items.type;
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 (_a = schemaWrapperInfo.propertySchemaObject.type) !== null && _a !== void 0 ? _a : 'string';
328
- };
329
- OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
330
- var regexResult;
331
- var result = null;
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
- 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 })); });
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(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; });
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: ((_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'; }),
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
- 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)) &&
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
- return OpenApiDocConverter;
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.24.2",
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
- "@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
  }