openapi-ts-generator 4.88.4 → 4.89.3

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,8 +1,11 @@
1
1
  import { IGeneratorOptions } from '../models/generator-options';
2
2
  import { IEntity, ITemplateData } from '../models/template-data';
3
3
  import { BaseGenerator } from './base-generator';
4
+ import { IHelperContext, PropertyType } from '../models/helper-context';
4
5
  export declare class FormGroupGenerator extends BaseGenerator<IEntity> {
5
6
  readonly GeneratorName = "FormGroupGenerator";
6
7
  constructor(options: IGeneratorOptions);
7
8
  generate(templateData: ITemplateData): void;
9
+ registerHelpers(): void;
10
+ validatorFactory(propertyCollection: PropertyType, propertyContext: IHelperContext, validationName: string, angularValidatorFunctionName: string): string;
8
11
  }
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.FormGroupGenerator = void 0;
19
19
  var _ = require("lodash");
20
20
  var base_generator_1 = require("./base-generator");
21
+ var HandleBars = require("handlebars");
21
22
  var FormGroupGenerator = /** @class */ (function (_super) {
22
23
  __extends(FormGroupGenerator, _super);
23
24
  function FormGroupGenerator(options) {
@@ -30,10 +31,36 @@ var FormGroupGenerator = /** @class */ (function (_super) {
30
31
  FormGroupGenerator.prototype.generate = function (templateData) {
31
32
  var _this = this;
32
33
  var _a;
34
+ this.registerHelpers();
33
35
  (_a = templateData.entities) === null || _a === void 0 ? void 0 : _a.filter(function (val) { var _a, _b; return ((_a = val.valueProperties) === null || _a === void 0 ? void 0 : _a.length) + ((_b = val.referenceProperties) === null || _b === void 0 ? void 0 : _b.length) > 0; }).forEach(function (entity) {
34
36
  _super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".form-group-fac.ts"), entity);
35
37
  });
36
38
  };
39
+ FormGroupGenerator.prototype.registerHelpers = function () {
40
+ 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');
51
+ });
52
+ };
53
+ FormGroupGenerator.prototype.validatorFactory = function (propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
54
+ var props = propertyContext.data.root[propertyCollection];
55
+ var prop = props[propertyContext.data.index];
56
+ var value = prop[validationName];
57
+ if (value !== undefined && value !== null) {
58
+ var hasMultipleValidators = prop.hasMultipleValidators;
59
+ value = typeof value === 'string' ? "'".concat(value, "'") : value;
60
+ return "".concat(!hasMultipleValidators ? ', ' : '', "Validators.").concat(angularValidatorFunctionName, "(").concat(value, ")").concat(hasMultipleValidators ? ', ' : '');
61
+ }
62
+ return '';
63
+ };
37
64
  return FormGroupGenerator;
38
65
  }(base_generator_1.BaseGenerator));
39
66
  exports.FormGroupGenerator = FormGroupGenerator;
@@ -0,0 +1,11 @@
1
+ import { IEntity } from './template-data';
2
+ export interface IHelperContext {
3
+ data: {
4
+ root: IEntity;
5
+ key: number;
6
+ index: number;
7
+ first: boolean;
8
+ };
9
+ name: string;
10
+ }
11
+ export declare type PropertyType = 'valueProperties' | 'referenceProperties';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "4.88.4",
3
+ "version": "4.89.3",
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",
@@ -12,30 +12,30 @@ export function {{name}}FormGroupFac(): FormGroup {
12
12
  {{#valueProperties}}
13
13
  {{#if isArray}}
14
14
  {{#if hasMultipleValidators}}
15
- {{name}}: new FormControl([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/if}}{{#if maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}])),
15
+ {{name}}: new FormControl([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
16
16
  {{else}}
17
- {{name}}: new FormControl([]{{#if required}}, Validators.required{{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/if}}{{#if maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}),
17
+ {{name}}: new FormControl([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
18
18
  {{/if}}
19
19
  {{else}}
20
20
  {{#if hasMultipleValidators}}
21
- {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/if}}{{#if maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}])),
21
+ {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
22
22
  {{else}}
23
- {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/if}}{{#if maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}),
23
+ {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
24
24
  {{/if}}
25
25
  {{/if}}
26
26
  {{/valueProperties}}
27
27
  {{#referenceProperties}}
28
28
  {{#if isArray}}
29
29
  {{#if hasMultipleValidators}}
30
- {{name}}: new FormArray([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/if}}{{#if maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}]),
30
+ {{name}}: new FormArray([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
31
31
  {{else}}
32
- {{name}}: new FormArray([]{{#if required}}, Validators.required{{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/if}}{{#if maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}),
32
+ {{name}}: new FormArray([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
33
33
  {{/if}}
34
34
  {{else}}
35
35
  {{#if hasMultipleValidators}}
36
- {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/if}}{{#if maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}]),
36
+ {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
37
37
  {{else}}
38
- {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/if}}{{#if maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minimum}}Validators.min({{minimum}}), {{/if}}{{#if maximum}}Validators.max({{maximum}}), {{/if}}{{#if pattern}}Validators.pattern('{{pattern}}'), {{/if}}),
38
+ {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
39
39
  {{/if}}
40
40
  {{/if}}
41
41
  {{/referenceProperties}}