openapi-ts-generator 5.225.9 → 5.227.6
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;
|
package/openapidoc-converter.js
CHANGED
|
@@ -112,6 +112,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
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);
|
|
@@ -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,
|
|
@@ -151,6 +153,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
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,
|
|
@@ -188,27 +191,29 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
188
191
|
}
|
|
189
192
|
};
|
|
190
193
|
OpenApiDocConverter.prototype.getInitialTestValue = function (parentTypeName, propertyName, schemaWrapperInfo) {
|
|
191
|
-
var _a, _b, _c;
|
|
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 || ((
|
|
198
|
-
var refObject = (((
|
|
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());
|
|
202
207
|
}
|
|
203
|
-
else if (refObject
|
|
204
|
-
return schemaObject.type === 'array' ? "[
|
|
205
|
-
}
|
|
206
|
-
else if (refObject && parentTypeName == refName) {
|
|
207
|
-
return schemaObject.type === 'array' ? "[]" : "null";
|
|
208
|
+
else if (refObject) {
|
|
209
|
+
return schemaObject.type === 'array' ? "[]" : "undefined";
|
|
208
210
|
}
|
|
209
211
|
else if (defaultValue) {
|
|
210
212
|
return "'".concat(defaultValue.split(' ').pop(), "'");
|
|
211
213
|
}
|
|
214
|
+
else if (email) {
|
|
215
|
+
return "'".concat((0, lodash_1.kebabCase)(parentTypeName), "@email.org'");
|
|
216
|
+
}
|
|
212
217
|
else if (typescriptType === 'Date') {
|
|
213
218
|
return 'new Date()';
|
|
214
219
|
}
|
|
@@ -216,14 +221,14 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
216
221
|
return 'false';
|
|
217
222
|
}
|
|
218
223
|
else if (typescriptType === 'number') {
|
|
219
|
-
return '0';
|
|
224
|
+
return minValue ? "".concat(minValue) : '0';
|
|
220
225
|
}
|
|
221
226
|
else {
|
|
222
227
|
var retValue = (0, lodash_1.snakeCase)(propertyName).toUpperCase();
|
|
223
228
|
while (minLength && retValue.length < minLength) {
|
|
224
|
-
retValue
|
|
229
|
+
retValue = "".concat(retValue, "_").concat(retValue);
|
|
225
230
|
}
|
|
226
|
-
return "'".concat(maxLength ?
|
|
231
|
+
return "'".concat(maxLength ? retValue.substring(0, maxLength) : retValue, "'");
|
|
227
232
|
}
|
|
228
233
|
};
|
|
229
234
|
OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
|
|
@@ -241,6 +246,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
241
246
|
return {
|
|
242
247
|
required: required,
|
|
243
248
|
name: propertyName,
|
|
249
|
+
isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
|
|
244
250
|
initialValue: initialValue,
|
|
245
251
|
initialTestValue: initialTestValue,
|
|
246
252
|
snakeCaseName: (0, lodash_1.snakeCase)(propertyName).toUpperCase(),
|
|
@@ -259,8 +265,11 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
259
265
|
};
|
|
260
266
|
};
|
|
261
267
|
OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
|
|
268
|
+
var _a;
|
|
262
269
|
var required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
270
|
+
var email = ((_a = schemaWrapperInfo.propertySchemaObject.format) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'email' || false;
|
|
263
271
|
return (+required +
|
|
272
|
+
+email +
|
|
264
273
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxLength) +
|
|
265
274
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
|
|
266
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.
|
|
3
|
+
"version": "5.227.6",
|
|
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",
|
|
@@ -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{{#
|
|
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{{#
|
|
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}}
|
package/templates/form.ts.hbs
CHANGED
|
@@ -13,18 +13,18 @@ import { I{{name}}Form } from './{{kebabCasedTypeName}}.form';{{/if}}{{/unless}}
|
|
|
13
13
|
export interface I{{name}}Form {
|
|
14
14
|
{{#valueProperties}}
|
|
15
15
|
{{#if isArray}}
|
|
16
|
-
{{name}}
|
|
16
|
+
{{name}}?: FormArray<FormControl<{{typeScriptType}}>>;
|
|
17
17
|
{{else}}
|
|
18
|
-
{{name}}
|
|
18
|
+
{{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}} | undefined>;
|
|
19
19
|
{{/if}}
|
|
20
20
|
{{/valueProperties}}
|
|
21
21
|
{{#referenceProperties}}
|
|
22
22
|
{{#if isArray}}
|
|
23
|
-
{{name}}
|
|
23
|
+
{{name}}?: FormArray<FormGroup<I{{typeScriptType}}Form>>;
|
|
24
24
|
{{else if isEnum}}
|
|
25
|
-
{{name}}
|
|
25
|
+
{{name}}?: FormControl<{{typeScriptType}}{{#unless required}} | null{{/unless}} | undefined>;
|
|
26
26
|
{{else}}
|
|
27
|
-
{{name}}
|
|
27
|
+
{{name}}?: FormGroup<I{{typeScriptType}}Form>;
|
|
28
28
|
{{/if}}
|
|
29
29
|
{{/referenceProperties}}
|
|
30
30
|
}
|
package/templates/model.ts.hbs
CHANGED
|
@@ -22,9 +22,9 @@ export interface I{{{name}}} {
|
|
|
22
22
|
{{/valueProperties}}
|
|
23
23
|
{{#referenceProperties}}
|
|
24
24
|
{{#if isEnum}}
|
|
25
|
-
{{name}}?: {{referenceTypeName}}{{#if isArray}}[]{{/if}}
|
|
25
|
+
{{name}}?: {{referenceTypeName}}{{#if isArray}}[]{{/if}};
|
|
26
26
|
{{else}}
|
|
27
|
-
{{name}}?: Partial<I{{referenceTypeName}}{{#if isArray}}[]{{/if}}
|
|
27
|
+
{{name}}?: Partial<I{{referenceTypeName}}{{#if isArray}}[]{{/if}}>;
|
|
28
28
|
{{/if}}
|
|
29
29
|
{{/referenceProperties}}
|
|
30
30
|
}
|
|
@@ -6,12 +6,10 @@
|
|
|
6
6
|
* Do not edit.
|
|
7
7
|
*/
|
|
8
8
|
{{#if importTypes}}{{#importTypes}}{{#unless isSelfReferencing}}{{#if isEnum}}
|
|
9
|
-
import { {{name}} } from './{{kebabCasedTypeName}}.enum';{{
|
|
10
|
-
import { createTest{{name}} } from './{{kebabCasedTypeName}}.test-obj-fac';{{/if}}{{/unless}}{{/importTypes}}{{/if}}
|
|
11
|
-
import { I{{name}} } from './{{kebabCasedName}}.model';
|
|
9
|
+
import { {{name}} } from './{{kebabCasedTypeName}}.enum';{{/if}}{{/unless}}{{/importTypes}}{{/if}}
|
|
12
10
|
import { {{name}}Properties } from './{{kebabCasedName}}.properties';
|
|
13
11
|
|
|
14
|
-
export function createTest{{name}}()
|
|
12
|
+
export function createTest{{name}}() {
|
|
15
13
|
return { {{#valueProperties}}
|
|
16
14
|
[{{../name}}Properties.{{snakeCaseName}}]: {{{initialTestValue}}},{{/valueProperties}} {{#referenceProperties}}
|
|
17
15
|
[{{../name}}Properties.{{snakeCaseName}}]: {{{initialTestValue}}},{{/referenceProperties}}
|