openapi-ts-generator 5.225.11 → 5.230.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.
@@ -43,6 +43,7 @@ export interface IValueProperty {
43
43
  minimum?: number;
44
44
  maxItems?: number;
45
45
  minItems?: number;
46
+ email: boolean;
46
47
  description?: string;
47
48
  pattern?: string;
48
49
  initialValue: string;
@@ -54,6 +55,7 @@ export interface IReferenceProperty {
54
55
  referenceTypeName: string;
55
56
  typeScriptType: string;
56
57
  hasValidators: boolean;
58
+ isSameAsParentTypescriptType: boolean;
57
59
  hasMultipleValidators: boolean;
58
60
  maxItems?: number;
59
61
  minItems?: number;
@@ -12,15 +12,15 @@ export declare class OpenApiDocConverter {
12
12
  convertPaths(): IPath[];
13
13
  convertEntities(): IEntity[];
14
14
  buildSchemaWrapperInfoForEnum(schemaWrapperInfo: SchemaWrapperInfo): void;
15
- buildSchemaWrapperInfo(schemaWrapperInfo: SchemaWrapperInfo): void;
16
- convertArray(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): void;
17
- convertSchemaObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
15
+ buildSchemaWrapperInfo(parentTypeName: string, schemaWrapperInfo: SchemaWrapperInfo): void;
16
+ convertArray(parentTypeName: string, propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): void;
17
+ convertSchemaObjectToPropertyType(parentTypeName: string, propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
18
18
  private convertValidator;
19
- convertArrayObjectToValuePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
19
+ convertArrayObjectToValuePropertyType(parentTypeName: string, propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IValueProperty;
20
20
  getInitialValue(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): string;
21
- getInitialTestValue(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): string;
22
- convertArrayObjectToReferencePropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
23
- convertReferenceObjectToPropertyType(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
21
+ getInitialTestValue(parentTypeName: string, propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): string;
22
+ convertArrayObjectToReferencePropertyType(parentTypeName: string, propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
23
+ convertReferenceObjectToPropertyType(parentTypeName: string, propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): IReferenceProperty;
24
24
  getValidatorCount(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): number;
25
25
  getPropertyTypeScriptType(schemaWrapperInfo: SchemaWrapperInfo): string;
26
26
  parseRef(schemaWrapperInfo: SchemaWrapperInfo): string;
@@ -52,7 +52,7 @@ var OpenApiDocConverter = /** @class */ (function () {
52
52
  this.buildSchemaWrapperInfoForEnum(schemaWrapperInfo);
53
53
  }
54
54
  else {
55
- this.buildSchemaWrapperInfo(schemaWrapperInfo);
55
+ this.buildSchemaWrapperInfo(schemaName, schemaWrapperInfo);
56
56
  }
57
57
  schemaWrapperInfo.updateReferenceProperties(this.options);
58
58
  var entity = {
@@ -84,38 +84,39 @@ var OpenApiDocConverter = /** @class */ (function () {
84
84
  return { key: key ? +key : 0, name: name, titleName: (0, lodash_1.startCase)(name) };
85
85
  }));
86
86
  };
87
- OpenApiDocConverter.prototype.buildSchemaWrapperInfo = function (schemaWrapperInfo) {
87
+ OpenApiDocConverter.prototype.buildSchemaWrapperInfo = function (parentTypeName, schemaWrapperInfo) {
88
88
  for (var propertyName in schemaWrapperInfo.componentSchemaObject.properties) {
89
89
  if ((schemaWrapperInfo.propertySchemaObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName]).type && // NOSONAR
90
90
  schemaWrapperInfo.propertySchemaObject.type !== 'array') {
91
- schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(propertyName, schemaWrapperInfo));
91
+ schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo));
92
92
  }
93
93
  else {
94
94
  schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName];
95
95
  if (schemaWrapperInfo.propertyReferenceObject.$ref) {
96
- schemaWrapperInfo.referenceProperties.push(this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo));
96
+ schemaWrapperInfo.referenceProperties.push(this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo));
97
97
  }
98
98
  else if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
99
- this.convertArray(propertyName, schemaWrapperInfo);
99
+ this.convertArray(parentTypeName, propertyName, schemaWrapperInfo);
100
100
  }
101
101
  }
102
102
  }
103
103
  };
104
- OpenApiDocConverter.prototype.convertArray = function (propertyName, schemaWrapperInfo) {
104
+ OpenApiDocConverter.prototype.convertArray = function (parentTypeName, propertyName, schemaWrapperInfo) {
105
105
  var arraySchemaObject = schemaWrapperInfo.propertySchemaObject.items;
106
106
  if (arraySchemaObject.type) {
107
- schemaWrapperInfo.valueProperties.push(this.convertArrayObjectToValuePropertyType(propertyName, schemaWrapperInfo));
107
+ schemaWrapperInfo.valueProperties.push(this.convertArrayObjectToValuePropertyType(parentTypeName, propertyName, schemaWrapperInfo));
108
108
  }
109
109
  else {
110
110
  schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.propertySchemaObject.items;
111
- schemaWrapperInfo.referenceProperties.push(this.convertArrayObjectToReferencePropertyType(propertyName, schemaWrapperInfo));
111
+ schemaWrapperInfo.referenceProperties.push(this.convertArrayObjectToReferencePropertyType(parentTypeName, propertyName, schemaWrapperInfo));
112
112
  }
113
113
  };
114
- OpenApiDocConverter.prototype.convertSchemaObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
114
+ OpenApiDocConverter.prototype.convertSchemaObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
115
+ var _a;
115
116
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
116
117
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
117
118
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
118
- var initialTestValue = this.getInitialTestValue(propertyName, schemaWrapperInfo);
119
+ var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
119
120
  return {
120
121
  required: required,
121
122
  name: propertyName,
@@ -128,6 +129,7 @@ var OpenApiDocConverter = /** @class */ (function () {
128
129
  minLength: schemaWrapperInfo.propertySchemaObject.minLength,
129
130
  maximum: schemaWrapperInfo.propertySchemaObject.maximum,
130
131
  minimum: schemaWrapperInfo.propertySchemaObject.minimum,
132
+ email: ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email',
131
133
  minItems: schemaWrapperInfo.propertySchemaObject.minItems,
132
134
  maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
133
135
  description: schemaWrapperInfo.propertySchemaObject.description,
@@ -140,17 +142,18 @@ var OpenApiDocConverter = /** @class */ (function () {
140
142
  var exists = validationValue !== null && validationValue !== undefined;
141
143
  return +exists;
142
144
  };
143
- OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
145
+ OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
144
146
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
145
147
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
146
148
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
147
- var initialTestValue = this.getInitialTestValue(propertyName, schemaWrapperInfo);
149
+ var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
148
150
  return {
149
151
  required: required,
150
152
  typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
151
153
  initialValue: initialValue,
152
154
  initialTestValue: initialTestValue,
153
155
  name: propertyName,
156
+ email: false,
154
157
  isArray: true,
155
158
  snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
156
159
  hasMultipleValidators: false,
@@ -187,15 +190,17 @@ var OpenApiDocConverter = /** @class */ (function () {
187
190
  return "''";
188
191
  }
189
192
  };
190
- OpenApiDocConverter.prototype.getInitialTestValue = function (propertyName, schemaWrapperInfo) {
191
- var _a, _b, _c;
193
+ OpenApiDocConverter.prototype.getInitialTestValue = function (parentTypeName, propertyName, schemaWrapperInfo) {
194
+ var _a, _b, _c, _d;
192
195
  var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
193
196
  var schemaObject = (((_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) || {})[propertyName];
194
197
  var maxLength = schemaWrapperInfo.propertySchemaObject.maxLength;
195
198
  var minLength = schemaWrapperInfo.propertySchemaObject.minLength;
199
+ var minValue = schemaWrapperInfo.propertySchemaObject.minimum;
200
+ var email = ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'email';
196
201
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
197
- var refName = schemaObject.$ref || ((_b = schemaObject.items) === null || _b === void 0 ? void 0 : _b.$ref);
198
- var refObject = (((_c = this.apiDocument.components) === null || _c === void 0 ? void 0 : _c.schemas) || {})[refName];
202
+ var refName = schemaObject.$ref || ((_c = schemaObject.items) === null || _c === void 0 ? void 0 : _c.$ref);
203
+ var refObject = (((_d = this.apiDocument.components) === null || _d === void 0 ? void 0 : _d.schemas) || {})[refName];
199
204
  var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
200
205
  if (defaultValue && refObject.enum) {
201
206
  return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
@@ -206,6 +211,9 @@ var OpenApiDocConverter = /** @class */ (function () {
206
211
  else if (defaultValue) {
207
212
  return "'".concat(defaultValue.split(' ').pop(), "'");
208
213
  }
214
+ else if (email) {
215
+ return "'".concat((0, lodash_1.kebabCase)(parentTypeName), "@email.org'");
216
+ }
209
217
  else if (typescriptType === 'Date') {
210
218
  return 'new Date()';
211
219
  }
@@ -213,7 +221,7 @@ var OpenApiDocConverter = /** @class */ (function () {
213
221
  return 'false';
214
222
  }
215
223
  else if (typescriptType === 'number') {
216
- return '0';
224
+ return minValue ? "".concat(minValue) : '0';
217
225
  }
218
226
  else {
219
227
  var retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
@@ -223,21 +231,22 @@ var OpenApiDocConverter = /** @class */ (function () {
223
231
  return "'".concat(maxLength ? retValue.substring(0, maxLength) : retValue, "'");
224
232
  }
225
233
  };
226
- OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (propertyName, schemaWrapperInfo) {
227
- return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
234
+ OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
235
+ return __assign(__assign({}, this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo)), { isArray: true });
228
236
  };
229
- OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
237
+ OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
230
238
  var _a, _b;
231
239
  var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
232
240
  var refSchema = (((_b = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _b === void 0 ? void 0 : _b.properties) || {})[propertyName];
233
241
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
234
242
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
235
243
  var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
236
- var initialTestValue = this.getInitialTestValue(propertyName, schemaWrapperInfo);
244
+ var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
237
245
  var typeName = this.parseRef(schemaWrapperInfo);
238
246
  return {
239
247
  required: required,
240
248
  name: propertyName,
249
+ isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
241
250
  initialValue: initialValue,
242
251
  initialTestValue: initialTestValue,
243
252
  snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
@@ -256,8 +265,11 @@ var OpenApiDocConverter = /** @class */ (function () {
256
265
  };
257
266
  };
258
267
  OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
268
+ var _a;
259
269
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
270
+ var email = ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email' || false;
260
271
  return (+required +
272
+ +email +
261
273
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
262
274
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
263
275
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "5.225.11",
3
+ "version": "5.230.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",
@@ -8,6 +8,7 @@
8
8
  "build": "npm run format && npm run lint && tsc && cp -rfv ./src/templates ./lib",
9
9
  "format": "prettier --write \"src/**/*.ts\"",
10
10
  "lint": "eslint . --ext .ts --output-file ./eslint-report.json --format json",
11
+ "link": "npm run build && cd lib && npm link && cd ..",
11
12
  "test": "npm run build && jest --collect-coverage",
12
13
  "prep:lib": "rm -rv ./lib/*.spec.* && rm -rv ./lib/**/*.spec.* && cp -v ./package.json ./lib/ && cp -v ./LICENSE ./lib/ && cp -v ./README.md ./lib/",
13
14
  "debug": "npm run build && node --inspect-brk ./lib/app.js"
@@ -23,9 +23,9 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
23
23
  {{/if}}
24
24
  {{else}}
25
25
  {{#if hasMultipleValidators}}
26
- {{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"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
26
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if email}}Validators.email, {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
27
27
  {{else}}
28
- {{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"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
28
+ {{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{#if email}}Validators.email {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
29
29
  {{/if}}
30
30
  {{/if}}
31
31
  {{/valueProperties}}
@@ -44,9 +44,9 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
44
44
  {{/if}}
45
45
  {{else}}
46
46
  {{#if hasMultipleValidators}}
47
- {{name}}: new FormGroup<I{{typeScriptType}}Form>({{typeScriptType}}FormGroupFac().controls, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
47
+ {{name}}: new FormGroup<I{{typeScriptType}}Form>({{#if isSameAsParentTypescriptType}}{}{{else}}{{typeScriptType}}FormGroupFac().controls{{/if}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
48
48
  {{else}}
49
- {{name}}: new FormGroup<I{{typeScriptType}}Form>({{typeScriptType}}FormGroupFac().controls{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
49
+ {{name}}: new FormGroup<I{{typeScriptType}}Form>({{#if isSameAsParentTypescriptType}}{}{{else}}{{typeScriptType}}FormGroupFac().controls{{/if}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
50
50
  {{/if}}
51
51
  {{/if}}
52
52
  {{/referenceProperties}}
@@ -15,14 +15,14 @@ export interface I{{name}}Form {
15
15
  {{#if isArray}}
16
16
  {{name}}?: FormArray<FormControl<{{typeScriptType}}>>;
17
17
  {{else}}
18
- {{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}} | undefined>;
18
+ {{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
19
19
  {{/if}}
20
20
  {{/valueProperties}}
21
21
  {{#referenceProperties}}
22
22
  {{#if isArray}}
23
23
  {{name}}?: FormArray<FormGroup<I{{typeScriptType}}Form>>;
24
24
  {{else if isEnum}}
25
- {{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}} | undefined>;
25
+ {{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}}>;
26
26
  {{else}}
27
27
  {{name}}?: FormGroup<I{{typeScriptType}}Form>;
28
28
  {{/if}}