openapi-ts-generator 9.24.2 → 9.31.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/enums/enum-helpers.d.ts +1 -1
- package/enums/enum-helpers.js +6 -9
- package/enums/enum-properties.js +1 -1
- package/enums/enum-value.d.ts +3 -3
- package/generators/barrel.generator.js +13 -34
- package/generators/base.generator.js +16 -18
- package/generators/endpoints.generator.js +23 -63
- package/generators/enum.generator.js +13 -33
- package/generators/form-group-factory.generator.js +59 -48
- package/generators/form.generator.js +14 -33
- package/generators/model-properties.generator.js +15 -33
- package/generators/model.generator.js +14 -34
- package/generators/test-object-factory.generator.js +14 -33
- package/index.js +72 -92
- package/models/entity.d.ts +1 -0
- package/models/enum-value.d.ts +1 -1
- package/models/generator-options.js +19 -21
- package/models/logger.js +6 -9
- package/models/nrsrx-filters.js +3 -4
- package/models/schema-info.d.ts +2 -1
- package/models/schema-info.js +8 -9
- package/openapidoc-converter.d.ts +1 -1
- package/openapidoc-converter.js +183 -186
- package/package.json +24 -23
- package/templates/enum.ts.hbs +16 -0
- package/templates/test-object-factory.ts.hbs +1 -1
package/enums/enum-helpers.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { IEnumValue } from './enum-value';
|
|
|
6
6
|
* @param lookupValue - The value to look up in the enum, which can be a number or a string.
|
|
7
7
|
* @returns The key of the enum value if found, otherwise `undefined`.
|
|
8
8
|
*/
|
|
9
|
-
export declare function getEnumKey(data: IEnumValue[], lookupValue: number | string): number | undefined;
|
|
9
|
+
export declare function getEnumKey(data: IEnumValue[], lookupValue: number | string): number | string | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Retrieves the display text for a given enum value.
|
|
12
12
|
*
|
package/enums/enum-helpers.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getEnumKey = getEnumKey;
|
|
4
|
+
exports.getEnumDisplayText = getEnumDisplayText;
|
|
5
|
+
exports.getEnum = getEnum;
|
|
4
6
|
/**
|
|
5
7
|
* Retrieves the key of an enum value from a list of enum values.
|
|
6
8
|
*
|
|
@@ -9,10 +11,8 @@ exports.getEnum = exports.getEnumDisplayText = exports.getEnumKey = void 0;
|
|
|
9
11
|
* @returns The key of the enum value if found, otherwise `undefined`.
|
|
10
12
|
*/
|
|
11
13
|
function getEnumKey(data, lookupValue) {
|
|
12
|
-
|
|
13
|
-
return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.key;
|
|
14
|
+
return getEnum(data, lookupValue)?.key;
|
|
14
15
|
}
|
|
15
|
-
exports.getEnumKey = getEnumKey;
|
|
16
16
|
/**
|
|
17
17
|
* Retrieves the display text for a given enum value.
|
|
18
18
|
*
|
|
@@ -21,10 +21,8 @@ exports.getEnumKey = getEnumKey;
|
|
|
21
21
|
* @returns The display text associated with the given enum value, or `undefined` if not found.
|
|
22
22
|
*/
|
|
23
23
|
function getEnumDisplayText(data, lookupValue) {
|
|
24
|
-
|
|
25
|
-
return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.displayText;
|
|
24
|
+
return getEnum(data, lookupValue)?.displayText;
|
|
26
25
|
}
|
|
27
|
-
exports.getEnumDisplayText = getEnumDisplayText;
|
|
28
26
|
/**
|
|
29
27
|
* Retrieves an enum value from a list of enum values based on a lookup value.
|
|
30
28
|
*
|
|
@@ -33,6 +31,5 @@ exports.getEnumDisplayText = getEnumDisplayText;
|
|
|
33
31
|
* @returns The matching enum value, or `undefined` if no match is found.
|
|
34
32
|
*/
|
|
35
33
|
function getEnum(data, lookupValue) {
|
|
36
|
-
return data.find(
|
|
34
|
+
return data.find((f) => f.name === lookupValue || f.key === lookupValue);
|
|
37
35
|
}
|
|
38
|
-
exports.getEnum = getEnum;
|
package/enums/enum-properties.js
CHANGED
|
@@ -6,4 +6,4 @@ var EnumProperties;
|
|
|
6
6
|
EnumProperties["KEY"] = "key";
|
|
7
7
|
EnumProperties["NAME"] = "name";
|
|
8
8
|
EnumProperties["DISPLAY_TEXT"] = "displayText";
|
|
9
|
-
})(EnumProperties
|
|
9
|
+
})(EnumProperties || (exports.EnumProperties = EnumProperties = {}));
|
package/enums/enum-value.d.ts
CHANGED
|
@@ -1,39 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.BarrelGenerator = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.barrel) || this;
|
|
27
|
-
_this.GeneratorName = 'BarrelGenerator';
|
|
28
|
-
_this.tsRegex = /.ts$/;
|
|
29
|
-
return _this;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const base_generator_1 = require("./base.generator");
|
|
6
|
+
class BarrelGenerator extends base_generator_1.BaseGenerator {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options, options.templates?.barrel);
|
|
9
|
+
this.GeneratorName = 'BarrelGenerator';
|
|
10
|
+
this.tsRegex = /.ts$/;
|
|
30
11
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return BarrelGenerator;
|
|
38
|
-
}(base_generator_1.BaseGenerator));
|
|
12
|
+
generate() {
|
|
13
|
+
let fileNames = (0, fs_1.readdirSync)(this.generatorOptions.outputPath).map((value) => value.replace(this.tsRegex, ''));
|
|
14
|
+
fileNames = fileNames.filter((x) => x !== 'endpoints');
|
|
15
|
+
return super.generateFile(`${this.generatorOptions.outputPath}/index.ts`, fileNames.length ? { fileNames } : null);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
39
18
|
exports.BarrelGenerator = BarrelGenerator;
|
|
@@ -1,43 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseGenerator = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const handlebars_1 = require("handlebars");
|
|
6
|
+
class BaseGenerator {
|
|
7
|
+
constructor(generatorOptions, templateFilePath) {
|
|
8
8
|
this.generatorOptions = generatorOptions;
|
|
9
9
|
this.templateFilePath = templateFilePath;
|
|
10
10
|
this.emptyArrayRegex = /, ]/g;
|
|
11
11
|
if (templateFilePath) {
|
|
12
|
-
|
|
12
|
+
const templateSource = (0, fs_1.readFileSync)(templateFilePath, { encoding: 'utf8' });
|
|
13
13
|
this.template = (0, handlebars_1.compile)(templateSource);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
16
|
+
generateFile(outputFilePath, context) {
|
|
18
17
|
if (!this.template) {
|
|
19
|
-
|
|
18
|
+
this.generatorOptions.logger?.warn(`Template for ${this.GeneratorName} has not been specified.`);
|
|
20
19
|
}
|
|
21
20
|
else if (!context) {
|
|
22
|
-
|
|
21
|
+
this.generatorOptions.logger?.warn(`Context for ${this.GeneratorName} has not been provided.`);
|
|
23
22
|
}
|
|
24
23
|
else {
|
|
25
24
|
try {
|
|
26
|
-
|
|
25
|
+
const content = this.template(context).replace(this.emptyArrayRegex, ']');
|
|
27
26
|
(0, fs_1.writeFileSync)(outputFilePath, content, { encoding: 'utf8' });
|
|
28
27
|
return content;
|
|
29
28
|
}
|
|
30
29
|
catch (err) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
this.generatorOptions.logger?.error(`Error executing template: ${this.templateFilePath ?? 'undefined'}.`);
|
|
31
|
+
this.generatorOptions.logger?.error(`This is likely an issue with the template.`);
|
|
32
|
+
this.generatorOptions.logger?.error(`Data: ${JSON.stringify(context)}`);
|
|
33
|
+
this.generatorOptions.logger?.error(`Goto: https://github.com/ikemtz/openapi-ts-generator to report an issue if necessary.`);
|
|
34
|
+
this.generatorOptions.logger?.error(JSON.stringify(err));
|
|
36
35
|
throw err;
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
return null;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
43
41
|
exports.BaseGenerator = BaseGenerator;
|
|
@@ -1,75 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
-
if (ar || !(i in from)) {
|
|
31
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
-
ar[i] = from[i];
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
-
};
|
|
37
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
3
|
exports.EndPointsGenerator = void 0;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
4
|
+
const base_generator_1 = require("./base.generator");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
class EndPointsGenerator extends base_generator_1.BaseGenerator {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options, options.templates?.endpoints);
|
|
9
|
+
this.GeneratorName = 'EndPointsGenerator';
|
|
10
|
+
this.endpointIdentifierRegex = /[A-z0-9_-]*$/;
|
|
11
|
+
}
|
|
12
|
+
generate(templateData) {
|
|
13
|
+
const paths = this.eliminateDupes(templateData);
|
|
14
|
+
return super.generateFile(`${this.generatorOptions.outputPath}/endpoints.ts`, { paths });
|
|
50
15
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var sortedTemplateData = __spreadArray([], templateData.paths, true).sort(function (x, y) { return (x.endpoint.toUpperCase() < y.endpoint.toUpperCase() ? -1 : 1); });
|
|
58
|
-
var result = [];
|
|
59
|
-
sortedTemplateData.forEach(function (val) {
|
|
60
|
-
val = __assign(__assign({}, val), { tag: _.camelCase(val.tag) });
|
|
61
|
-
var dupeIndex = result.findIndex(function (f) { return f.tag === val.tag; });
|
|
16
|
+
eliminateDupes(templateData) {
|
|
17
|
+
const sortedTemplateData = [...templateData.paths].sort((x, y) => (x.endpoint.toUpperCase() < y.endpoint.toUpperCase() ? -1 : 1));
|
|
18
|
+
const result = [];
|
|
19
|
+
sortedTemplateData.forEach((val) => {
|
|
20
|
+
val = { ...val, tag: (0, lodash_1.camelCase)(val.tag) };
|
|
21
|
+
const dupeIndex = result.findIndex((f) => f.tag === val.tag);
|
|
62
22
|
if (dupeIndex > -1) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
23
|
+
const dupeCount = result.filter((f) => f.tag === val.tag).length + 1;
|
|
24
|
+
const endpointIdentifier = (this.endpointIdentifierRegex.exec(val.endpoint) || [])[0];
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
26
|
+
result.push({ ...val, tag: (0, lodash_1.camelCase)(`${val.tag}_${endpointIdentifier || dupeCount}`) });
|
|
66
27
|
}
|
|
67
28
|
else {
|
|
68
29
|
result.push(val);
|
|
69
30
|
}
|
|
70
31
|
});
|
|
71
32
|
return result;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
}(base_generator_1.BaseGenerator));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
75
35
|
exports.EndPointsGenerator = EndPointsGenerator;
|
|
@@ -1,39 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.EnumGenerator = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var _a;
|
|
26
|
-
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.enum) || this;
|
|
27
|
-
_this.GeneratorName = 'EnumGenerator';
|
|
28
|
-
return _this;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const base_generator_1 = require("./base.generator");
|
|
6
|
+
class EnumGenerator extends base_generator_1.BaseGenerator {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
super(options, options.templates?.enum);
|
|
9
|
+
this.GeneratorName = 'EnumGenerator';
|
|
29
10
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
generate(templateData) {
|
|
12
|
+
templateData.entities
|
|
13
|
+
?.filter((entity) => entity.isEnum)
|
|
14
|
+
.forEach((entity) => {
|
|
15
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${(0, lodash_1.kebabCase)(entity.name)}.enum.ts`, entity);
|
|
35
16
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}(base_generator_1.BaseGenerator));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
39
19
|
exports.EnumGenerator = EnumGenerator;
|
|
@@ -1,42 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
8
26
|
};
|
|
9
|
-
return function (
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
15
33
|
};
|
|
16
34
|
})();
|
|
17
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
36
|
exports.FormGroupFactoryGenerator = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.formGroupFactory) || this;
|
|
28
|
-
_this.GeneratorName = 'FormGroupFactoryGenerator';
|
|
29
|
-
return _this;
|
|
37
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
38
|
+
const lodash_1 = require("lodash");
|
|
39
|
+
const base_generator_1 = require("./base.generator");
|
|
40
|
+
const HandleBars = __importStar(require("handlebars"));
|
|
41
|
+
class FormGroupFactoryGenerator extends base_generator_1.BaseGenerator {
|
|
42
|
+
constructor(options) {
|
|
43
|
+
super(options, options.templates?.formGroupFactory);
|
|
44
|
+
this.GeneratorName = 'FormGroupFactoryGenerator';
|
|
30
45
|
}
|
|
31
|
-
|
|
32
|
-
var _this = this;
|
|
33
|
-
var _a;
|
|
46
|
+
generate(templateData) {
|
|
34
47
|
this.registerHelpers();
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
templateData.entities
|
|
49
|
+
?.filter((val) => val.valueProperties?.length + val.referenceProperties?.length > 0)
|
|
50
|
+
.forEach((entity) => {
|
|
51
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${(0, lodash_1.kebabCase)(entity.name)}.form-group-fac.ts`, entity);
|
|
37
52
|
});
|
|
38
|
-
}
|
|
39
|
-
|
|
53
|
+
}
|
|
54
|
+
registerHelpers() {
|
|
40
55
|
this.registerValidatorHelper('minimum', 'min');
|
|
41
56
|
this.registerValidatorHelper('maximum', 'max');
|
|
42
57
|
this.registerValidatorHelper('minLength');
|
|
@@ -44,25 +59,21 @@ var FormGroupFactoryGenerator = /** @class */ (function (_super) {
|
|
|
44
59
|
this.registerValidatorHelper('maxItems', 'maxLength');
|
|
45
60
|
this.registerValidatorHelper('minItems', 'minLength');
|
|
46
61
|
this.registerValidatorHelper('pattern');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
FormGroupFactoryGenerator.prototype.validatorFactory = function (propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
|
|
56
|
-
var props = propertyContext.data.root[propertyCollection];
|
|
57
|
-
var prop = props[propertyContext.data.index];
|
|
58
|
-
var value = prop[validationName];
|
|
62
|
+
}
|
|
63
|
+
registerValidatorHelper(validatorName, angularValidatorName = validatorName) {
|
|
64
|
+
HandleBars.registerHelper(`${validatorName}Validator`, (x, y) => this.validatorFactory(x, y, validatorName, angularValidatorName));
|
|
65
|
+
}
|
|
66
|
+
validatorFactory(propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
|
|
67
|
+
const props = propertyContext.data.root[propertyCollection];
|
|
68
|
+
const prop = props[propertyContext.data.index];
|
|
69
|
+
let value = prop[validationName];
|
|
59
70
|
if (value !== undefined && value !== null) {
|
|
60
|
-
|
|
61
|
-
value = typeof value === 'string' ?
|
|
62
|
-
|
|
71
|
+
const hasMultipleValidators = prop.hasMultipleValidators;
|
|
72
|
+
value = typeof value === 'string' ? `'${value}'` : value;
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
74
|
+
return `Validators.${angularValidatorFunctionName}(${value})${hasMultipleValidators ? ', ' : ''}`;
|
|
63
75
|
}
|
|
64
76
|
return '';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}(base_generator_1.BaseGenerator));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
68
79
|
exports.FormGroupFactoryGenerator = FormGroupFactoryGenerator;
|
|
@@ -1,39 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.FormGenerator = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.form) || this;
|
|
27
|
-
_this.GeneratorName = 'FormGenerator';
|
|
28
|
-
return _this;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const base_generator_1 = require("./base.generator");
|
|
7
|
+
class FormGenerator extends base_generator_1.BaseGenerator {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options, options.templates?.form);
|
|
10
|
+
this.GeneratorName = 'FormGenerator';
|
|
29
11
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
generate(templateData) {
|
|
13
|
+
templateData.entities
|
|
14
|
+
?.filter((val) => val.valueProperties?.length + val.referenceProperties?.length > 0)
|
|
15
|
+
.forEach((entity) => {
|
|
16
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${(0, lodash_1.kebabCase)(entity.name)}.form.ts`, entity);
|
|
35
17
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}(base_generator_1.BaseGenerator));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
39
20
|
exports.FormGenerator = FormGenerator;
|
|
@@ -1,39 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.ModelPropertiesGenerator = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.modelProperties) || this;
|
|
27
|
-
_this.GeneratorName = 'ModelPropertiesGenerator';
|
|
28
|
-
return _this;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const base_generator_1 = require("./base.generator");
|
|
7
|
+
class ModelPropertiesGenerator extends base_generator_1.BaseGenerator {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options, options.templates?.modelProperties);
|
|
10
|
+
this.GeneratorName = 'ModelPropertiesGenerator';
|
|
29
11
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
generate(templateData) {
|
|
13
|
+
templateData.entities
|
|
14
|
+
?.filter((entity) => !entity.isEnum)
|
|
15
|
+
.filter((val) => val.valueProperties?.length > 0 || val.referenceProperties?.length > 0)
|
|
16
|
+
.forEach((entity) => {
|
|
17
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${(0, lodash_1.kebabCase)(entity.name)}.properties.ts`, entity);
|
|
35
18
|
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
}(base_generator_1.BaseGenerator));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
39
21
|
exports.ModelPropertiesGenerator = ModelPropertiesGenerator;
|