openapi-ts-generator 5.223.4 → 5.223.7
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.
|
@@ -7,5 +7,6 @@ export declare class FormGroupGenerator extends BaseGenerator<IEntity> {
|
|
|
7
7
|
constructor(options: IGeneratorOptions);
|
|
8
8
|
generate(templateData: ITemplateData): void;
|
|
9
9
|
registerHelpers(): void;
|
|
10
|
+
registerValidatorHelper(validatorName: string, angularValidatorName?: string): void;
|
|
10
11
|
validatorFactory(propertyCollection: PropertyType, propertyContext: IHelperContext, validationName: string, angularValidatorFunctionName: string): string;
|
|
11
12
|
}
|
|
@@ -37,17 +37,19 @@ var FormGroupGenerator = /** @class */ (function (_super) {
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
FormGroupGenerator.prototype.registerHelpers = function () {
|
|
40
|
+
this.registerValidatorHelper('minimum', 'min');
|
|
41
|
+
this.registerValidatorHelper('maximum', 'max');
|
|
42
|
+
this.registerValidatorHelper('minLength');
|
|
43
|
+
this.registerValidatorHelper('maxLength');
|
|
44
|
+
this.registerValidatorHelper('maxItems', 'maxLength');
|
|
45
|
+
this.registerValidatorHelper('minItems', 'minLength');
|
|
46
|
+
this.registerValidatorHelper('pattern');
|
|
47
|
+
};
|
|
48
|
+
FormGroupGenerator.prototype.registerValidatorHelper = function (validatorName, angularValidatorName) {
|
|
40
49
|
var _this = this;
|
|
41
|
-
|
|
42
|
-
HandleBars.registerHelper(
|
|
43
|
-
|
|
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');
|
|
50
|
+
if (angularValidatorName === void 0) { angularValidatorName = validatorName; }
|
|
51
|
+
HandleBars.registerHelper("".concat(validatorName, "Validator"), function (x, y) {
|
|
52
|
+
return _this.validatorFactory(x, y, validatorName, angularValidatorName);
|
|
51
53
|
});
|
|
52
54
|
};
|
|
53
55
|
FormGroupGenerator.prototype.validatorFactory = function (propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
|
|
@@ -39,6 +39,8 @@ export interface IValueProperty {
|
|
|
39
39
|
minLength?: number;
|
|
40
40
|
maximum?: number;
|
|
41
41
|
minimum?: number;
|
|
42
|
+
maxItems?: number;
|
|
43
|
+
minItems?: number;
|
|
42
44
|
description?: string;
|
|
43
45
|
pattern?: string;
|
|
44
46
|
initialValue: string;
|
|
@@ -49,6 +51,13 @@ export interface IReferenceProperty {
|
|
|
49
51
|
referenceTypeName: string;
|
|
50
52
|
typeScriptType: string;
|
|
51
53
|
hasValidators: boolean;
|
|
54
|
+
hasMultipleValidators: boolean;
|
|
55
|
+
maxItems?: number;
|
|
56
|
+
minItems?: number;
|
|
57
|
+
maxLength?: number;
|
|
58
|
+
minLength?: number;
|
|
59
|
+
maximum?: number;
|
|
60
|
+
minimum?: number;
|
|
52
61
|
isArray: boolean;
|
|
53
62
|
required: boolean;
|
|
54
63
|
isEnum?: boolean;
|
package/openapidoc-converter.js
CHANGED
|
@@ -125,6 +125,8 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
125
125
|
minLength: schemaWrapperInfo.propertySchemaObject.minLength,
|
|
126
126
|
maximum: schemaWrapperInfo.propertySchemaObject.maximum,
|
|
127
127
|
minimum: schemaWrapperInfo.propertySchemaObject.minimum,
|
|
128
|
+
minItems: schemaWrapperInfo.propertySchemaObject.minItems,
|
|
129
|
+
maxItems: schemaWrapperInfo.propertySchemaObject.maxItems,
|
|
128
130
|
description: schemaWrapperInfo.propertySchemaObject.description,
|
|
129
131
|
pattern: schemaWrapperInfo.propertySchemaObject.pattern,
|
|
130
132
|
hasMultipleValidators: validatorCount > 1,
|
|
@@ -184,8 +186,9 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
184
186
|
return __assign(__assign({}, this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo)), { isArray: true });
|
|
185
187
|
};
|
|
186
188
|
OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (propertyName, schemaWrapperInfo) {
|
|
187
|
-
var _a;
|
|
189
|
+
var _a, _b;
|
|
188
190
|
var propertySchema = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || {})[this.parseRef(schemaWrapperInfo)];
|
|
191
|
+
var refSchema = (((_b = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _b === void 0 ? void 0 : _b.properties) || {})[propertyName];
|
|
189
192
|
var required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
190
193
|
var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
191
194
|
var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
|
|
@@ -200,6 +203,13 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
200
203
|
isArray: false,
|
|
201
204
|
isEnum: (propertySchema.enum || []).length > 0,
|
|
202
205
|
hasValidators: validatorCount > 0,
|
|
206
|
+
hasMultipleValidators: validatorCount > 1,
|
|
207
|
+
maxLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxLength,
|
|
208
|
+
minLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minLength,
|
|
209
|
+
maximum: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maximum,
|
|
210
|
+
minimum: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minimum,
|
|
211
|
+
minItems: refSchema === null || refSchema === void 0 ? void 0 : refSchema.minItems,
|
|
212
|
+
maxItems: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxItems,
|
|
203
213
|
};
|
|
204
214
|
};
|
|
205
215
|
OpenApiDocConverter.prototype.getValidatorCount = function (propertyName, schemaWrapperInfo) {
|
|
@@ -209,6 +219,8 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
209
219
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.minLength) +
|
|
210
220
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.maximum) +
|
|
211
221
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.minimum) +
|
|
222
|
+
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.maxItems) +
|
|
223
|
+
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.minItems) +
|
|
212
224
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
|
|
213
225
|
};
|
|
214
226
|
OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-generator",
|
|
3
|
-
"version": "5.223.
|
|
3
|
+
"version": "5.223.7",
|
|
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",
|
|
@@ -15,30 +15,30 @@ export function {{name}}FormGroupFac(): FormGroup {
|
|
|
15
15
|
{{#valueProperties}}
|
|
16
16
|
{{#if isArray}}
|
|
17
17
|
{{#if hasMultipleValidators}}
|
|
18
|
-
{{name}}: new FormControl([], { validators: 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"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]) })),
|
|
19
19
|
{{else}}
|
|
20
|
-
{{name}}: new FormControl([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{{patternValidator "valueProperties"}}} }{{/if}}),
|
|
20
|
+
{{name}}: new FormControl([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}} }{{/if}}),
|
|
21
21
|
{{/if}}
|
|
22
22
|
{{else}}
|
|
23
23
|
{{#if hasMultipleValidators}}
|
|
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}} }),
|
|
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"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
|
|
25
25
|
{{else}}
|
|
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}}),
|
|
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"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
|
|
27
27
|
{{/if}}
|
|
28
28
|
{{/if}}
|
|
29
29
|
{{/valueProperties}}
|
|
30
30
|
{{#referenceProperties}}
|
|
31
31
|
{{#if isArray}}
|
|
32
32
|
{{#if hasMultipleValidators}}
|
|
33
|
-
{{name}}: new FormArray([], { validators: 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"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]) }),
|
|
34
34
|
{{else}}
|
|
35
|
-
{{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
|
|
35
|
+
{{name}}: new FormArray([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
|
|
36
36
|
{{/if}}
|
|
37
37
|
{{else}}
|
|
38
38
|
{{#if hasMultipleValidators}}
|
|
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}} }),
|
|
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"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
|
|
40
40
|
{{else}}
|
|
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}}),
|
|
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"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
|
|
42
42
|
{{/if}}
|
|
43
43
|
{{/if}}
|
|
44
44
|
{{/referenceProperties}}
|