openapi-ts-generator 4.192.8 → 5.220.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.
@@ -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;
@@ -38,12 +39,16 @@ export interface IValueProperty {
38
39
  minimum?: number;
39
40
  description?: string;
40
41
  pattern?: string;
42
+ initialValue: string;
41
43
  }
42
44
  export interface IReferenceProperty {
43
45
  name: string;
44
46
  snakeCaseName: string;
45
47
  referenceTypeName: string;
48
+ typeScriptType: string;
49
+ hasValidators: boolean;
46
50
  isArray: boolean;
47
51
  required: boolean;
48
52
  isEnum?: boolean;
53
+ initialValue: string;
49
54
  }
@@ -17,8 +17,10 @@ export declare class OpenApiDocConverter {
17
17
  convertSchemaObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
18
18
  private convertValidator;
19
19
  convertArrayObjectToValuePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
20
+ getInitialValue(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): string;
20
21
  convertArrayObjectToReferencePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
21
22
  convertReferenceObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
23
+ getValidatorCount(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): number;
22
24
  getPropertyTypeScriptType(schemaWrapperInfo: SchemaWrapperInfo): string;
23
25
  parseRef(schemaWrapperInfo: SchemaWrapperInfo): string;
24
26
  getImportTypes(entityName: string, schemaWrapperInfo: SchemaWrapperInfo): IImportType[];
@@ -113,9 +113,12 @@ 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);
117
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
116
118
  return {
117
119
  required: required,
118
120
  name: propertyName,
121
+ initialValue: initialValue,
119
122
  isArray: false,
120
123
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
121
124
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
@@ -125,13 +128,8 @@ var OpenApiDocConverter = /** @class */ (function () {
125
128
  minimum: schemaWrapperInfo.propertySchemaObject.minimum,
126
129
  description: schemaWrapperInfo.propertySchemaObject.description,
127
130
  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,
131
+ hasMultipleValidators: validatorCount > 1,
132
+ hasValidators: validatorCount > 0,
135
133
  };
136
134
  };
137
135
  OpenApiDocConverter.prototype.convertValidator = function (validationValue) {
@@ -140,30 +138,71 @@ var OpenApiDocConverter = /** @class */ (function () {
140
138
  };
141
139
  OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
142
140
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
141
+ var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
142
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
143
143
  return {
144
144
  required: required,
145
+ typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
146
+ initialValue: initialValue,
145
147
  name: propertyName,
146
148
  isArray: true,
147
149
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
148
- typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
149
150
  hasMultipleValidators: false,
151
+ hasValidators: validatorCount > 0,
150
152
  };
151
153
  };
154
+ OpenApiDocConverter.prototype.getInitialValue = function (propertyName, schemaWrapperInfo) {
155
+ var _a, _b;
156
+ var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
157
+ var isRequired = this.getIsRequired(propertyName, schemaWrapperInfo);
158
+ var defaultValue = (schemaWrapperInfo.componentSchemaObject.default ||
159
+ ((_b = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[schemaWrapperInfo.propertyReferenceObject['$ref']]) === null || _b === void 0 ? void 0 : _b.default));
160
+ if (defaultValue) {
161
+ return "'".concat(defaultValue.split(' ').pop(), "'");
162
+ }
163
+ else if (!isRequired) {
164
+ return 'null';
165
+ }
166
+ else if (typescriptType === 'Date') {
167
+ return 'new Date()';
168
+ }
169
+ else if (typescriptType === 'boolean') {
170
+ return 'false';
171
+ }
172
+ else {
173
+ return "''";
174
+ }
175
+ };
152
176
  OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (propertyName, schemaWrapperInfo) {
153
177
  return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
154
178
  };
155
179
  OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
156
180
  var _a;
157
181
  var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
182
+ var required = this.getIsRequired(propertyName, schemaWrapperInfo);
183
+ var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
184
+ var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
158
185
  return {
186
+ required: required,
159
187
  name: propertyName,
188
+ initialValue: initialValue,
160
189
  snakeCaseName: _.snakeCase(propertyName).toUpperCase(),
161
190
  referenceTypeName: this.parseRef(schemaWrapperInfo),
191
+ typeScriptType: this.parseRef(schemaWrapperInfo),
162
192
  isArray: false,
163
- required: (schemaWrapperInfo.componentSchemaObject.required || []).indexOf(propertyName) > -1,
164
193
  isEnum: (propertySchema.enum || []).length > 0,
194
+ hasValidators: validatorCount > 0,
165
195
  };
166
196
  };
197
+ OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
198
+ var required = this.getIsRequired(propertyName, schemaWrapperInfo);
199
+ return (+required +
200
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
201
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
202
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
203
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
204
+ +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
205
+ };
167
206
  OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
168
207
  if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
169
208
  return schemaWrapperInfo.propertySchemaObject.items.type;
@@ -177,10 +216,7 @@ var OpenApiDocConverter = /** @class */ (function () {
177
216
  else if (schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
178
217
  return 'Date';
179
218
  }
180
- if (!schemaWrapperInfo.propertySchemaObject.type) {
181
- throw new Error('Invalid Property Type');
182
- }
183
- return schemaWrapperInfo.propertySchemaObject.type;
219
+ return schemaWrapperInfo.propertySchemaObject.type || 'string';
184
220
  };
185
221
  OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
186
222
  var regexResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "4.192.8",
3
+ "version": "5.220.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",
@@ -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",
@@ -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,38 +6,39 @@
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
- import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR
9
+ import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR{{#if importTypes}}{{#importTypes}}{{#if isEnum}}
10
+ import { {{name}} } from './{{kebabCasedTypeName}}.enum'; //NOSONAR{{else}}
11
+ import { I{{name}} } from './{{kebabCasedTypeName}}.model'; //NOSONAR{{/if}}{{/importTypes}}{{/if}}
10
12
 
11
13
  export function {{name}}FormGroupFac(): FormGroup {
12
14
  return new FormGroup({
13
15
  {{#valueProperties}}
14
16
  {{#if isArray}}
15
17
  {{#if hasMultipleValidators}}
16
- {{name}}: new FormControl([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
18
+ {{name}}: new FormControl([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]) })),
17
19
  {{else}}
18
- {{name}}: new FormControl([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
20
+ {{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
21
  {{/if}}
20
22
  {{else}}
21
23
  {{#if hasMultipleValidators}}
22
- {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}])),
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}} }),
23
25
  {{else}}
24
- {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}),
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}}),
25
27
  {{/if}}
26
28
  {{/if}}
27
29
  {{/valueProperties}}
28
30
  {{#referenceProperties}}
29
31
  {{#if isArray}}
30
32
  {{#if hasMultipleValidators}}
31
- {{name}}: new FormArray([], Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
33
+ {{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
34
  {{else}}
33
- {{name}}: new FormArray([]{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
35
+ {{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
36
  {{/if}}
35
37
  {{else}}
36
38
  {{#if hasMultipleValidators}}
37
- {{name}}: new FormControl('', Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}])),
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}} }),
38
40
  {{else}}
39
- {{name}}: new FormControl(''{{#if required}}, Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}),
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}}),
40
42
  {{/if}}
41
43
  {{/if}}
42
44
  {{/referenceProperties}}