@jmm-devkit/ngx-form-generator 1.2.3 → 1.3.0
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-cli.js +11 -1
- package/dist/generator-lib.d.ts +2 -1
- package/dist/generator-lib.js +5 -2
- package/package.json +1 -1
package/dist/generator-cli.js
CHANGED
|
@@ -28,6 +28,11 @@ async function main() {
|
|
|
28
28
|
alias: ['f', 'outFile'],
|
|
29
29
|
description: 'Generated file name',
|
|
30
30
|
type: 'string'
|
|
31
|
+
})
|
|
32
|
+
.option('max-depth', {
|
|
33
|
+
alias: ['d', 'maxDepth'],
|
|
34
|
+
description: 'Maximum depth of the generated forms',
|
|
35
|
+
type: 'number'
|
|
31
36
|
})
|
|
32
37
|
.help()
|
|
33
38
|
.wrap(null)
|
|
@@ -37,7 +42,12 @@ async function main() {
|
|
|
37
42
|
.example('npx ngx-form-generator -i swagger.json -o project/form/src/lib')
|
|
38
43
|
.alias('help', 'h').argv;
|
|
39
44
|
const spec = await (0, generator_lib_1.loadSpec)(argv['input-spec']);
|
|
40
|
-
const
|
|
45
|
+
const maxDepth = argv['max-depth'];
|
|
46
|
+
if (maxDepth !== undefined && (isNaN(maxDepth) || maxDepth < 1)) {
|
|
47
|
+
console.error('Error: max-depth must be a number greater than 0');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
const file = (0, generator_lib_1.makeForm)(spec, maxDepth);
|
|
41
51
|
let fileName = argv['file-name'] || (0, generator_lib_1.makeFileName)(spec) || 'forms.ts';
|
|
42
52
|
if (argv.output) {
|
|
43
53
|
fileName = (0, path_1.join)(argv.output, fileName);
|
package/dist/generator-lib.d.ts
CHANGED
|
@@ -10,9 +10,10 @@ import { OpenAPI } from 'openapi-types';
|
|
|
10
10
|
/**
|
|
11
11
|
* Generates Angular ReactiveForms from an OpenAPI v2 or v3 spec.
|
|
12
12
|
* @param spec - The OpenAPI document.
|
|
13
|
+
* @param maxDepth - The maximum depth of the generated forms.
|
|
13
14
|
* @returns A string representing the generated forms.
|
|
14
15
|
*/
|
|
15
|
-
export declare function makeForm(spec: OpenAPI.Document): string;
|
|
16
|
+
export declare function makeForm(spec: OpenAPI.Document, maxDepth?: number): string;
|
|
16
17
|
/**
|
|
17
18
|
* Adds a validation rule for a form field.
|
|
18
19
|
* @param rule - The validation rule to add.
|
package/dist/generator-lib.js
CHANGED
|
@@ -19,14 +19,17 @@ 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
20
|
const NEEDED_IMPORTS = `import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms'; \n`;
|
|
21
21
|
let rules = [...DEFAULT_RULES];
|
|
22
|
+
let MAX_DEPTH = 2;
|
|
22
23
|
/**
|
|
23
24
|
* Generates Angular ReactiveForms from an OpenAPI v2 or v3 spec.
|
|
24
25
|
* @param spec - The OpenAPI document.
|
|
26
|
+
* @param maxDepth - The maximum depth of the generated forms.
|
|
25
27
|
* @returns A string representing the generated forms.
|
|
26
28
|
*/
|
|
27
|
-
function makeForm(spec) {
|
|
29
|
+
function makeForm(spec, maxDepth) {
|
|
28
30
|
var _a;
|
|
29
31
|
let definitions;
|
|
32
|
+
MAX_DEPTH = maxDepth !== null && maxDepth !== void 0 ? maxDepth : MAX_DEPTH;
|
|
30
33
|
if ('definitions' in spec) {
|
|
31
34
|
definitions = spec.definitions;
|
|
32
35
|
}
|
|
@@ -67,7 +70,7 @@ function makeDefinition(definitionName, definition) {
|
|
|
67
70
|
*/
|
|
68
71
|
function makeFieldsBody(definition, depth) {
|
|
69
72
|
const fields = [];
|
|
70
|
-
if (depth
|
|
73
|
+
if (depth >= MAX_DEPTH)
|
|
71
74
|
return fields;
|
|
72
75
|
depth++;
|
|
73
76
|
const hasProperties = 'properties' in definition && definition.properties;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jmm-devkit/ngx-form-generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
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",
|