@jmm-devkit/ngx-form-generator 1.2.2 → 1.2.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.
Files changed (2) hide show
  1. package/dist/generator-lib.js +32 -10
  2. package/package.json +79 -79
@@ -66,17 +66,39 @@ function makeDefinition(definitionName, definition) {
66
66
  * @returns An array of strings representing the form fields.
67
67
  */
68
68
  function makeFieldsBody(definition, depth) {
69
- if (!('properties' in definition) || !definition.properties || depth > 2)
70
- return [];
71
- depth++;
72
69
  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
- });
70
+ if (depth > 2)
71
+ return fields;
72
+ depth++;
73
+ const hasProperties = 'properties' in definition && definition.properties;
74
+ if (hasProperties && definition.properties) {
75
+ // Process each property in the definition
76
+ Object.keys(definition.properties).forEach(fieldName => {
77
+ var _a, _b;
78
+ 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);
79
+ if (field !== '') {
80
+ fields.push(field);
81
+ }
82
+ });
83
+ }
84
+ // Handle allOf by merging properties from referenced schemas
85
+ const hasAllOf = 'allOf' in definition && Array.isArray(definition.allOf);
86
+ if (hasAllOf && definition.allOf) {
87
+ definition.allOf.forEach((subSchema) => {
88
+ var _a, _b, _c;
89
+ // If the subSchema is a reference, resolve it from definitions
90
+ if ('$ref' in subSchema) {
91
+ const refName = subSchema.$ref.split('/').pop();
92
+ const refSchema = ((_a = definition.definitions) === null || _a === void 0 ? void 0 : _a[refName]) || ((_c = (_b = definition.components) === null || _b === void 0 ? void 0 : _b.schemas) === null || _c === void 0 ? void 0 : _c[refName]);
93
+ if (refSchema) {
94
+ fields.push(...makeFieldsBody(refSchema, depth));
95
+ }
96
+ }
97
+ else {
98
+ fields.push(...makeFieldsBody(subSchema, depth));
99
+ }
100
+ });
101
+ }
80
102
  return fields;
81
103
  }
82
104
  /**
package/package.json CHANGED
@@ -1,79 +1,79 @@
1
- {
2
- "name": "@jmm-devkit/ngx-form-generator",
3
- "version": "1.2.2",
4
- "description": "Generates an Angular ReactiveForm from a Swagger or OpenAPI definition",
5
- "main": "dist/generator-lib.js",
6
- "repository": "github:jmm-devkit/ngx-form-generator",
7
- "bin": {
8
- "ngx-form-generator": "dist/generator-cli.js"
9
- },
10
- "scripts": {
11
- "test": "npm run build && jasmine dist/*.spec.js",
12
- "build": "tsc --project .\\",
13
- "lint": "eslint . --ext .ts",
14
- "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
15
- },
16
- "author": "Martin McWhorter <martin@mcwhorter.org> (https://github.com/martinmcwhorter)",
17
- "license": "MIT",
18
- "keywords": [
19
- "angular",
20
- "validation",
21
- "form",
22
- "reactive-forms",
23
- "swagger",
24
- "openapi",
25
- "typescript"
26
- ],
27
- "devDependencies": {
28
- "@commitlint/cli": "^17.1.2",
29
- "@commitlint/config-conventional": "^17.0.3",
30
- "@types/camelcase": "^4.1.0",
31
- "@types/jasmine": "^4.3.0",
32
- "@types/node-fetch": "^2.5.5",
33
- "@types/prettier": "^1.19.1",
34
- "@types/yaml": "^1.2.0",
35
- "@types/yargs": "^17.0.13",
36
- "@typescript-eslint/eslint-plugin": "^5.0.0",
37
- "@typescript-eslint/parser": "^5.0.0",
38
- "commitiquette": "^1.2.1",
39
- "commitizen": "^4.2.4",
40
- "eslint": "^8.0.1",
41
- "eslint-config-prettier": "^6.10.1",
42
- "husky": "^7.0.4",
43
- "jasmine": "^4.4.0",
44
- "lint-staged": "^13.0.3",
45
- "openapi-types": "^7.0.1",
46
- "typescript": "^4.8.4"
47
- },
48
- "dependencies": {
49
- "@apidevtools/swagger-parser": "^10.0.2",
50
- "camelcase": "^5.0.0",
51
- "prettier": "^1.19.1",
52
- "ts-morph": "^16.0.0",
53
- "yaml": "^2.1.3",
54
- "yargs": "^17.6.0"
55
- },
56
- "husky": {
57
- "hooks": {
58
- "pre-commit": "lint-staged",
59
- "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true",
60
- "commit-msg": "commitLint -E HUSKY_GIT_PARAMS"
61
- }
62
- },
63
- "lint-staged": {
64
- "*.{js,css,json,md}": [
65
- "prettier --write",
66
- "git add"
67
- ],
68
- "*.ts": [
69
- "eslint --fix",
70
- "prettier --write",
71
- "git add"
72
- ]
73
- },
74
- "config": {
75
- "commitizen": {
76
- "path": "commitiquette"
77
- }
78
- }
79
- }
1
+ {
2
+ "name": "@jmm-devkit/ngx-form-generator",
3
+ "version": "1.2.3",
4
+ "description": "Generates an Angular ReactiveForm from a Swagger or OpenAPI definition",
5
+ "main": "dist/generator-lib.js",
6
+ "repository": "github:jmm-devkit/ngx-form-generator",
7
+ "bin": {
8
+ "ngx-form-generator": "dist/generator-cli.js"
9
+ },
10
+ "scripts": {
11
+ "test": "npm run build && jasmine dist/*.spec.js",
12
+ "build": "tsc --project .\\",
13
+ "lint": "eslint . --ext .ts",
14
+ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md"
15
+ },
16
+ "author": "Martin McWhorter <martin@mcwhorter.org> (https://github.com/martinmcwhorter)",
17
+ "license": "MIT",
18
+ "keywords": [
19
+ "angular",
20
+ "validation",
21
+ "form",
22
+ "reactive-forms",
23
+ "swagger",
24
+ "openapi",
25
+ "typescript"
26
+ ],
27
+ "devDependencies": {
28
+ "@commitlint/cli": "^17.1.2",
29
+ "@commitlint/config-conventional": "^17.0.3",
30
+ "@types/camelcase": "^4.1.0",
31
+ "@types/jasmine": "^4.3.0",
32
+ "@types/node-fetch": "^2.5.5",
33
+ "@types/prettier": "^1.19.1",
34
+ "@types/yaml": "^1.2.0",
35
+ "@types/yargs": "^17.0.13",
36
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
37
+ "@typescript-eslint/parser": "^5.0.0",
38
+ "commitiquette": "^1.2.1",
39
+ "commitizen": "^4.2.4",
40
+ "eslint": "^8.0.1",
41
+ "eslint-config-prettier": "^6.10.1",
42
+ "husky": "^7.0.4",
43
+ "jasmine": "^4.4.0",
44
+ "lint-staged": "^13.0.3",
45
+ "openapi-types": "^7.0.1",
46
+ "typescript": "^4.8.4"
47
+ },
48
+ "dependencies": {
49
+ "@apidevtools/swagger-parser": "^10.0.2",
50
+ "camelcase": "^5.0.0",
51
+ "prettier": "^1.19.1",
52
+ "ts-morph": "^16.0.0",
53
+ "yaml": "^2.1.3",
54
+ "yargs": "^17.6.0"
55
+ },
56
+ "husky": {
57
+ "hooks": {
58
+ "pre-commit": "lint-staged",
59
+ "prepare-commit-msg": "exec < /dev/tty && git cz --hook || true",
60
+ "commit-msg": "commitLint -E HUSKY_GIT_PARAMS"
61
+ }
62
+ },
63
+ "lint-staged": {
64
+ "*.{js,css,json,md}": [
65
+ "prettier --write",
66
+ "git add"
67
+ ],
68
+ "*.ts": [
69
+ "eslint --fix",
70
+ "prettier --write",
71
+ "git add"
72
+ ]
73
+ },
74
+ "config": {
75
+ "commitizen": {
76
+ "path": "commitiquette"
77
+ }
78
+ }
79
+ }