openapi-ts-generator 5.221.7 → 5.223.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.
@@ -24,6 +24,8 @@ export interface IImportType {
24
24
  kebabCasedTypeName: string;
25
25
  name: string;
26
26
  isEnum: boolean;
27
+ areAllArrays: boolean;
28
+ isSelfReferencing: boolean;
27
29
  }
28
30
  export interface IValueProperty {
29
31
  name: string;
@@ -46,7 +48,6 @@ export interface IReferenceProperty {
46
48
  snakeCaseName: string;
47
49
  referenceTypeName: string;
48
50
  typeScriptType: string;
49
- kebabCasedTypeScriptType: string;
50
51
  hasValidators: boolean;
51
52
  isArray: boolean;
52
53
  required: boolean;
@@ -14,7 +14,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.OpenApiDocConverter = void 0;
15
15
  var generator_options_1 = require("./models/generator-options");
16
16
  var schema_info_1 = require("./models/schema-info");
17
- var _ = require("lodash");
18
17
  var pluralize_1 = require("pluralize");
19
18
  var lodash_1 = require("lodash");
20
19
  var OpenApiDocConverter = /** @class */ (function () {
@@ -37,7 +36,7 @@ var OpenApiDocConverter = /** @class */ (function () {
37
36
  tagLookup = tagLookup || path.delete || path.patch;
38
37
  var tag = ((tagLookup === null || tagLookup === void 0 ? void 0 : tagLookup.tags) || ['unknown_endpoint'])[0];
39
38
  paths.push({
40
- tag: _.snakeCase(tag),
39
+ tag: (0, lodash_1.snakeCase)(tag),
41
40
  endpoint: this.options.pathUrlFormattingCallBack ? this.options.pathUrlFormattingCallBack(key) : key,
42
41
  });
43
42
  }
@@ -81,7 +80,7 @@ var OpenApiDocConverter = /** @class */ (function () {
81
80
  var _a, _b;
82
81
  var key = (_a = _this.startNumberregex.exec(x)) === null || _a === void 0 ? void 0 : _a.at(0);
83
82
  var name = ((_b = _this.endAlphaNumRegex.exec(x)) === null || _b === void 0 ? void 0 : _b.at(0)) || '';
84
- return { key: key ? +key : 0, name: name, titleName: _.startCase(name) };
83
+ return { key: key ? +key : 0, name: name, titleName: (0, lodash_1.startCase)(name) };
85
84
  }));
86
85
  };
87
86
  OpenApiDocConverter.prototype.buildSchemaWrapperInfo = function (schemaWrapperInfo) {
@@ -120,7 +119,7 @@ var OpenApiDocConverter = /** @class */ (function () {
120
119
  name: propertyName,
121
120
  initialValue: initialValue,
122
121
  isArray: false,
123
- snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
122
+ snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
124
123
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
125
124
  maxLength: schemaWrapperInfo.propertySchemaObject.maxLength,
126
125
  minLength: schemaWrapperInfo.propertySchemaObject.minLength,
@@ -146,23 +145,28 @@ var OpenApiDocConverter = /** @class */ (function () {
146
145
  initialValue: initialValue,
147
146
  name: propertyName,
148
147
  isArray: true,
149
- snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
148
+ snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
150
149
  hasMultipleValidators: false,
151
150
  hasValidators: validatorCount > 0,
152
151
  };
153
152
  };
154
153
  OpenApiDocConverter.prototype.getInitialValue = function (propertyName, schemaWrapperInfo) {
155
- var _a;
154
+ var _a, _b;
156
155
  var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
157
156
  var isRequired = this.getIsRequired(propertyName, schemaWrapperInfo);
158
- var refObject = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[schemaWrapperInfo.propertyReferenceObject['$ref']];
157
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
158
+ var refName = (((_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) || {})[propertyName].$ref;
159
+ var refObject = (((_b = this.apiDocument.components) === null || _b === void 0 ? void 0 : _b.schemas) || {})[refName];
159
160
  var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
160
- if (defaultValue) {
161
- return "'".concat(defaultValue.split(' ').pop(), "'");
162
- }
163
- else if (!isRequired) {
161
+ if (!isRequired) {
164
162
  return 'null';
165
163
  }
164
+ else if (defaultValue && refObject.enum) {
165
+ return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
166
+ }
167
+ else if (defaultValue) {
168
+ return "'".concat(defaultValue.split(' ').pop(), "'");
169
+ }
166
170
  else if (typescriptType === 'Date') {
167
171
  return 'new Date()';
168
172
  }
@@ -190,10 +194,9 @@ var OpenApiDocConverter = /** @class */ (function () {
190
194
  required: required,
191
195
  name: propertyName,
192
196
  initialValue: initialValue,
193
- snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
197
+ snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
194
198
  referenceTypeName: typeName,
195
199
  typeScriptType: typeName,
196
- kebabCasedTypeScriptType: (0, lodash_1.kebabCase)(typeName),
197
200
  isArray: false,
198
201
  isEnum: (propertySchema.enum || []).length > 0,
199
202
  hasValidators: validatorCount > 0,
@@ -237,17 +240,23 @@ var OpenApiDocConverter = /** @class */ (function () {
237
240
  };
238
241
  OpenApiDocConverter.prototype.getImportTypes = function (entityName, schemaWrapperInfo) {
239
242
  var _this = this;
243
+ var _a;
244
+ var schemaProperties = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || { properties: {} })[entityName].properties || {};
245
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
246
+ 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 })); });
240
247
  return schemaWrapperInfo.referenceProperties
241
248
  .map(function (t) { return t.referenceTypeName; })
242
- .filter(function (t) { return t !== entityName; })
243
249
  .filter(function (value, index, array) { return array.indexOf(value) === index; })
244
250
  .map(function (value) {
245
251
  var _a;
246
- var propertySchema = (((_a = _this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[value];
252
+ var refSchema = (((_a = _this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[value];
253
+ var props = properties.filter(function (t) { return t.items.$ref === value || t.$ref === value; });
247
254
  return {
248
255
  name: value,
249
- kebabCasedTypeName: _.kebabCase(value),
250
- isEnum: (propertySchema.enum || []).length > 0,
256
+ kebabCasedTypeName: (0, lodash_1.kebabCase)(value),
257
+ isEnum: (refSchema.enum || []).length > 0,
258
+ areAllArrays: props.every(function (val) { return val.type === 'array'; }),
259
+ isSelfReferencing: entityName === value,
251
260
  };
252
261
  });
253
262
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.221.7",
3
+ "version": "5.223.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",
@@ -6,9 +6,9 @@
6
6
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
7
7
  * Do not edit.
8
8
  */
9
- import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR{{#referenceProperties}}{{#unless isArray}}{{#if isEnum}}
10
- import { {{typeScriptType}} } from './{{kebabCasedTypeScriptType}}.enum';{{else}}
11
- import { I{{typeScriptType}} } from './{{kebabCasedTypeScriptType}}.model';{{/if}}{{/unless}}{{/referenceProperties}}
9
+ import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR{{#if importTypes}}{{#importTypes}}{{#unless areAllArrays}}{{#if isEnum}}
10
+ import { {{name}} } from './{{kebabCasedTypeName}}.enum';{{else}}
11
+ import { I{{name}} } from './{{kebabCasedTypeName}}.model';{{/if}}{{/unless}}{{/importTypes}}{{/if}}
12
12
 
13
13
  export function {{name}}FormGroupFac(): FormGroup {
14
14
  return new FormGroup({
@@ -5,9 +5,9 @@
5
5
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
6
  * Do not edit.
7
7
  */
8
- {{#if importTypes}}{{#importTypes}}{{#if isEnum}}
8
+ {{#if importTypes}}{{#importTypes}}{{#unless isSelfReferencing}}{{#if isEnum}}
9
9
  import { {{name}} } from './{{kebabCasedTypeName}}.enum';{{else}}
10
- import { I{{name}} } from './{{kebabCasedTypeName}}.model';{{/if}}{{/importTypes}}
10
+ import { I{{name}} } from './{{kebabCasedTypeName}}.model';{{/if}}{{/unless}}{{/importTypes}}
11
11
 
12
12
  {{/if}}{{#if description}}/**
13
13
  * {{description}}