openapi-ts-generator 5.223.4 → 5.223.11

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) {
@@ -39,6 +39,8 @@ export interface IValueProperty {
39
39
  minLength?: number;
40
40
  maximum?: number;
41
41
  minimum?: number;
42
+ maxItems?: number;
43
+ minItems?: number;
42
44
  description?: string;
43
45
  pattern?: string;
44
46
  initialValue: string;
@@ -49,6 +51,13 @@ export interface IReferenceProperty {
49
51
  referenceTypeName: string;
50
52
  typeScriptType: string;
51
53
  hasValidators: boolean;
54
+ hasMultipleValidators: boolean;
55
+ maxItems?: number;
56
+ minItems?: number;
57
+ maxLength?: number;
58
+ minLength?: number;
59
+ maximum?: number;
60
+ minimum?: number;
52
61
  isArray: boolean;
53
62
  required: boolean;
54
63
  isEnum?: boolean;
@@ -125,6 +125,8 @@ var OpenApiDocConverter = /** @class */ (function () {
125
125
  minLength: schemaWrapperInfo.propertySchemaObject.minLength,
126
126
  maximum: schemaWrapperInfo.propertySchemaObject.maximum,
127
127
  minimum: schemaWrapperInfo.propertySchemaObject.minimum,
128
+ minItems: schemaWrapperInfo.propertySchemaObject.minItems,
129
+ maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
128
130
  description: schemaWrapperInfo.propertySchemaObject.description,
129
131
  pattern: schemaWrapperInfo.propertySchemaObject.pattern,
130
132
  hasMultipleValidators: validatorCount > 1,
@@ -184,8 +186,9 @@ var OpenApiDocConverter = /** @class */ (function () {
184
186
  return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
185
187
  };
186
188
  OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
187
- var _a;
189
+ var _a, _b;
188
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];
189
192
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
190
193
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
191
194
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
@@ -200,6 +203,13 @@ var OpenApiDocConverter = /** @class */ (function () {
200
203
  isArray: false,
201
204
  isEnum: (propertySchema.enum || []).length > 0,
202
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,
203
213
  };
204
214
  };
205
215
  OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
@@ -209,6 +219,8 @@ var OpenApiDocConverter = /** @class */ (function () {
209
219
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
210
220
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
211
221
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
222
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxItems) +
223
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minItems) +
212
224
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
213
225
  };
214
226
  OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.223.4",
3
+ "version": "5.223.11",
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",
@@ -10,35 +10,52 @@ import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms';
10
10
  import { {{name}} } from './{{kebabCasedTypeName}}.enum';{{else}}
11
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}}: FormArray;
17
+ {{else}}
18
+ {{name}}: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
19
+ {{/if}}
20
+ {{/valueProperties}}
21
+ {{#referenceProperties}}
22
+ {{#if isArray}}
23
+ {{name}}: FormArray;
24
+ {{else}}
25
+ {{name}}: 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}}