openapi-ts-generator 5.223.2 → 5.223.9

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.
@@ -7,5 +7,6 @@ export declare class FormGroupGenerator extends BaseGenerator<IEntity> {
7
7
  constructor(options: IGeneratorOptions);
8
8
  generate(templateData: ITemplateData): void;
9
9
  registerHelpers(): void;
10
+ registerValidatorHelper(validatorName: string, angularValidatorName?: string): void;
10
11
  validatorFactory(propertyCollection: PropertyType, propertyContext: IHelperContext, validationName: string, angularValidatorFunctionName: string): string;
11
12
  }
@@ -37,17 +37,19 @@ var FormGroupGenerator = /** @class */ (function (_super) {
37
37
  });
38
38
  };
39
39
  FormGroupGenerator.prototype.registerHelpers = function () {
40
+ this.registerValidatorHelper('minimum', 'min');
41
+ this.registerValidatorHelper('maximum', 'max');
42
+ this.registerValidatorHelper('minLength');
43
+ this.registerValidatorHelper('maxLength');
44
+ this.registerValidatorHelper('maxItems', 'maxLength');
45
+ this.registerValidatorHelper('minItems', 'minLength');
46
+ this.registerValidatorHelper('pattern');
47
+ };
48
+ FormGroupGenerator.prototype.registerValidatorHelper = function (validatorName, angularValidatorName) {
40
49
  var _this = this;
41
- HandleBars.registerHelper('minimumValidator', function (x, y) { return _this.validatorFactory(x, y, 'minimum', 'min'); });
42
- HandleBars.registerHelper('maximumValidator', function (x, y) { return _this.validatorFactory(x, y, 'maximum', 'max'); });
43
- HandleBars.registerHelper('minLengthValidator', function (x, y) {
44
- return _this.validatorFactory(x, y, 'minLength', 'minLength');
45
- });
46
- HandleBars.registerHelper('maxLengthValidator', function (x, y) {
47
- return _this.validatorFactory(x, y, 'maxLength', 'maxLength');
48
- });
49
- HandleBars.registerHelper('patternValidator', function (x, y) {
50
- return _this.validatorFactory(x, y, 'pattern', 'pattern');
50
+ if (angularValidatorName === void 0) { angularValidatorName = validatorName; }
51
+ HandleBars.registerHelper("".concat(validatorName, "Validator"), function (x, y) {
52
+ return _this.validatorFactory(x, y, validatorName, angularValidatorName);
51
53
  });
52
54
  };
53
55
  FormGroupGenerator.prototype.validatorFactory = function (propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
@@ -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;
@@ -37,6 +39,8 @@ export interface IValueProperty {
37
39
  minLength?: number;
38
40
  maximum?: number;
39
41
  minimum?: number;
42
+ maxItems?: number;
43
+ minItems?: number;
40
44
  description?: string;
41
45
  pattern?: string;
42
46
  initialValue: string;
@@ -46,8 +50,14 @@ export interface IReferenceProperty {
46
50
  snakeCaseName: string;
47
51
  referenceTypeName: string;
48
52
  typeScriptType: string;
49
- kebabCasedTypeScriptType: string;
50
53
  hasValidators: boolean;
54
+ hasMultipleValidators: boolean;
55
+ maxItems?: number;
56
+ minItems?: number;
57
+ maxLength?: number;
58
+ minLength?: number;
59
+ maximum?: number;
60
+ minimum?: number;
51
61
  isArray: boolean;
52
62
  required: boolean;
53
63
  isEnum?: 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,12 +119,14 @@ 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,
127
126
  maximum: schemaWrapperInfo.propertySchemaObject.maximum,
128
127
  minimum: schemaWrapperInfo.propertySchemaObject.minimum,
128
+ minItems: schemaWrapperInfo.propertySchemaObject.minItems,
129
+ maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
129
130
  description: schemaWrapperInfo.propertySchemaObject.description,
130
131
  pattern: schemaWrapperInfo.propertySchemaObject.pattern,
131
132
  hasMultipleValidators: validatorCount > 1,
@@ -146,7 +147,7 @@ var OpenApiDocConverter = /** @class */ (function () {
146
147
  initialValue: initialValue,
147
148
  name: propertyName,
148
149
  isArray: true,
149
- snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
150
+ snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
150
151
  hasMultipleValidators: false,
151
152
  hasValidators: validatorCount > 0,
152
153
  };
@@ -185,8 +186,9 @@ var OpenApiDocConverter = /** @class */ (function () {
185
186
  return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
186
187
  };
187
188
  OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
188
- var _a;
189
+ var _a, _b;
189
190
  var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
191
+ var refSchema = (((_b = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _b === void 0 ? void 0 : _b.properties) || {})[propertyName];
190
192
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
191
193
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
192
194
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
@@ -195,13 +197,19 @@ var OpenApiDocConverter = /** @class */ (function () {
195
197
  required: required,
196
198
  name: propertyName,
197
199
  initialValue: initialValue,
198
- snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
200
+ snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
199
201
  referenceTypeName: typeName,
200
202
  typeScriptType: typeName,
201
- kebabCasedTypeScriptType: (0, lodash_1.kebabCase)(typeName),
202
203
  isArray: false,
203
204
  isEnum: (propertySchema.enum || []).length > 0,
204
205
  hasValidators: validatorCount > 0,
206
+ hasMultipleValidators: validatorCount > 1,
207
+ maxLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxLength,
208
+ minLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minLength,
209
+ maximum: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maximum,
210
+ minimum: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minimum,
211
+ minItems: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minItems,
212
+ maxItems: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxItems,
205
213
  };
206
214
  };
207
215
  OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
@@ -211,6 +219,8 @@ var OpenApiDocConverter = /** @class */ (function () {
211
219
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
212
220
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
213
221
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
222
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxItems) +
223
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minItems) +
214
224
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
215
225
  };
216
226
  OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
@@ -242,17 +252,23 @@ var OpenApiDocConverter = /** @class */ (function () {
242
252
  };
243
253
  OpenApiDocConverter.prototype.getImportTypes = function (entityName, schemaWrapperInfo) {
244
254
  var _this = this;
255
+ var _a;
256
+ var schemaProperties = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || { properties: {} })[entityName].properties || {};
257
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
258
+ 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 })); });
245
259
  return schemaWrapperInfo.referenceProperties
246
260
  .map(function (t) { return t.referenceTypeName; })
247
- .filter(function (t) { return t !== entityName; })
248
261
  .filter(function (value, index, array) { return array.indexOf(value) === index; })
249
262
  .map(function (value) {
250
263
  var _a;
251
- var propertySchema = (((_a = _this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[value];
264
+ var refSchema = (((_a = _this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[value];
265
+ var props = properties.filter(function (t) { return t.items.$ref === value || t.$ref === value; });
252
266
  return {
253
267
  name: value,
254
- kebabCasedTypeName: _.kebabCase(value),
255
- isEnum: (propertySchema.enum || []).length > 0,
268
+ kebabCasedTypeName: (0, lodash_1.kebabCase)(value),
269
+ isEnum: (refSchema.enum || []).length > 0,
270
+ areAllArrays: props.every(function (val) { return val.type === 'array'; }),
271
+ isSelfReferencing: entityName === value,
256
272
  };
257
273
  });
258
274
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.223.2",
3
+ "version": "5.223.9",
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,39 +6,56 @@
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
- export function {{name}}FormGroupFac(): FormGroup {
14
- return new FormGroup({
13
+ export interface I{{name}}Form {
14
+ {{#valueProperties}}
15
+ {{#if isArray}}
16
+ {{name}}: new FormArray;
17
+ {{else}}
18
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
19
+ {{/if}}
20
+ {{/valueProperties}}
21
+ {{#referenceProperties}}
22
+ {{#if isArray}}
23
+ {{name}}: new FormArray;
24
+ {{else}}
25
+ {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
26
+ {{/if}}
27
+ {{/referenceProperties}}
28
+ }
29
+
30
+ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
31
+ return new FormGroup<I{{name}}Form>({
15
32
  {{#valueProperties}}
16
33
  {{#if isArray}}
17
34
  {{#if hasMultipleValidators}}
18
- {{name}}: new FormControl([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]) })),
35
+ {{name}}: new FormArray([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]) })),
19
36
  {{else}}
20
- {{name}}: new FormControl([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}} }{{/if}}),
37
+ {{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}} }{{/if}}),
21
38
  {{/if}}
22
39
  {{else}}
23
40
  {{#if hasMultipleValidators}}
24
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
41
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
25
42
  {{else}}
26
- {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
43
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
27
44
  {{/if}}
28
45
  {{/if}}
29
46
  {{/valueProperties}}
30
47
  {{#referenceProperties}}
31
48
  {{#if isArray}}
32
49
  {{#if hasMultipleValidators}}
33
- {{name}}: new FormArray([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]) }),
50
+ {{name}}: new FormArray([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]) }),
34
51
  {{else}}
35
- {{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
52
+ {{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
36
53
  {{/if}}
37
54
  {{else}}
38
55
  {{#if hasMultipleValidators}}
39
- {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
56
+ {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
40
57
  {{else}}
41
- {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
58
+ {{name}}: new FormControl<{{#unless isEnum}}I{{/unless}}{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
42
59
  {{/if}}
43
60
  {{/if}}
44
61
  {{/referenceProperties}}
@@ -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}}