@jmm-devkit/ngx-form-generator 1.2.1 → 1.2.2
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.
- package/dist/generator-lib.d.ts +30 -1
- package/dist/generator-lib.js +175 -85
- package/dist/rules.d.ts +12 -10
- package/dist/rules.js +18 -26
- package/package.json +1 -1
package/dist/generator-lib.d.ts
CHANGED
|
@@ -7,9 +7,38 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Rule } from './rules';
|
|
9
9
|
import { OpenAPI } from 'openapi-types';
|
|
10
|
+
/**
|
|
11
|
+
* Generates Angular ReactiveForms from an OpenAPI v2 or v3 spec.
|
|
12
|
+
* @param spec - The OpenAPI document.
|
|
13
|
+
* @returns A string representing the generated forms.
|
|
14
|
+
*/
|
|
15
|
+
export declare function makeForm(spec: OpenAPI.Document): string;
|
|
16
|
+
/**
|
|
17
|
+
* Adds a validation rule for a form field.
|
|
18
|
+
* @param rule - The validation rule to add.
|
|
19
|
+
*/
|
|
10
20
|
export declare function addRule(rule: Rule): void;
|
|
21
|
+
/**
|
|
22
|
+
* Removes a validation rule from the form field rules.
|
|
23
|
+
* @param rule - The validation rule to remove.
|
|
24
|
+
*/
|
|
11
25
|
export declare function resetRules(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Generates a file name based on the OpenAPI spec title.
|
|
28
|
+
* @param swagger - The OpenAPI document.
|
|
29
|
+
* @returns A string representing the file name or undefined if no title is available.
|
|
30
|
+
*/
|
|
12
31
|
export declare function makeFileName(swagger: OpenAPI.Document): string | undefined;
|
|
13
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Saves the generated file using ts-morph.
|
|
34
|
+
* @param file - The content of the file to save.
|
|
35
|
+
* @param fileName - The name of the file to save.
|
|
36
|
+
* @returns A promise that resolves when the file is saved.
|
|
37
|
+
*/
|
|
14
38
|
export declare function saveFile(file: string, fileName: string): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Loads an OpenAPI specification from a file or URL.
|
|
41
|
+
* @param fileOrUrlPath - The path to the OpenAPI spec file or URL.
|
|
42
|
+
* @returns A promise that resolves to the dereferenced OpenAPI document.
|
|
43
|
+
*/
|
|
15
44
|
export declare function loadSpec(fileOrUrlPath: string): Promise<OpenAPI.Document>;
|
package/dist/generator-lib.js
CHANGED
|
@@ -10,91 +10,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.loadSpec = exports.saveFile = exports.
|
|
13
|
+
exports.loadSpec = exports.saveFile = exports.makeFileName = exports.resetRules = exports.addRule = exports.makeForm = void 0;
|
|
14
14
|
const ts_morph_1 = require("ts-morph");
|
|
15
15
|
const prettier_1 = __importDefault(require("prettier"));
|
|
16
16
|
const camelcase_1 = __importDefault(require("camelcase"));
|
|
17
17
|
const rules_1 = require("./rules");
|
|
18
18
|
const swagger_parser_1 = __importDefault(require("@apidevtools/swagger-parser"));
|
|
19
19
|
const DEFAULT_RULES = [rules_1.requiredRule, rules_1.patternRule, rules_1.minLengthRule, rules_1.maxLengthRule, rules_1.emailRule, rules_1.minimumRule, rules_1.maximumRule];
|
|
20
|
+
const NEEDED_IMPORTS = `import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms'; \n`;
|
|
20
21
|
let rules = [...DEFAULT_RULES];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rules = [...DEFAULT_RULES];
|
|
27
|
-
}
|
|
28
|
-
exports.resetRules = resetRules;
|
|
29
|
-
function makeFileName(swagger) {
|
|
30
|
-
if (swagger.info && swagger.info.title) {
|
|
31
|
-
return `${(0, camelcase_1.default)(swagger.info.title)}.ts`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.makeFileName = makeFileName;
|
|
35
|
-
function makeFieldRules(fieldName, definition) {
|
|
36
|
-
return rules
|
|
37
|
-
.map(rule => rule(fieldName, definition))
|
|
38
|
-
.filter(item => item != '')
|
|
39
|
-
.join();
|
|
40
|
-
}
|
|
41
|
-
function makeField(fieldName, definition) {
|
|
42
|
-
if (definition.properties[fieldName]['type'] === 'array') {
|
|
43
|
-
const itemDefinition = definition.properties[fieldName]['items'];
|
|
44
|
-
const minItems = +definition.properties[fieldName]['minItems'] || 1;
|
|
45
|
-
const items = [];
|
|
46
|
-
if (itemDefinition['type'] === 'object') {
|
|
47
|
-
for (let i = 0; i <= minItems; i++) {
|
|
48
|
-
items.push(`new FormGroup({${makeFieldsBody(itemDefinition)}})`);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const _dummyProps = {
|
|
53
|
-
properties: {
|
|
54
|
-
dummy: itemDefinition
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const value = 'default' in _dummyProps.properties.dummy ? `'${_dummyProps.properties.dummy.default}'` : null;
|
|
58
|
-
for (let i = 1; i <= minItems; i++) {
|
|
59
|
-
items.push(`new FormControl(${value}, [${makeFieldRules('dummy', _dummyProps)}])`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return `"${fieldName}": new FormArray([${items.join(',')}])`;
|
|
63
|
-
}
|
|
64
|
-
else if (definition.properties[fieldName]['type'] === 'object') {
|
|
65
|
-
const constructFormGroup = makeFieldsBody(definition.properties[fieldName]);
|
|
66
|
-
return `"${fieldName}": new FormGroup({${constructFormGroup}})`;
|
|
67
|
-
}
|
|
68
|
-
const value = 'default' in definition.properties[fieldName] ? `'${definition.properties[fieldName].default}'` : null;
|
|
69
|
-
return `"${fieldName}": new FormControl(${value}, [${makeFieldRules(fieldName, definition)}])`;
|
|
70
|
-
}
|
|
71
|
-
function makeFieldsBody(definition) {
|
|
72
|
-
if ('allOf' in definition) {
|
|
73
|
-
const definitionKeys = Object.keys(definition.allOf);
|
|
74
|
-
const allOfFieldsBody = definitionKeys
|
|
75
|
-
.map(key => makeFieldsBody(definition.allOf[key]))
|
|
76
|
-
.reduce((acc, val) => acc.concat(val), []);
|
|
77
|
-
return allOfFieldsBody;
|
|
78
|
-
}
|
|
79
|
-
if (!definition.properties)
|
|
80
|
-
return [];
|
|
81
|
-
const fields = Object.keys(definition.properties);
|
|
82
|
-
const fieldsBody = fields.map(fieldName => makeField(fieldName, definition)).filter(item => item !== '');
|
|
83
|
-
return fieldsBody;
|
|
84
|
-
}
|
|
85
|
-
function makeDefinition(definitionName, definition) {
|
|
86
|
-
const fieldsBody = makeFieldsBody(definition);
|
|
87
|
-
return `
|
|
88
|
-
export const ${(0, camelcase_1.default)(definitionName)}Form = () => new FormGroup({
|
|
89
|
-
${fieldsBody}
|
|
90
|
-
});
|
|
91
|
-
`;
|
|
92
|
-
}
|
|
93
|
-
function makeHeader(body) {
|
|
94
|
-
return `import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms';
|
|
95
|
-
|
|
96
|
-
${body}`;
|
|
97
|
-
}
|
|
22
|
+
/**
|
|
23
|
+
* Generates Angular ReactiveForms from an OpenAPI v2 or v3 spec.
|
|
24
|
+
* @param spec - The OpenAPI document.
|
|
25
|
+
* @returns A string representing the generated forms.
|
|
26
|
+
*/
|
|
98
27
|
function makeForm(spec) {
|
|
99
28
|
var _a;
|
|
100
29
|
let definitions;
|
|
@@ -110,21 +39,182 @@ function makeForm(spec) {
|
|
|
110
39
|
if (!definitions) {
|
|
111
40
|
throw new Error('Cannot find schemas/definitions');
|
|
112
41
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return prettier_1.default.format(
|
|
42
|
+
let body = NEEDED_IMPORTS + '\n\n';
|
|
43
|
+
Object.keys(definitions).forEach(key => {
|
|
44
|
+
if (definitions === null || definitions === void 0 ? void 0 : definitions[key]) {
|
|
45
|
+
body += makeDefinition(key, definitions[key]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return prettier_1.default.format(body, { parser: 'typescript', singleQuote: true });
|
|
120
49
|
}
|
|
121
50
|
exports.makeForm = makeForm;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a form definition for a given OpenAPI definition.
|
|
53
|
+
* @param definitionName - The name of the definition.
|
|
54
|
+
* @param definition - The OpenAPI definition object.
|
|
55
|
+
* @returns A string representing the form definition.
|
|
56
|
+
*/
|
|
57
|
+
function makeDefinition(definitionName, definition) {
|
|
58
|
+
return `export const ${(0, camelcase_1.default)(definitionName)}Form = () => new FormGroup({
|
|
59
|
+
${makeFieldsBody(definition, 0)}
|
|
60
|
+
});\n`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Generates the body of fields for a form based on the provided definition.
|
|
64
|
+
* @param definition - The OpenAPI definition object containing properties.
|
|
65
|
+
* @param depth - The current depth of recursion.
|
|
66
|
+
* @returns An array of strings representing the form fields.
|
|
67
|
+
*/
|
|
68
|
+
function makeFieldsBody(definition, depth) {
|
|
69
|
+
if (!('properties' in definition) || !definition.properties || depth > 2)
|
|
70
|
+
return [];
|
|
71
|
+
depth++;
|
|
72
|
+
const fields = [];
|
|
73
|
+
Object.keys(definition.properties).forEach(fieldName => {
|
|
74
|
+
var _a, _b;
|
|
75
|
+
const field = makeField(fieldName, (_a = definition.properties) === null || _a === void 0 ? void 0 : _a[fieldName], !!((_b = definition.required) === null || _b === void 0 ? void 0 : _b.includes(fieldName)), depth);
|
|
76
|
+
if (field !== '') {
|
|
77
|
+
fields.push(field);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return fields;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a form field for a given OpenAPI property.
|
|
84
|
+
* @param fieldName - The name of the field.
|
|
85
|
+
* @param property - The OpenAPI property object.
|
|
86
|
+
* @param isRequired - Indicates if the field is required.
|
|
87
|
+
* @param depth - The current depth of recursion.
|
|
88
|
+
* @returns A string representing the form field.
|
|
89
|
+
*/
|
|
90
|
+
function makeField(fieldName, property, isRequired, depth) {
|
|
91
|
+
let fieldRepesentation;
|
|
92
|
+
if (property.allOf) {
|
|
93
|
+
fieldRepesentation = makeField(fieldName, property.allOf, isRequired, depth);
|
|
94
|
+
}
|
|
95
|
+
else if (property.type === 'array') {
|
|
96
|
+
fieldRepesentation = makeArrayField(fieldName, property, isRequired, depth);
|
|
97
|
+
}
|
|
98
|
+
else if (property.type === 'object') {
|
|
99
|
+
fieldRepesentation = makeObjectField(fieldName, property, isRequired, depth);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
fieldRepesentation = makePrimitiveField(fieldName, property, isRequired);
|
|
103
|
+
}
|
|
104
|
+
return fieldRepesentation;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Creates a form array field for a given OpenAPI array schema.
|
|
108
|
+
* @param fieldName - The name of the field.
|
|
109
|
+
* @param property - The OpenAPI array schema object.
|
|
110
|
+
* @param isRequired - Indicates if the field is required.
|
|
111
|
+
* @param depth - The current depth of recursion.
|
|
112
|
+
* @returns A string representing the form array field.
|
|
113
|
+
*/
|
|
114
|
+
function makeArrayField(fieldName, property, isRequired, depth) {
|
|
115
|
+
var _a;
|
|
116
|
+
const itemDefinition = property.items;
|
|
117
|
+
const minItems = (_a = property['minItems']) !== null && _a !== void 0 ? _a : 1;
|
|
118
|
+
const items = [];
|
|
119
|
+
if (itemDefinition['type'] === 'object') {
|
|
120
|
+
for (let i = 0; i <= minItems; i++) {
|
|
121
|
+
items.push(`new FormGroup({${makeFieldsBody(itemDefinition, depth)}})`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const _dummyProps = {
|
|
126
|
+
properties: {
|
|
127
|
+
dummy: itemDefinition
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const value = 'default' in _dummyProps.properties.dummy ? `'${_dummyProps.properties.dummy.default}'` : null;
|
|
131
|
+
for (let i = 1; i <= minItems; i++) {
|
|
132
|
+
items.push(`new FormControl(${value}, [${makeFieldRules('dummy', _dummyProps, isRequired)}])`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return `"${fieldName}": new FormArray([${items.join(',')}])`;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates a form object field for a given OpenAPI object schema.
|
|
139
|
+
* @param fieldName - The name of the field.
|
|
140
|
+
* @param property - The OpenAPI object schema object.
|
|
141
|
+
* @param isRequired - Indicates if the field is required.
|
|
142
|
+
* @param depth - The current depth of recursion.
|
|
143
|
+
* @returns A string representing the form object field.
|
|
144
|
+
*/
|
|
145
|
+
function makeObjectField(fieldName, property, isRequired, depth) {
|
|
146
|
+
const groupBody = makeFieldsBody(property, depth);
|
|
147
|
+
return `"${fieldName}": new FormGroup({${groupBody}}, [${makeFieldRules(fieldName, property, isRequired)}])`;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Creates a form control for a primitive field based on its OpenAPI definition.
|
|
151
|
+
* @param fieldName - The name of the field.
|
|
152
|
+
* @param property - The OpenAPI property object.
|
|
153
|
+
* @param isRequired - Indicates if the field is required.
|
|
154
|
+
* @returns A string representing the form control.
|
|
155
|
+
*/
|
|
156
|
+
function makePrimitiveField(fieldName, property, isRequired) {
|
|
157
|
+
const value = 'default' in property ? `'${property.default}'` : null;
|
|
158
|
+
return `"${fieldName}": new FormControl(${value}, [${makeFieldRules(fieldName, property, isRequired)}])`;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates validation rules for a form field based on its OpenAPI definition.
|
|
162
|
+
* @param fieldName - The name of the field.
|
|
163
|
+
* @param property - The OpenAPI property object.
|
|
164
|
+
* @param isRequired - Indicates if the field is required.
|
|
165
|
+
* @returns A string representing the validation rules.
|
|
166
|
+
*/
|
|
167
|
+
function makeFieldRules(fieldName, property, isRequired) {
|
|
168
|
+
return rules
|
|
169
|
+
.map(rule => rule(fieldName, property, isRequired))
|
|
170
|
+
.filter(item => item != '')
|
|
171
|
+
.join();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Adds a validation rule for a form field.
|
|
175
|
+
* @param rule - The validation rule to add.
|
|
176
|
+
*/
|
|
177
|
+
function addRule(rule) {
|
|
178
|
+
rules.push(rule);
|
|
179
|
+
}
|
|
180
|
+
exports.addRule = addRule;
|
|
181
|
+
/**
|
|
182
|
+
* Removes a validation rule from the form field rules.
|
|
183
|
+
* @param rule - The validation rule to remove.
|
|
184
|
+
*/
|
|
185
|
+
function resetRules() {
|
|
186
|
+
rules = [...DEFAULT_RULES];
|
|
187
|
+
}
|
|
188
|
+
exports.resetRules = resetRules;
|
|
189
|
+
/**
|
|
190
|
+
* Generates a file name based on the OpenAPI spec title.
|
|
191
|
+
* @param swagger - The OpenAPI document.
|
|
192
|
+
* @returns A string representing the file name or undefined if no title is available.
|
|
193
|
+
*/
|
|
194
|
+
function makeFileName(swagger) {
|
|
195
|
+
var _a;
|
|
196
|
+
if ((_a = swagger.info) === null || _a === void 0 ? void 0 : _a.title) {
|
|
197
|
+
return `${(0, camelcase_1.default)(swagger.info.title)}.ts`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
exports.makeFileName = makeFileName;
|
|
201
|
+
/**
|
|
202
|
+
* Saves the generated file using ts-morph.
|
|
203
|
+
* @param file - The content of the file to save.
|
|
204
|
+
* @param fileName - The name of the file to save.
|
|
205
|
+
* @returns A promise that resolves when the file is saved.
|
|
206
|
+
*/
|
|
122
207
|
async function saveFile(file, fileName) {
|
|
123
208
|
const project = new ts_morph_1.Project();
|
|
124
209
|
project.createSourceFile(fileName, file, { overwrite: true });
|
|
125
210
|
return project.save();
|
|
126
211
|
}
|
|
127
212
|
exports.saveFile = saveFile;
|
|
213
|
+
/**
|
|
214
|
+
* Loads an OpenAPI specification from a file or URL.
|
|
215
|
+
* @param fileOrUrlPath - The path to the OpenAPI spec file or URL.
|
|
216
|
+
* @returns A promise that resolves to the dereferenced OpenAPI document.
|
|
217
|
+
*/
|
|
128
218
|
async function loadSpec(fileOrUrlPath) {
|
|
129
219
|
const parser = new swagger_parser_1.default();
|
|
130
220
|
return parser.dereference(fileOrUrlPath);
|
package/dist/rules.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Copyright (c) 2020 Verizon
|
|
7
7
|
*/
|
|
8
|
-
import { OpenAPIV2 } from 'openapi-types';
|
|
8
|
+
import { OpenAPIV2, OpenAPIV3 } from 'openapi-types';
|
|
9
9
|
export declare type Property = {
|
|
10
10
|
format?: string;
|
|
11
11
|
pattern?: string;
|
|
@@ -15,12 +15,14 @@ export declare type Property = {
|
|
|
15
15
|
maximum?: number;
|
|
16
16
|
};
|
|
17
17
|
export declare type Properties = Record<string, Property>;
|
|
18
|
-
export declare type Rule = (fieldName: string, properties:
|
|
19
|
-
export declare type
|
|
20
|
-
export declare
|
|
21
|
-
export declare
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
export declare function
|
|
25
|
-
export declare function
|
|
26
|
-
export declare function
|
|
18
|
+
export declare type Rule = (fieldName: string, properties: SchemaProperty, isRequired: boolean) => string;
|
|
19
|
+
export declare type Definitions = OpenAPIV2.DefinitionsObject | Record<string, OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject> | undefined;
|
|
20
|
+
export declare type Definition = OpenAPIV2.DefinitionsObject | OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject;
|
|
21
|
+
export declare type SchemaProperty = OpenAPIV2.SchemaObject | OpenAPIV3.SchemaObject;
|
|
22
|
+
export declare function requiredRule(fieldName: string, property: SchemaProperty, isRequired: boolean): string;
|
|
23
|
+
export declare function patternRule(fieldName: string, property: SchemaProperty): string;
|
|
24
|
+
export declare function minLengthRule(fieldName: string, property: SchemaProperty): string;
|
|
25
|
+
export declare function maxLengthRule(fieldName: string, property: SchemaProperty): string;
|
|
26
|
+
export declare function emailRule(fieldName: string, property: SchemaProperty): string;
|
|
27
|
+
export declare function minimumRule(fieldName: string, property: SchemaProperty): string;
|
|
28
|
+
export declare function maximumRule(fieldName: string, property: SchemaProperty): string;
|
package/dist/rules.js
CHANGED
|
@@ -8,45 +8,37 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.maximumRule = exports.minimumRule = exports.emailRule = exports.maxLengthRule = exports.minLengthRule = exports.patternRule = exports.requiredRule = void 0;
|
|
11
|
-
function hasMetadata(fieldName,
|
|
12
|
-
return
|
|
11
|
+
function hasMetadata(fieldName, property, metadataName) {
|
|
12
|
+
return property.hasOwnProperty(metadataName);
|
|
13
13
|
}
|
|
14
|
-
function abstractRule(fieldName,
|
|
15
|
-
return hasMetadata(fieldName,
|
|
16
|
-
? `Validators.${ruleName}(${definition.properties[fieldName][ruleName]})`
|
|
17
|
-
: '';
|
|
14
|
+
function abstractRule(fieldName, property, ruleName) {
|
|
15
|
+
return hasMetadata(fieldName, property, ruleName) ? `Validators.${ruleName}(${property[ruleName]})` : '';
|
|
18
16
|
}
|
|
19
|
-
function requiredRule(fieldName,
|
|
20
|
-
return
|
|
17
|
+
function requiredRule(fieldName, property, isRequired) {
|
|
18
|
+
return isRequired ? `Validators.required` : '';
|
|
21
19
|
}
|
|
22
20
|
exports.requiredRule = requiredRule;
|
|
23
|
-
function patternRule(fieldName,
|
|
24
|
-
return hasMetadata(fieldName,
|
|
25
|
-
? `Validators.pattern(/${definition.properties[fieldName]['pattern']}/)`
|
|
26
|
-
: '';
|
|
21
|
+
function patternRule(fieldName, property) {
|
|
22
|
+
return hasMetadata(fieldName, property, 'pattern') ? `Validators.pattern(/${property['pattern']}/)` : '';
|
|
27
23
|
}
|
|
28
24
|
exports.patternRule = patternRule;
|
|
29
|
-
function minLengthRule(fieldName,
|
|
30
|
-
return abstractRule(fieldName,
|
|
25
|
+
function minLengthRule(fieldName, property) {
|
|
26
|
+
return abstractRule(fieldName, property, 'minLength');
|
|
31
27
|
}
|
|
32
28
|
exports.minLengthRule = minLengthRule;
|
|
33
|
-
function maxLengthRule(fieldName,
|
|
34
|
-
return abstractRule(fieldName,
|
|
29
|
+
function maxLengthRule(fieldName, property) {
|
|
30
|
+
return abstractRule(fieldName, property, 'maxLength');
|
|
35
31
|
}
|
|
36
32
|
exports.maxLengthRule = maxLengthRule;
|
|
37
|
-
function emailRule(fieldName,
|
|
38
|
-
return
|
|
33
|
+
function emailRule(fieldName, property) {
|
|
34
|
+
return property.format === 'email' ? `Validators.email` : '';
|
|
39
35
|
}
|
|
40
36
|
exports.emailRule = emailRule;
|
|
41
|
-
function minimumRule(fieldName,
|
|
42
|
-
return hasMetadata(fieldName,
|
|
43
|
-
? `Validators.min(${definition.properties[fieldName]['minimum']})`
|
|
44
|
-
: '';
|
|
37
|
+
function minimumRule(fieldName, property) {
|
|
38
|
+
return hasMetadata(fieldName, property, 'minimum') ? `Validators.min(${property['minimum']})` : '';
|
|
45
39
|
}
|
|
46
40
|
exports.minimumRule = minimumRule;
|
|
47
|
-
function maximumRule(fieldName,
|
|
48
|
-
return hasMetadata(fieldName,
|
|
49
|
-
? `Validators.max(${definition.properties[fieldName]['maximum']})`
|
|
50
|
-
: '';
|
|
41
|
+
function maximumRule(fieldName, property) {
|
|
42
|
+
return hasMetadata(fieldName, property, 'maximum') ? `Validators.max(${property['maximum']})` : '';
|
|
51
43
|
}
|
|
52
44
|
exports.maximumRule = maximumRule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jmm-devkit/ngx-form-generator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Generates an Angular ReactiveForm from a Swagger or OpenAPI definition",
|
|
5
5
|
"main": "dist/generator-lib.js",
|
|
6
6
|
"repository": "github:jmm-devkit/ngx-form-generator",
|