openapi-ts-generator 4.83.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.
package/README.md CHANGED
@@ -73,3 +73,5 @@ generateTsModels({
73
73
  valuePropertyTypeFilterCallBack: (val, i, arr) => !val.name.startsWith('created') && !val.name.startsWith('updated'),
74
74
  });
75
75
  ```
76
+
77
+ Check out [openapi-mermaid](https://www.npmjs.com/package/openapi-mermaid), it will auto-generate mermaid entity diagrams using your swagger docs.
@@ -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;
package/index.js CHANGED
@@ -67,16 +67,15 @@ function generateTsModels(options) {
67
67
  exports.generateTsModels = generateTsModels;
68
68
  function getOpenApiDocumentAsync(options) {
69
69
  return __awaiter(this, void 0, void 0, function () {
70
- var apiDoc, axios, response, response;
70
+ var apiDoc, response, response;
71
71
  return __generator(this, function (_a) {
72
72
  switch (_a.label) {
73
73
  case 0:
74
74
  if (!options.openApiJsonUrl) return [3 /*break*/, 2];
75
- axios = new axios_1.Axios();
76
- return [4 /*yield*/, axios.get(options.openApiJsonUrl)];
75
+ return [4 /*yield*/, axios_1.default.get(options.openApiJsonUrl)];
77
76
  case 1:
78
77
  response = _a.sent();
79
- apiDoc = JSON.parse(response.data);
78
+ apiDoc = response.data;
80
79
  return [3 /*break*/, 3];
81
80
  case 2:
82
81
  if (options.openApiJsonFileName) {
@@ -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 });
@@ -7,6 +7,7 @@ export declare class SchemaWrapperInfo {
7
7
  readonly componentSchemaObject: SchemaObject;
8
8
  readonly valueProperties: IValueProperty[];
9
9
  referenceProperties: IReferenceProperty[];
10
+ readonly description?: string;
10
11
  constructor(schemaItem: SchemaObject);
11
12
  updateReferenceProperties(options: IGeneratorOptions): void;
12
13
  }
@@ -7,6 +7,7 @@ var SchemaWrapperInfo = /** @class */ (function () {
7
7
  this.propertySchemaObject = {};
8
8
  this.propertyReferenceObject = { $ref: '' };
9
9
  this.componentSchemaObject = schemaItem;
10
+ this.description = schemaItem.description;
10
11
  this.valueProperties = [];
11
12
  this.referenceProperties = [];
12
13
  }
@@ -8,6 +8,7 @@ export interface IPath {
8
8
  }
9
9
  export interface IEntity {
10
10
  name: string;
11
+ description?: string;
11
12
  importTypes: IImportType[];
12
13
  valueProperties: IValueProperty[];
13
14
  referenceProperties: IReferenceProperty[];
@@ -25,6 +26,10 @@ export interface IValueProperty {
25
26
  required: boolean;
26
27
  maxLength?: number;
27
28
  minLength?: number;
29
+ maximum?: number;
30
+ minimum?: number;
31
+ description?: string;
32
+ pattern?: string;
28
33
  }
29
34
  export interface IReferenceProperty {
30
35
  name: string;
@@ -50,6 +50,7 @@ var OpenApiDocConverter = /** @class */ (function () {
50
50
  schemaWrapperInfo.updateReferenceProperties(this.options);
51
51
  var entity = {
52
52
  name: schemaName,
53
+ description: schemaWrapperInfo.description,
53
54
  referenceProperties: schemaWrapperInfo.referenceProperties,
54
55
  valueProperties: schemaWrapperInfo.valueProperties.filter(this.options.valuePropertyTypeFilterCallBack || generator_options_1.defaultFilter),
55
56
  importTypes: this.getImportTypes(schemaName, schemaWrapperInfo),
@@ -96,7 +97,17 @@ var OpenApiDocConverter = /** @class */ (function () {
96
97
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
97
98
  maxLength: schemaWrapperInfo.propertySchemaObject.maxLength,
98
99
  minLength: schemaWrapperInfo.propertySchemaObject.minLength,
99
- hasMultipleValidators: +required + +!!schemaWrapperInfo.propertySchemaObject.maxLength + +!!schemaWrapperInfo.propertySchemaObject.minLength > 1,
100
+ maximum: schemaWrapperInfo.propertySchemaObject.maximum,
101
+ minimum: schemaWrapperInfo.propertySchemaObject.minimum,
102
+ description: schemaWrapperInfo.propertySchemaObject.description,
103
+ pattern: schemaWrapperInfo.propertySchemaObject.pattern,
104
+ hasMultipleValidators: +required +
105
+ +!!schemaWrapperInfo.propertySchemaObject.maxLength +
106
+ +!!schemaWrapperInfo.propertySchemaObject.minLength +
107
+ +!!schemaWrapperInfo.propertySchemaObject.maximum +
108
+ +!!schemaWrapperInfo.propertySchemaObject.minimum +
109
+ +!!schemaWrapperInfo.propertySchemaObject.pattern >
110
+ 1,
100
111
  };
101
112
  };
102
113
  OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "4.83.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 maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/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 maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/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 maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/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 maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/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 maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/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 maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/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 maxLength}}Validators.maxLength({{maxLength}}), {{/if}}{{#if minLength}}Validators.minLength({{minLength}}), {{/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 maxLength}}, Validators.maxLength({{maxLength}}){{/if}}{{#if minLength}}, Validators.minLength({{minLength}}){{/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}}
@@ -5,9 +5,15 @@
5
5
  * Do not edit.
6
6
  */
7
7
  /* tslint:disable */
8
- export enum {{name}}Properties {
8
+ {{#if description}}/**
9
+ * {{description}}
10
+ */
11
+ {{/if}}export enum {{name}}Properties {
9
12
  {{#valueProperties}}
10
- {{snakeCaseName}} = '{{name}}',
13
+ {{#if description}}/**
14
+ * {{description}}
15
+ */
16
+ {{/if}} {{snakeCaseName}} = '{{name}}',
11
17
  {{/valueProperties}}
12
18
  {{#referenceProperties}}
13
19
  {{snakeCaseName}} = '{{name}}',
@@ -10,9 +10,14 @@
10
10
  import { I{{name}} } from './{{kebabCasedTypeName}}.model';
11
11
  {{/importTypes}}
12
12
 
13
+ {{/if}}{{#if description}}/**
14
+ * {{description}}
15
+ */
16
+ {{/if}}export interface I{{{name}}} {
17
+ {{#valueProperties}}{{#if description}}/**
18
+ * {{description}}
19
+ */
13
20
  {{/if}}
14
- export interface I{{{name}}} {
15
- {{#valueProperties}}
16
21
  {{name}}?: {{typeScriptType}}{{#if isArray}}[]{{/if}};
17
22
  {{/valueProperties}}
18
23
  {{#referenceProperties}}