openapi-ts-generator 4.88.4 → 4.114.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,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 });
@@ -13,6 +13,7 @@ export declare class OpenApiDocConverter {
13
13
  buildSchemaWrapperInfo(schemaWrapperInfo: SchemaWrapperInfo): void;
14
14
  convertArray(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): void;
15
15
  convertSchemaObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
16
+ private convertValidator;
16
17
  convertArrayObjectToValuePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
17
18
  convertArrayObjectToReferencePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
18
19
  convertReferenceObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
@@ -102,14 +102,18 @@ var OpenApiDocConverter = /** @class */ (function () {
102
102
  description: schemaWrapperInfo.propertySchemaObject.description,
103
103
  pattern: schemaWrapperInfo.propertySchemaObject.pattern,
104
104
  hasMultipleValidators: +required +
105
- +!!schemaWrapperInfo.propertySchemaObject.maxLength +
106
- +!!schemaWrapperInfo.propertySchemaObject.minLength +
107
- +!!schemaWrapperInfo.propertySchemaObject.maximum +
108
- +!!schemaWrapperInfo.propertySchemaObject.minimum +
109
- +!!schemaWrapperInfo.propertySchemaObject.pattern >
105
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
106
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
107
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
108
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
109
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern) >
110
110
  1,
111
111
  };
112
112
  };
113
+ OpenApiDocConverter.prototype.convertValidator = function (validationValue) {
114
+ var exists = validationValue !== null && validationValue !== undefined;
115
+ return +exists;
116
+ };
113
117
  OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
114
118
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
115
119
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "4.88.4",
3
+ "version": "4.114.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",
@@ -37,23 +37,23 @@
37
37
  "homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
38
38
  "devDependencies": {
39
39
  "@types/jest": "^27.4.1",
40
- "@types/lodash": "^4.14.180",
41
- "@types/node": "^16.11.26",
42
- "@typescript-eslint/eslint-plugin": "^5.16.0",
43
- "@typescript-eslint/parser": "^5.16.0",
44
- "eslint": "^8.11.0",
40
+ "@types/lodash": "^4.14.182",
41
+ "@types/node": "^16.11.27",
42
+ "@typescript-eslint/eslint-plugin": "^5.20.0",
43
+ "@typescript-eslint/parser": "^5.20.0",
44
+ "eslint": "^8.14.0",
45
45
  "eslint-config-prettier": "^8.5.0",
46
- "eslint-config-standard": "^16.0.2",
47
- "eslint-plugin-import": "^2.25.4",
46
+ "eslint-config-standard": "^16.0.3",
47
+ "eslint-plugin-import": "^2.26.0",
48
48
  "eslint-plugin-node": "^11.1.0",
49
49
  "eslint-plugin-promise": "^6.0.0",
50
50
  "jest": "^27.5.1",
51
- "jest-junit": "^13.0.0",
51
+ "jest-junit": "^13.2.0",
52
52
  "openapi3-ts": "^2.0.2",
53
- "prettier": "^2.6.0",
53
+ "prettier": "^2.6.2",
54
54
  "rxjs": "^7.5.5",
55
55
  "ts-jest": "^27.1.3",
56
- "typescript": "^4.6.2"
56
+ "typescript": "^4.6.3"
57
57
  },
58
58
  "dependencies": {
59
59
  "axios": ">=0.x",
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  /**
2
3
  * This file is generated by the openapi-ts-generator
3
4
  * #endpoints-ts.hbs
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  /**
2
3
  * This file is generated by the openapi-ts-generator
3
4
  * #form-group-factory.ts.hbs
@@ -12,30 +13,30 @@ export function {{name}}FormGroupFac(): FormGroup {
12
13
  {{#valueProperties}}
13
14
  {{#if isArray}}
14
15
  {{#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}}])),
16
+ {{name}}: new FormControl([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
16
17
  {{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}}),
18
+ {{name}}: new FormControl([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
18
19
  {{/if}}
19
20
  {{else}}
20
21
  {{#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}}])),
22
+ {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
22
23
  {{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}}),
24
+ {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
24
25
  {{/if}}
25
26
  {{/if}}
26
27
  {{/valueProperties}}
27
28
  {{#referenceProperties}}
28
29
  {{#if isArray}}
29
30
  {{#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}}]),
31
+ {{name}}: new FormArray([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
31
32
  {{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}}),
33
+ {{name}}: new FormArray([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
33
34
  {{/if}}
34
35
  {{else}}
35
36
  {{#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}}]),
37
+ {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
37
38
  {{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}}),
39
+ {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
39
40
  {{/if}}
40
41
  {{/if}}
41
42
  {{/referenceProperties}}
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  /**
2
3
  * This file is generated by the openapi-ts-generator
3
4
  * #generate-barrel-ts.hbs
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  /**
2
3
  * This file is generated by the openapi-ts-generator
3
4
  * #model-properties.ts.hbs
@@ -1,3 +1,4 @@
1
+ /* istanbul ignore file */
1
2
  /**
2
3
  * This file is generated by the openapi-ts-generator
3
4
  * #model.ts.hbs