openapi-ts-generator 4.192.6 → 5.220.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.
@@ -57,7 +57,7 @@ var FormGroupGenerator = /** @class */ (function (_super) {
57
57
  if (value !== undefined && value !== null) {
58
58
  var hasMultipleValidators = prop.hasMultipleValidators;
59
59
  value = typeof value === 'string' ? "'".concat(value, "'") : value;
60
- return "".concat(!hasMultipleValidators ? ', ' : '', "Validators.").concat(angularValidatorFunctionName, "(").concat(value, ")").concat(hasMultipleValidators ? ', ' : '');
60
+ return "Validators.".concat(angularValidatorFunctionName, "(").concat(value, ")").concat(hasMultipleValidators ? ', ' : '');
61
61
  }
62
62
  return '';
63
63
  };
@@ -28,8 +28,9 @@ export interface IImportType {
28
28
  export interface IValueProperty {
29
29
  name: string;
30
30
  snakeCaseName: string;
31
- typeScriptType?: string;
31
+ typeScriptType: string;
32
32
  isArray: boolean;
33
+ hasValidators: boolean;
33
34
  hasMultipleValidators: boolean;
34
35
  required: boolean;
35
36
  maxLength?: number;
@@ -43,6 +44,8 @@ export interface IReferenceProperty {
43
44
  name: string;
44
45
  snakeCaseName: string;
45
46
  referenceTypeName: string;
47
+ typeScriptType: string;
48
+ hasValidators: boolean;
46
49
  isArray: boolean;
47
50
  required: boolean;
48
51
  isEnum?: boolean;
@@ -19,6 +19,7 @@ export declare class OpenApiDocConverter {
19
19
  convertArrayObjectToValuePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
20
20
  convertArrayObjectToReferencePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
21
21
  convertReferenceObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
22
+ getValidatorCount(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): number;
22
23
  getPropertyTypeScriptType(schemaWrapperInfo: SchemaWrapperInfo): string;
23
24
  parseRef(schemaWrapperInfo: SchemaWrapperInfo): string;
24
25
  getImportTypes(entityName: string, schemaWrapperInfo: SchemaWrapperInfo): IImportType[];
@@ -113,6 +113,7 @@ var OpenApiDocConverter = /** @class */ (function () {
113
113
  };
114
114
  OpenApiDocConverter.prototype.convertSchemaObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
115
115
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
116
+ var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
116
117
  return {
117
118
  required: required,
118
119
  name: propertyName,
@@ -125,13 +126,8 @@ var OpenApiDocConverter = /** @class */ (function () {
125
126
  minimum: schemaWrapperInfo.propertySchemaObject.minimum,
126
127
  description: schemaWrapperInfo.propertySchemaObject.description,
127
128
  pattern: schemaWrapperInfo.propertySchemaObject.pattern,
128
- hasMultipleValidators: +required +
129
- +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
130
- +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
131
- +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
132
- +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
133
- +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern) >
134
- 1,
129
+ hasMultipleValidators: validatorCount > 1,
130
+ hasValidators: validatorCount > 0,
135
131
  };
136
132
  };
137
133
  OpenApiDocConverter.prototype.convertValidator = function (validationValue) {
@@ -140,6 +136,7 @@ var OpenApiDocConverter = /** @class */ (function () {
140
136
  };
141
137
  OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
142
138
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
139
+ var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
143
140
  return {
144
141
  required: required,
145
142
  name: propertyName,
@@ -147,6 +144,7 @@ var OpenApiDocConverter = /** @class */ (function () {
147
144
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
148
145
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
149
146
  hasMultipleValidators: false,
147
+ hasValidators: validatorCount > 0,
150
148
  };
151
149
  };
152
150
  OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (propertyName, schemaWrapperInfo) {
@@ -155,15 +153,28 @@ var OpenApiDocConverter = /** @class */ (function () {
155
153
  OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
156
154
  var _a;
157
155
  var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
156
+ var required = this.getIsRequired(propertyName, schemaWrapperInfo);
157
+ var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
158
158
  return {
159
+ required: required,
159
160
  name: propertyName,
160
161
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
161
162
  referenceTypeName: this.parseRef(schemaWrapperInfo),
163
+ typeScriptType: this.parseRef(schemaWrapperInfo),
162
164
  isArray: false,
163
- required: (schemaWrapperInfo.componentSchemaObject.required || []).indexOf(propertyName) > -1,
164
165
  isEnum: (propertySchema.enum || []).length > 0,
166
+ hasValidators: validatorCount > 0,
165
167
  };
166
168
  };
169
+ OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
170
+ var required = this.getIsRequired(propertyName, schemaWrapperInfo);
171
+ return (+required +
172
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
173
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
174
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
175
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
176
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
177
+ };
167
178
  OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
168
179
  if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
169
180
  return schemaWrapperInfo.propertySchemaObject.items.type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "4.192.6",
3
+ "version": "5.220.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",
@@ -40,9 +40,9 @@
40
40
  "@types/lodash": "^4.14.182",
41
41
  "@types/node": "^16.11.27",
42
42
  "@types/pluralize": "^0.0.29",
43
- "@typescript-eslint/eslint-plugin": "^5.30.5",
44
- "@typescript-eslint/parser": "^5.30.5",
45
- "eslint": "^8.19.0",
43
+ "@typescript-eslint/eslint-plugin": "^5.32.0",
44
+ "@typescript-eslint/parser": "^5.32.0",
45
+ "eslint": "^8.21.0",
46
46
  "eslint-config-prettier": "^8.5.0",
47
47
  "eslint-config-standard": "^17.0.0",
48
48
  "eslint-plugin-import": "^2.26.0",
@@ -17,6 +17,6 @@
17
17
 
18
18
  export const {{{camelSingularName}}}Values = [
19
19
  {{#enumValues}}
20
- { key: {{key}}, name: '{{titleName}}'},
20
+ { key: {{key}}, name: '{{name}}', displayText: '{{titleName}}'},
21
21
  {{/enumValues}}
22
22
  ];
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1
2
  /* istanbul ignore file */
2
3
  /**
3
4
  * This file is generated by the openapi-ts-generator
@@ -5,7 +6,6 @@
5
6
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
7
  * Do not edit.
7
8
  */
8
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
9
  import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR
10
10
 
11
11
  export function {{name}}FormGroupFac(): FormGroup {
@@ -13,30 +13,30 @@ export function {{name}}FormGroupFac(): FormGroup {
13
13
  {{#valueProperties}}
14
14
  {{#if isArray}}
15
15
  {{#if hasMultipleValidators}}
16
- {{name}}: new FormControl([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
16
+ {{name}}: new FormControl([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]) })),
17
17
  {{else}}
18
- {{name}}: new FormControl([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
18
+ {{name}}: new FormControl([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} }{{/if}}),
19
19
  {{/if}}
20
20
  {{else}}
21
21
  {{#if hasMultipleValidators}}
22
- {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
22
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{#if required}}''{{else}}null{{/if}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
23
23
  {{else}}
24
- {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
24
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{#if required}}''{{else}}null{{/if}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
25
25
  {{/if}}
26
26
  {{/if}}
27
27
  {{/valueProperties}}
28
28
  {{#referenceProperties}}
29
29
  {{#if isArray}}
30
30
  {{#if hasMultipleValidators}}
31
- {{name}}: new FormArray([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
31
+ {{name}}: new FormArray([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
32
32
  {{else}}
33
- {{name}}: new FormArray([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
33
+ {{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
34
34
  {{/if}}
35
35
  {{else}}
36
36
  {{#if hasMultipleValidators}}
37
- {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
37
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{#if required}}''{{else}}null{{/if}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
38
38
  {{else}}
39
- {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
39
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{#if required}}''{{else}}null{{/if}}{{#if hasValidators}} { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
40
40
  {{/if}}
41
41
  {{/if}}
42
42
  {{/referenceProperties}}