openapi-ts-generator 4.192.6 → 5.52.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.
- package/README.md +1 -1
- package/generators/{barrel-generator.d.ts → barrel.generator.d.ts} +1 -1
- package/generators/{barrel-generator.js → barrel.generator.js} +2 -2
- package/generators/{base-generator.d.ts → base.generator.d.ts} +1 -1
- package/generators/{base-generator.js → base.generator.js} +13 -10
- package/generators/{endpoints-generator.d.ts → endpoints.generator.d.ts} +1 -1
- package/generators/{endpoints-generator.js → endpoints.generator.js} +1 -1
- package/generators/{enum-generator.d.ts → enum.generator.d.ts} +3 -2
- package/generators/{enum-generator.js → enum.generator.js} +1 -1
- package/generators/{form-group-generator.d.ts → form-group-factory.generator.d.ts} +6 -4
- package/generators/{form-group-generator.js → form-group-factory.generator.js} +24 -22
- package/generators/form.generator.d.ts +9 -0
- package/generators/form.generator.js +39 -0
- package/generators/index.d.ts +8 -5
- package/generators/index.js +8 -5
- package/generators/{model-properties-generator.d.ts → model-properties.generator.d.ts} +3 -2
- package/generators/{model-properties-generator.js → model-properties.generator.js} +1 -1
- package/generators/{model-generator.d.ts → model.generator.d.ts} +3 -2
- package/generators/{model-generator.js → model.generator.js} +5 -4
- package/generators/test-object-factory.generator.d.ts +9 -0
- package/generators/test-object-factory.generator.js +39 -0
- package/index.js +7 -4
- package/models/entity.d.ts +16 -0
- package/models/entity.js +2 -0
- package/models/enum-value.d.ts +6 -0
- package/models/enum-value.js +2 -0
- package/models/generator-options.d.ts +10 -2
- package/models/generator-options.js +3 -3
- package/models/helper-context.d.ts +1 -1
- package/models/nrsrx-filters.d.ts +2 -1
- package/models/reference-property.d.ts +20 -0
- package/models/reference-property.js +2 -0
- package/models/schema-info.d.ts +4 -6
- package/models/template-data.d.ts +4 -36
- package/models/value-property.d.ts +21 -0
- package/models/value-property.js +2 -0
- package/openapidoc-converter.d.ts +13 -7
- package/openapidoc-converter.js +169 -39
- package/package.json +7 -6
- package/templates/entity.ts.hbs +30 -0
- package/templates/enum.ts.hbs +17 -2
- package/templates/form-group-factory.ts.hbs +24 -11
- package/templates/form.ts.hbs +30 -0
- package/templates/index.ts.hbs +1 -1
- package/templates/model.ts.hbs +8 -4
- package/templates/test-object-factory.ts.hbs +17 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://ikemtz.visualstudio.com/CI%20CD/_build/latest?definitionId=20&branchName=master) [](https://www.npmjs.com/package/openapi-ts-generator) [](https://www.npmjs.com/package/openapi-ts-generator) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://github.com/ikemtz/openapi-ts-generator/issues) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator)
|
|
1
|
+
[](https://ikemtz.visualstudio.com/CI%20CD/_build/latest?definitionId=20&branchName=master) [](https://www.npmjs.com/package/openapi-ts-generator) [](https://www.npmjs.com/package/openapi-ts-generator) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://github.com/ikemtz/openapi-ts-generator/issues) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [](https://github.com/ikemtz/openapi-ts-generator/actions/workflows/codeql-analysis.yml)
|
|
2
2
|
|
|
3
3
|
# OpenApi-TS-Generator
|
|
4
4
|
|
|
@@ -17,7 +17,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.BarrelGenerator = void 0;
|
|
19
19
|
var fs_1 = require("fs");
|
|
20
|
-
var base_generator_1 = require("./base
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
21
|
var BarrelGenerator = /** @class */ (function (_super) {
|
|
22
22
|
__extends(BarrelGenerator, _super);
|
|
23
23
|
function BarrelGenerator(options) {
|
|
@@ -32,7 +32,7 @@ var BarrelGenerator = /** @class */ (function (_super) {
|
|
|
32
32
|
var _this = this;
|
|
33
33
|
var fileNames = (0, fs_1.readdirSync)(this.generatorOptions.outputPath).map(function (value) { return value.replace(_this.tsRegex, ''); });
|
|
34
34
|
fileNames = fileNames.filter(function (x) { return x !== 'endpoints'; });
|
|
35
|
-
return _super.prototype.generateFile.call(this, "".concat(this.generatorOptions.outputPath, "/index.ts"), { fileNames: fileNames });
|
|
35
|
+
return _super.prototype.generateFile.call(this, "".concat(this.generatorOptions.outputPath, "/index.ts"), fileNames.length ? { fileNames: fileNames } : null);
|
|
36
36
|
};
|
|
37
37
|
return BarrelGenerator;
|
|
38
38
|
}(base_generator_1.BaseGenerator));
|
|
@@ -6,5 +6,5 @@ export declare abstract class BaseGenerator<TContextSchema> {
|
|
|
6
6
|
readonly template?: HandlebarsTemplateDelegate<TContextSchema>;
|
|
7
7
|
readonly emptyArrayRegex: RegExp;
|
|
8
8
|
constructor(generatorOptions: IGeneratorOptions, templateFilePath: string | undefined);
|
|
9
|
-
protected generateFile(outputFilePath: string, context: TContextSchema): string | null;
|
|
9
|
+
protected generateFile(outputFilePath: string, context: TContextSchema | null): string | null;
|
|
10
10
|
}
|
|
@@ -14,25 +14,28 @@ var BaseGenerator = /** @class */ (function () {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
BaseGenerator.prototype.generateFile = function (outputFilePath, context) {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
|
-
if (this.template) {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
18
|
+
if (!this.template) {
|
|
19
|
+
(_a = this.generatorOptions.logger) === null || _a === void 0 ? void 0 : _a.warn("Template for ".concat(this.GeneratorName, " has not been specified."));
|
|
20
|
+
}
|
|
21
|
+
else if (!context) {
|
|
22
|
+
(_b = this.generatorOptions.logger) === null || _b === void 0 ? void 0 : _b.warn("Context for ".concat(this.GeneratorName, " has not been provided."));
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
19
25
|
try {
|
|
20
26
|
var content = this.template(context).replace(this.emptyArrayRegex, ']');
|
|
21
27
|
(0, fs_1.writeFileSync)(outputFilePath, content, { encoding: 'utf8' });
|
|
22
28
|
return content;
|
|
23
29
|
}
|
|
24
30
|
catch (err) {
|
|
25
|
-
(
|
|
26
|
-
(
|
|
27
|
-
(
|
|
28
|
-
(
|
|
29
|
-
(
|
|
31
|
+
(_c = this.generatorOptions.logger) === null || _c === void 0 ? void 0 : _c.error("Error executing template: ".concat((_d = this.templateFilePath) !== null && _d !== void 0 ? _d : 'undefined', "."));
|
|
32
|
+
(_e = this.generatorOptions.logger) === null || _e === void 0 ? void 0 : _e.error("This is likely an issue with the template.");
|
|
33
|
+
(_f = this.generatorOptions.logger) === null || _f === void 0 ? void 0 : _f.error("Data: ".concat(JSON.stringify(context)));
|
|
34
|
+
(_g = this.generatorOptions.logger) === null || _g === void 0 ? void 0 : _g.error("Goto: https://github.com/ikemtz/openapi-ts-generator to report an issue if necessary.");
|
|
35
|
+
(_h = this.generatorOptions.logger) === null || _h === void 0 ? void 0 : _h.error(JSON.stringify(err));
|
|
30
36
|
throw err;
|
|
31
37
|
}
|
|
32
38
|
}
|
|
33
|
-
else {
|
|
34
|
-
(_g = this.generatorOptions.logger) === null || _g === void 0 ? void 0 : _g.warn("Template for ".concat(this.GeneratorName, " has not been specified"));
|
|
35
|
-
}
|
|
36
39
|
return null;
|
|
37
40
|
};
|
|
38
41
|
return BaseGenerator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
2
|
import { IPath, ITemplateData } from '../models/template-data';
|
|
3
|
-
import { BaseGenerator } from './base
|
|
3
|
+
import { BaseGenerator } from './base.generator';
|
|
4
4
|
export declare class EndPointsGenerator extends BaseGenerator<{
|
|
5
5
|
paths: IPath[];
|
|
6
6
|
}> {
|
|
@@ -36,7 +36,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.EndPointsGenerator = void 0;
|
|
39
|
-
var base_generator_1 = require("./base
|
|
39
|
+
var base_generator_1 = require("./base.generator");
|
|
40
40
|
var _ = require("lodash");
|
|
41
41
|
var EndPointsGenerator = /** @class */ (function (_super) {
|
|
42
42
|
__extends(EndPointsGenerator, _super);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ITemplateData } from '../models/template-data';
|
|
3
|
+
import { IEntity } from '../models/entity';
|
|
4
|
+
import { BaseGenerator } from './base.generator';
|
|
4
5
|
export declare class EnumGenerator extends BaseGenerator<IEntity> {
|
|
5
6
|
readonly GeneratorName = "EnumGenerator";
|
|
6
7
|
constructor(options: IGeneratorOptions);
|
|
@@ -17,7 +17,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.EnumGenerator = void 0;
|
|
19
19
|
var _ = require("lodash");
|
|
20
|
-
var base_generator_1 = require("./base
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
21
|
var EnumGenerator = /** @class */ (function (_super) {
|
|
22
22
|
__extends(EnumGenerator, _super);
|
|
23
23
|
function EnumGenerator(options) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ITemplateData } from '../models/template-data';
|
|
3
|
+
import { IEntity } from '../models/entity';
|
|
4
|
+
import { BaseGenerator } from './base.generator';
|
|
4
5
|
import { IHelperContext, PropertyType } from '../models/helper-context';
|
|
5
|
-
export declare class
|
|
6
|
-
readonly GeneratorName = "
|
|
6
|
+
export declare class FormGroupFactoryGenerator extends BaseGenerator<IEntity> {
|
|
7
|
+
readonly GeneratorName = "FormGroupFactoryGenerator";
|
|
7
8
|
constructor(options: IGeneratorOptions);
|
|
8
9
|
generate(templateData: ITemplateData): void;
|
|
9
10
|
registerHelpers(): void;
|
|
11
|
+
registerValidatorHelper(validatorName: string, angularValidatorName?: string): void;
|
|
10
12
|
validatorFactory(propertyCollection: PropertyType, propertyContext: IHelperContext, validationName: string, angularValidatorFunctionName: string): string;
|
|
11
13
|
}
|
|
@@ -15,20 +15,20 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
18
|
+
exports.FormGroupFactoryGenerator = void 0;
|
|
19
19
|
var _ = require("lodash");
|
|
20
|
-
var base_generator_1 = require("./base
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
21
|
var HandleBars = require("handlebars");
|
|
22
|
-
var
|
|
23
|
-
__extends(
|
|
24
|
-
function
|
|
22
|
+
var FormGroupFactoryGenerator = /** @class */ (function (_super) {
|
|
23
|
+
__extends(FormGroupFactoryGenerator, _super);
|
|
24
|
+
function FormGroupFactoryGenerator(options) {
|
|
25
25
|
var _this = this;
|
|
26
26
|
var _a;
|
|
27
27
|
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.formGroupFactory) || this;
|
|
28
|
-
_this.GeneratorName = '
|
|
28
|
+
_this.GeneratorName = 'FormGroupFactoryGenerator';
|
|
29
29
|
return _this;
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
FormGroupFactoryGenerator.prototype.generate = function (templateData) {
|
|
32
32
|
var _this = this;
|
|
33
33
|
var _a;
|
|
34
34
|
this.registerHelpers();
|
|
@@ -36,31 +36,33 @@ var FormGroupGenerator = /** @class */ (function (_super) {
|
|
|
36
36
|
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".form-group-fac.ts"), entity);
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
FormGroupFactoryGenerator.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
|
+
FormGroupFactoryGenerator.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
|
+
FormGroupFactoryGenerator.prototype.validatorFactory = function (propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
|
|
54
56
|
var props = propertyContext.data.root[propertyCollection];
|
|
55
57
|
var prop = props[propertyContext.data.index];
|
|
56
58
|
var value = prop[validationName];
|
|
57
59
|
if (value !== undefined && value !== null) {
|
|
58
60
|
var hasMultipleValidators = prop.hasMultipleValidators;
|
|
59
61
|
value = typeof value === 'string' ? "'".concat(value, "'") : value;
|
|
60
|
-
return "
|
|
62
|
+
return "Validators.".concat(angularValidatorFunctionName, "(").concat(value, ")").concat(hasMultipleValidators ? ', ' : '');
|
|
61
63
|
}
|
|
62
64
|
return '';
|
|
63
65
|
};
|
|
64
|
-
return
|
|
66
|
+
return FormGroupFactoryGenerator;
|
|
65
67
|
}(base_generator_1.BaseGenerator));
|
|
66
|
-
exports.
|
|
68
|
+
exports.FormGroupFactoryGenerator = FormGroupFactoryGenerator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
+
import { ITemplateData } from '../models/template-data';
|
|
3
|
+
import { IEntity } from '../models/entity';
|
|
4
|
+
import { BaseGenerator } from './base.generator';
|
|
5
|
+
export declare class FormGenerator extends BaseGenerator<IEntity> {
|
|
6
|
+
readonly GeneratorName = "FormGenerator";
|
|
7
|
+
constructor(options: IGeneratorOptions);
|
|
8
|
+
generate(templateData: ITemplateData): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.FormGenerator = void 0;
|
|
19
|
+
var _ = require("lodash");
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
|
+
var FormGenerator = /** @class */ (function (_super) {
|
|
22
|
+
__extends(FormGenerator, _super);
|
|
23
|
+
function FormGenerator(options) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
var _a;
|
|
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;
|
|
29
|
+
}
|
|
30
|
+
FormGenerator.prototype.generate = function (templateData) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = templateData.entities) === null || _a === void 0 ? void 0 : _a.filter(function (val) { var _a, _b; return ((_a = val.valueProperties) === null || _a === void 0 ? void 0 : _a.length) + ((_b = val.referenceProperties) === null || _b === void 0 ? void 0 : _b.length) > 0; }).forEach(function (entity) {
|
|
34
|
+
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".form.ts"), entity);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return FormGenerator;
|
|
38
|
+
}(base_generator_1.BaseGenerator));
|
|
39
|
+
exports.FormGenerator = FormGenerator;
|
package/generators/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from './model
|
|
2
|
-
export * from './form-group-generator';
|
|
3
|
-
export * from './model-properties
|
|
4
|
-
export * from './barrel
|
|
5
|
-
export * from './enum
|
|
1
|
+
export * from './model.generator';
|
|
2
|
+
export * from './form-group-factory.generator';
|
|
3
|
+
export * from './model-properties.generator';
|
|
4
|
+
export * from './barrel.generator';
|
|
5
|
+
export * from './enum.generator';
|
|
6
|
+
export * from './form.generator';
|
|
7
|
+
export * from './test-object-factory.generator';
|
|
8
|
+
export * from './endpoints.generator';
|
package/generators/index.js
CHANGED
|
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./model
|
|
18
|
-
__exportStar(require("./form-group-generator"), exports);
|
|
19
|
-
__exportStar(require("./model-properties
|
|
20
|
-
__exportStar(require("./barrel
|
|
21
|
-
__exportStar(require("./enum
|
|
17
|
+
__exportStar(require("./model.generator"), exports);
|
|
18
|
+
__exportStar(require("./form-group-factory.generator"), exports);
|
|
19
|
+
__exportStar(require("./model-properties.generator"), exports);
|
|
20
|
+
__exportStar(require("./barrel.generator"), exports);
|
|
21
|
+
__exportStar(require("./enum.generator"), exports);
|
|
22
|
+
__exportStar(require("./form.generator"), exports);
|
|
23
|
+
__exportStar(require("./test-object-factory.generator"), exports);
|
|
24
|
+
__exportStar(require("./endpoints.generator"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ITemplateData } from '../models/template-data';
|
|
3
|
+
import { IEntity } from '../models/entity';
|
|
4
|
+
import { BaseGenerator } from './base.generator';
|
|
4
5
|
export declare class ModelPropertiesGenerator extends BaseGenerator<IEntity> {
|
|
5
6
|
readonly GeneratorName = "ModelPropertiesGenerator";
|
|
6
7
|
constructor(options: IGeneratorOptions);
|
|
@@ -17,7 +17,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ModelPropertiesGenerator = void 0;
|
|
19
19
|
var _ = require("lodash");
|
|
20
|
-
var base_generator_1 = require("./base
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
21
|
var ModelPropertiesGenerator = /** @class */ (function (_super) {
|
|
22
22
|
__extends(ModelPropertiesGenerator, _super);
|
|
23
23
|
function ModelPropertiesGenerator(options) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { ITemplateData } from '../models/template-data';
|
|
3
|
+
import { IEntity } from '../models/entity';
|
|
4
|
+
import { BaseGenerator } from './base.generator';
|
|
4
5
|
export declare class ModelGenerator extends BaseGenerator<IEntity> {
|
|
5
6
|
readonly GeneratorName = "ModelGenerator";
|
|
6
7
|
constructor(options: IGeneratorOptions);
|
|
@@ -17,21 +17,22 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ModelGenerator = void 0;
|
|
19
19
|
var _ = require("lodash");
|
|
20
|
-
var base_generator_1 = require("./base
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
21
|
var ModelGenerator = /** @class */ (function (_super) {
|
|
22
22
|
__extends(ModelGenerator, _super);
|
|
23
23
|
function ModelGenerator(options) {
|
|
24
24
|
var _this = this;
|
|
25
|
-
var _a;
|
|
26
|
-
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.model) || this;
|
|
25
|
+
var _a, _b;
|
|
26
|
+
_this = _super.call(this, options, options.genClasses ? (_a = options.templates) === null || _a === void 0 ? void 0 : _a.entity : (_b = options.templates) === null || _b === void 0 ? void 0 : _b.model) || this;
|
|
27
27
|
_this.GeneratorName = 'ModelGenerator';
|
|
28
28
|
return _this;
|
|
29
29
|
}
|
|
30
30
|
ModelGenerator.prototype.generate = function (templateData) {
|
|
31
31
|
var _this = this;
|
|
32
32
|
var _a;
|
|
33
|
+
var fileSuffix = this.generatorOptions.genClasses ? '.entity.ts' : '.model.ts';
|
|
33
34
|
(_a = templateData.entities) === null || _a === void 0 ? void 0 : _a.filter(function (entity) { return !entity.isEnum; }).forEach(function (entity) {
|
|
34
|
-
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name)
|
|
35
|
+
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name)).concat(fileSuffix), entity);
|
|
35
36
|
});
|
|
36
37
|
};
|
|
37
38
|
return ModelGenerator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
+
import { ITemplateData } from '../models/template-data';
|
|
3
|
+
import { IEntity } from '../models/entity';
|
|
4
|
+
import { BaseGenerator } from './base.generator';
|
|
5
|
+
export declare class TestObjectFactoryGenerator extends BaseGenerator<IEntity> {
|
|
6
|
+
readonly GeneratorName = "TestObjectFactoryGenerator";
|
|
7
|
+
constructor(options: IGeneratorOptions);
|
|
8
|
+
generate(templateData: ITemplateData): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.TestObjectFactoryGenerator = void 0;
|
|
19
|
+
var _ = require("lodash");
|
|
20
|
+
var base_generator_1 = require("./base.generator");
|
|
21
|
+
var TestObjectFactoryGenerator = /** @class */ (function (_super) {
|
|
22
|
+
__extends(TestObjectFactoryGenerator, _super);
|
|
23
|
+
function TestObjectFactoryGenerator(options) {
|
|
24
|
+
var _this = this;
|
|
25
|
+
var _a;
|
|
26
|
+
_this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.testObjectFactory) || this;
|
|
27
|
+
_this.GeneratorName = 'TestObjectFactoryGenerator';
|
|
28
|
+
return _this;
|
|
29
|
+
}
|
|
30
|
+
TestObjectFactoryGenerator.prototype.generate = function (templateData) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
var _a;
|
|
33
|
+
(_a = templateData.entities) === null || _a === void 0 ? void 0 : _a.filter(function (val) { var _a, _b; return ((_a = val.valueProperties) === null || _a === void 0 ? void 0 : _a.length) + ((_b = val.referenceProperties) === null || _b === void 0 ? void 0 : _b.length) > 0; }).forEach(function (entity) {
|
|
34
|
+
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".test-obj-fac.ts"), entity);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
return TestObjectFactoryGenerator;
|
|
38
|
+
}(base_generator_1.BaseGenerator));
|
|
39
|
+
exports.TestObjectFactoryGenerator = TestObjectFactoryGenerator;
|
package/index.js
CHANGED
|
@@ -39,7 +39,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.generateTsModels = exports.nrsrxValuePropertyTypeFilterCallBack = exports.nrsrxTypeFilterCallBack = void 0;
|
|
40
40
|
var fs = require("fs");
|
|
41
41
|
var generators_1 = require("./generators");
|
|
42
|
-
var endpoints_generator_1 = require("./generators/endpoints-generator");
|
|
43
42
|
var generator_options_1 = require("./models/generator-options");
|
|
44
43
|
var openapidoc_converter_1 = require("./openapidoc-converter");
|
|
45
44
|
var axios_1 = require("axios");
|
|
@@ -72,7 +71,7 @@ function getOpenApiDocumentAsync(options) {
|
|
|
72
71
|
switch (_a.label) {
|
|
73
72
|
case 0:
|
|
74
73
|
if (!options.openApiJsonUrl) return [3 /*break*/, 2];
|
|
75
|
-
return [4 /*yield*/, axios_1.default.get(options.openApiJsonUrl)];
|
|
74
|
+
return [4 /*yield*/, axios_1.default.get(options.openApiJsonUrl, options.axiosConfig)];
|
|
76
75
|
case 1:
|
|
77
76
|
response = _a.sent();
|
|
78
77
|
apiDoc = response.data;
|
|
@@ -100,15 +99,19 @@ function generateOutput(options, templateData) {
|
|
|
100
99
|
var modelGenerator = new generators_1.ModelGenerator(options);
|
|
101
100
|
modelGenerator.generate(templateData);
|
|
102
101
|
if (options.genAngularFormGroups) {
|
|
103
|
-
var formGroupGenerator = new generators_1.
|
|
102
|
+
var formGroupGenerator = new generators_1.FormGroupFactoryGenerator(options);
|
|
104
103
|
formGroupGenerator.generate(templateData);
|
|
104
|
+
var formGenerator = new generators_1.FormGenerator(options);
|
|
105
|
+
formGenerator.generate(templateData);
|
|
105
106
|
}
|
|
106
107
|
var modelPropertiesGenerator = new generators_1.ModelPropertiesGenerator(options);
|
|
107
108
|
modelPropertiesGenerator.generate(templateData);
|
|
108
|
-
var endpointGenerator = new
|
|
109
|
+
var endpointGenerator = new generators_1.EndPointsGenerator(options);
|
|
109
110
|
endpointGenerator.generate(templateData);
|
|
110
111
|
var barrelGenerator = new generators_1.BarrelGenerator(options);
|
|
111
112
|
var enumGenerator = new generators_1.EnumGenerator(options);
|
|
112
113
|
enumGenerator.generate(templateData);
|
|
114
|
+
var testObjFacGenerator = new generators_1.TestObjectFactoryGenerator(options);
|
|
115
|
+
testObjFacGenerator.generate(templateData);
|
|
113
116
|
barrelGenerator.generate();
|
|
114
117
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IReferenceProperty } from './reference-property';
|
|
2
|
+
import { IValueProperty } from './value-property';
|
|
3
|
+
import { IImportType } from './template-data';
|
|
4
|
+
import { IEnumValue } from './enum-value';
|
|
5
|
+
export interface IEntity {
|
|
6
|
+
isEnum?: boolean;
|
|
7
|
+
enumValues: (string | IEnumValue)[];
|
|
8
|
+
name: string;
|
|
9
|
+
kebabCasedName: string;
|
|
10
|
+
camelSingularName: string;
|
|
11
|
+
singularName: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
importTypes: IImportType[];
|
|
14
|
+
valueProperties: IValueProperty[];
|
|
15
|
+
referenceProperties: IReferenceProperty[];
|
|
16
|
+
}
|
package/models/entity.js
ADDED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { ILogger } from './logger';
|
|
2
|
-
import { IEntity
|
|
2
|
+
import { IEntity } from './entity';
|
|
3
|
+
import { IReferenceProperty } from './reference-property';
|
|
4
|
+
import { IValueProperty } from './value-property';
|
|
5
|
+
import { AxiosRequestConfig } from 'axios';
|
|
3
6
|
export interface IGeneratorOptions {
|
|
4
7
|
logger?: ILogger;
|
|
5
8
|
outputPath: string;
|
|
6
9
|
openApiJsonUrl?: string;
|
|
7
10
|
openApiJsonFileName?: string;
|
|
8
11
|
genAngularFormGroups?: boolean;
|
|
12
|
+
genClasses?: boolean;
|
|
9
13
|
typeFilterCallBack?: (entity: IEntity, index: number, array: IEntity[]) => boolean;
|
|
10
14
|
valuePropertyTypeFilterCallBack?: (valueProperty: IValueProperty, index: number, array: IValueProperty[]) => boolean;
|
|
11
15
|
referencePropertyTypeFilterCallBack?: (referenceProperty: IReferenceProperty, index: number, array: IReferenceProperty[]) => boolean;
|
|
12
16
|
pathUrlFormattingCallBack?: (url: string) => string;
|
|
13
17
|
templates?: ITemplates | null;
|
|
18
|
+
axiosConfig?: AxiosRequestConfig<any>;
|
|
14
19
|
}
|
|
15
20
|
export interface ITemplates {
|
|
16
21
|
model?: string;
|
|
22
|
+
entity?: string;
|
|
23
|
+
testObjectFactory?: string;
|
|
24
|
+
form?: string;
|
|
17
25
|
formGroupFactory?: string;
|
|
18
26
|
modelProperties?: string;
|
|
19
27
|
barrel?: string;
|
|
20
28
|
enum?: string;
|
|
21
29
|
endpoints?: string;
|
|
22
30
|
}
|
|
23
|
-
export declare function defaultFilter(
|
|
31
|
+
export declare function defaultFilter(_value: IEntity | IValueProperty | IReferenceProperty, _index: number, _array: IEntity[] | IValueProperty[] | IReferenceProperty[]): boolean;
|
|
24
32
|
export declare function setGeneratorOptionDefaults(options: IGeneratorOptions): IGeneratorOptions;
|
|
@@ -14,17 +14,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.setGeneratorOptionDefaults = exports.defaultFilter = void 0;
|
|
15
15
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
16
16
|
var path_1 = require("path");
|
|
17
|
-
function defaultFilter(
|
|
17
|
+
function defaultFilter(_value, _index, _array) {
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
20
|
exports.defaultFilter = defaultFilter;
|
|
21
21
|
function setGeneratorOptionDefaults(options) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
23
23
|
var templateFolder = (0, path_1.resolve)("".concat(__dirname, "/.."), 'templates');
|
|
24
24
|
options.typeFilterCallBack = (_a = options.typeFilterCallBack) !== null && _a !== void 0 ? _a : defaultFilter;
|
|
25
25
|
options.valuePropertyTypeFilterCallBack = (_b = options.valuePropertyTypeFilterCallBack) !== null && _b !== void 0 ? _b : defaultFilter;
|
|
26
26
|
options.referencePropertyTypeFilterCallBack = (_c = options.referencePropertyTypeFilterCallBack) !== null && _c !== void 0 ? _c : defaultFilter;
|
|
27
|
-
options.templates = __assign(__assign({}, options.templates), { model: (_e = (_d = options.templates) === null || _d === void 0 ? void 0 : _d.model) !== null && _e !== void 0 ? _e : "".concat(templateFolder, "/model.ts.hbs"),
|
|
27
|
+
options.templates = __assign(__assign({}, options.templates), { model: (_e = (_d = options.templates) === null || _d === void 0 ? void 0 : _d.model) !== null && _e !== void 0 ? _e : "".concat(templateFolder, "/model.ts.hbs"), entity: (_g = (_f = options.templates) === null || _f === void 0 ? void 0 : _f.entity) !== null && _g !== void 0 ? _g : "".concat(templateFolder, "/entity.ts.hbs"), form: (_j = (_h = options.templates) === null || _h === void 0 ? void 0 : _h.form) !== null && _j !== void 0 ? _j : "".concat(templateFolder, "/form.ts.hbs"), formGroupFactory: (_l = (_k = options.templates) === null || _k === void 0 ? void 0 : _k.formGroupFactory) !== null && _l !== void 0 ? _l : "".concat(templateFolder, "/form-group-factory.ts.hbs"), testObjectFactory: (_o = (_m = options.templates) === null || _m === void 0 ? void 0 : _m.testObjectFactory) !== null && _o !== void 0 ? _o : "".concat(templateFolder, "/test-object-factory.ts.hbs"), barrel: (_q = (_p = options.templates) === null || _p === void 0 ? void 0 : _p.barrel) !== null && _q !== void 0 ? _q : "".concat(templateFolder, "/index.ts.hbs"), enum: (_s = (_r = options.templates) === null || _r === void 0 ? void 0 : _r.barrel) !== null && _s !== void 0 ? _s : "".concat(templateFolder, "/enum.ts.hbs"), modelProperties: (_u = (_t = options.templates) === null || _t === void 0 ? void 0 : _t.barrel) !== null && _u !== void 0 ? _u : "".concat(templateFolder, "/model-properties.ts.hbs"), endpoints: (_w = (_v = options.templates) === null || _v === void 0 ? void 0 : _v.endpoints) !== null && _w !== void 0 ? _w : "".concat(templateFolder, "/endpoints.ts.hbs") });
|
|
28
28
|
return options;
|
|
29
29
|
}
|
|
30
30
|
exports.setGeneratorOptionDefaults = setGeneratorOptionDefaults;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { IEntity
|
|
1
|
+
import { IEntity } from './entity';
|
|
2
|
+
import { IValueProperty } from './value-property';
|
|
2
3
|
export declare function nrsrxTypeFilterCallBack(val: IEntity, _i: number, _arr: IEntity[]): boolean;
|
|
3
4
|
export declare function nrsrxValuePropertyTypeFilterCallBack(val: IValueProperty, _i: number, _arr: IValueProperty[]): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface IReferenceProperty {
|
|
2
|
+
name: string;
|
|
3
|
+
snakeCaseName: string;
|
|
4
|
+
referenceTypeName: string;
|
|
5
|
+
typeScriptType: string;
|
|
6
|
+
hasValidators: boolean;
|
|
7
|
+
isSameAsParentTypescriptType: boolean;
|
|
8
|
+
hasMultipleValidators: boolean;
|
|
9
|
+
maxItems?: number;
|
|
10
|
+
minItems?: number;
|
|
11
|
+
maxLength?: number;
|
|
12
|
+
minLength?: number;
|
|
13
|
+
maximum?: number;
|
|
14
|
+
minimum?: number;
|
|
15
|
+
isArray: boolean;
|
|
16
|
+
required: boolean;
|
|
17
|
+
isEnum?: boolean;
|
|
18
|
+
initialValue: string;
|
|
19
|
+
initialTestValue: string;
|
|
20
|
+
}
|
package/models/schema-info.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { ReferenceObject, SchemaObject } from 'openapi3-ts';
|
|
2
|
+
import { IEnumValue } from './enum-value';
|
|
2
3
|
import { IGeneratorOptions } from './generator-options';
|
|
3
|
-
import { IReferenceProperty
|
|
4
|
+
import { IReferenceProperty } from './reference-property';
|
|
5
|
+
import { IValueProperty } from './value-property';
|
|
4
6
|
export declare class SchemaWrapperInfo {
|
|
5
7
|
propertySchemaObject: SchemaObject;
|
|
6
8
|
propertyReferenceObject: ReferenceObject;
|
|
7
9
|
isEnum?: boolean;
|
|
8
|
-
readonly enumValues: (string |
|
|
9
|
-
key?: number;
|
|
10
|
-
name: string;
|
|
11
|
-
titleName: string;
|
|
12
|
-
})[];
|
|
10
|
+
readonly enumValues: (string | IEnumValue)[];
|
|
13
11
|
readonly componentSchemaObject: SchemaObject;
|
|
14
12
|
readonly valueProperties: IValueProperty[];
|
|
15
13
|
referenceProperties: IReferenceProperty[];
|