openapi-ts-generator 3.5.1 → 3.26.4
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 +14 -1
- package/generators/barrel-generator.d.ts +1 -2
- package/generators/barrel-generator.js +5 -2
- package/generators/base-generator.d.ts +1 -1
- package/generators/base-generator.js +7 -7
- package/generators/endpoints-generator.d.ts +12 -0
- package/generators/endpoints-generator.js +70 -0
- package/generators/form-group-generator.js +3 -1
- package/generators/index.js +1 -1
- package/generators/model-generator.js +3 -1
- package/generators/model-properties-generator.js +3 -1
- package/index.js +11 -7
- package/models/generator-options.d.ts +8 -7
- package/models/generator-options.js +3 -2
- package/models/logger.js +3 -3
- package/models/template-data.d.ts +5 -1
- package/openapidoc-converter.d.ts +2 -1
- package/openapidoc-converter.js +26 -15
- package/package.json +27 -24
- package/templates/endpoints.ts.hbs +17 -0
- package/templates/form-group-factory.ts.hbs +2 -2
- package/templates/model.ts.hbs +1 -1
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://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)
|
|
2
2
|
|
|
3
3
|
# OpenApi-TS-Generator
|
|
4
4
|
|
|
@@ -34,6 +34,7 @@ const generator = require('openapi-ts-generator');
|
|
|
34
34
|
generator.generateTsModels({
|
|
35
35
|
openApiJsonUrl: '{Your Swagger Enpoint URL here}',
|
|
36
36
|
outputPath: './{outputFolder}/',
|
|
37
|
+
genAngularFormGroups: true /* Set this to true if only if you're in an Angular project*/
|
|
37
38
|
});
|
|
38
39
|
```
|
|
39
40
|
|
|
@@ -48,6 +49,18 @@ generator.generateTsModels({
|
|
|
48
49
|
});
|
|
49
50
|
```
|
|
50
51
|
|
|
52
|
+
## Want to include Angular FormGroup Factories?
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
const generator = require('openapi-ts-generator');
|
|
56
|
+
|
|
57
|
+
generator.generateTsModels({
|
|
58
|
+
openApiJsonFileName: '{location and file name of your OpenApi document}',
|
|
59
|
+
outputPath: './{outputFolder}/',
|
|
60
|
+
genAngularFormGroups: true
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
51
64
|
## Working example with NRSRx based service
|
|
52
65
|
|
|
53
66
|
```javascript
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
2
|
import { BaseGenerator } from './base-generator';
|
|
4
3
|
export declare class BarrelGenerator extends BaseGenerator<{
|
|
5
4
|
fileNames: string[];
|
|
@@ -7,5 +6,5 @@ export declare class BarrelGenerator extends BaseGenerator<{
|
|
|
7
6
|
readonly GeneratorName = "BarrelGenerator";
|
|
8
7
|
private readonly tsRegex;
|
|
9
8
|
constructor(options: IGeneratorOptions);
|
|
10
|
-
generate(
|
|
9
|
+
generate(): string | null;
|
|
11
10
|
}
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
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");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -25,9 +27,10 @@ var BarrelGenerator = /** @class */ (function (_super) {
|
|
|
25
27
|
_this.tsRegex = /.ts$/;
|
|
26
28
|
return _this;
|
|
27
29
|
}
|
|
28
|
-
BarrelGenerator.prototype.generate = function (
|
|
30
|
+
BarrelGenerator.prototype.generate = function () {
|
|
29
31
|
var _this = this;
|
|
30
32
|
var fileNames = fs_1.readdirSync(this.generatorOptions.outputPath).map(function (value) { return value.replace(_this.tsRegex, ''); });
|
|
33
|
+
fileNames = fileNames.filter(function (x) { return x !== 'endpoints'; });
|
|
31
34
|
return _super.prototype.generateFile.call(this, this.generatorOptions.outputPath + "/index.ts", { fileNames: fileNames });
|
|
32
35
|
};
|
|
33
36
|
return BarrelGenerator;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
export declare abstract class BaseGenerator<TContextSchema
|
|
2
|
+
export declare abstract class BaseGenerator<TContextSchema> {
|
|
3
3
|
readonly generatorOptions: IGeneratorOptions;
|
|
4
4
|
readonly templateFilePath: string | undefined;
|
|
5
5
|
abstract readonly GeneratorName: string;
|
|
@@ -14,7 +14,7 @@ var BaseGenerator = /** @class */ (function () {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
BaseGenerator.prototype.generateFile = function (outputFilePath, context) {
|
|
17
|
-
var _a, _b, _c, _d, _e, _f;
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
18
18
|
if (this.template) {
|
|
19
19
|
try {
|
|
20
20
|
var content = this.template(context).replace(this.emptyArrayRegex, ']');
|
|
@@ -22,16 +22,16 @@ var BaseGenerator = /** @class */ (function () {
|
|
|
22
22
|
return content;
|
|
23
23
|
}
|
|
24
24
|
catch (err) {
|
|
25
|
-
(_a = this.generatorOptions.logger) === null || _a === void 0 ? void 0 : _a.error("Error executing template: " + this.templateFilePath + ".");
|
|
26
|
-
(
|
|
27
|
-
(
|
|
28
|
-
(
|
|
29
|
-
(
|
|
25
|
+
(_a = this.generatorOptions.logger) === null || _a === void 0 ? void 0 : _a.error("Error executing template: " + ((_b = this.templateFilePath) !== null && _b !== void 0 ? _b : 'undefined') + ".");
|
|
26
|
+
(_c = this.generatorOptions.logger) === null || _c === void 0 ? void 0 : _c.error("This is likely an issue with the template.");
|
|
27
|
+
(_d = this.generatorOptions.logger) === null || _d === void 0 ? void 0 : _d.error("Data: " + JSON.stringify(context));
|
|
28
|
+
(_e = this.generatorOptions.logger) === null || _e === void 0 ? void 0 : _e.error("Goto: https://github.com/ikemtz/openapi-ts-generator to report an issue if necessary.");
|
|
29
|
+
(_f = this.generatorOptions.logger) === null || _f === void 0 ? void 0 : _f.error(err);
|
|
30
30
|
throw err;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
(
|
|
34
|
+
(_g = this.generatorOptions.logger) === null || _g === void 0 ? void 0 : _g.warn("Template for " + this.GeneratorName + " has not been specified");
|
|
35
35
|
}
|
|
36
36
|
return null;
|
|
37
37
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
+
import { IPath, ITemplateData } from '../models/template-data';
|
|
3
|
+
import { BaseGenerator } from './base-generator';
|
|
4
|
+
export declare class EndPointsGenerator extends BaseGenerator<{
|
|
5
|
+
paths: IPath[];
|
|
6
|
+
}> {
|
|
7
|
+
readonly GeneratorName = "EndPointsGenerator";
|
|
8
|
+
readonly endpointIdentifierRegex: RegExp;
|
|
9
|
+
constructor(options: IGeneratorOptions);
|
|
10
|
+
generate(templateData: ITemplateData): string | null;
|
|
11
|
+
eliminateDupes(templateData: ITemplateData): IPath[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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) {
|
|
29
|
+
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
30
|
+
to[j] = from[i];
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.EndPointsGenerator = void 0;
|
|
35
|
+
var base_generator_1 = require("./base-generator");
|
|
36
|
+
var _ = require("lodash");
|
|
37
|
+
var EndPointsGenerator = /** @class */ (function (_super) {
|
|
38
|
+
__extends(EndPointsGenerator, _super);
|
|
39
|
+
function EndPointsGenerator(options) {
|
|
40
|
+
var _a;
|
|
41
|
+
var _this = _super.call(this, options, (_a = options.templates) === null || _a === void 0 ? void 0 : _a.endpoints) || this;
|
|
42
|
+
_this.GeneratorName = 'EndPointsGenerator';
|
|
43
|
+
_this.endpointIdentifierRegex = /[A-z0-9_-]*$/;
|
|
44
|
+
return _this;
|
|
45
|
+
}
|
|
46
|
+
EndPointsGenerator.prototype.generate = function (templateData) {
|
|
47
|
+
var paths = this.eliminateDupes(templateData);
|
|
48
|
+
return _super.prototype.generateFile.call(this, this.generatorOptions.outputPath + "/endpoints.ts", { paths: paths });
|
|
49
|
+
};
|
|
50
|
+
EndPointsGenerator.prototype.eliminateDupes = function (templateData) {
|
|
51
|
+
var _this = this;
|
|
52
|
+
var sortedTemplateData = __spreadArray([], templateData.paths).sort(function (x, y) { return (x.endpoint.toUpperCase() < y.endpoint.toUpperCase() ? -1 : 1); });
|
|
53
|
+
var result = [];
|
|
54
|
+
sortedTemplateData.forEach(function (val) {
|
|
55
|
+
val = __assign(__assign({}, val), { tag: _.camelCase(val.tag) });
|
|
56
|
+
var dupeIndex = result.findIndex(function (f) { return f.tag === val.tag; });
|
|
57
|
+
if (dupeIndex > -1) {
|
|
58
|
+
var dupeCount = result.filter(function (f) { return f.tag === val.tag; }).length + 1;
|
|
59
|
+
var endpointIdentifier = (_this.endpointIdentifierRegex.exec(val.endpoint) || [])[0];
|
|
60
|
+
result.push(__assign(__assign({}, val), { tag: _.camelCase(val.tag + "_" + (endpointIdentifier || dupeCount)) }));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
result.push(val);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
return EndPointsGenerator;
|
|
69
|
+
}(base_generator_1.BaseGenerator));
|
|
70
|
+
exports.EndPointsGenerator = EndPointsGenerator;
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
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");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
package/generators/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
7
7
|
o[k2] = m[k];
|
|
8
8
|
}));
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./model-generator"), exports);
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
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");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
3
3
|
var extendStatics = function (d, b) {
|
|
4
4
|
extendStatics = Object.setPrototypeOf ||
|
|
5
5
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
7
|
return extendStatics(d, b);
|
|
8
8
|
};
|
|
9
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");
|
|
10
12
|
extendStatics(d, b);
|
|
11
13
|
function __() { this.constructor = d; }
|
|
12
14
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
package/index.js
CHANGED
|
@@ -36,10 +36,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.generateTsModels = void 0;
|
|
39
|
+
exports.generateTsModels = exports.nrsrxValuePropertyTypeFilterCallBack = exports.nrsrxTypeFilterCallBack = void 0;
|
|
40
40
|
var fs = require("fs");
|
|
41
|
-
var node_fetch_1 = require("node-fetch");
|
|
42
41
|
var generators_1 = require("./generators");
|
|
42
|
+
var endpoints_generator_1 = require("./generators/endpoints-generator");
|
|
43
43
|
var generator_options_1 = require("./models/generator-options");
|
|
44
44
|
var openapidoc_converter_1 = require("./openapidoc-converter");
|
|
45
45
|
var nrsrx_filters_1 = require("./models/nrsrx-filters");
|
|
@@ -71,12 +71,12 @@ function getOpenApiDocumentAsync(options) {
|
|
|
71
71
|
switch (_a.label) {
|
|
72
72
|
case 0:
|
|
73
73
|
if (!options.openApiJsonUrl) return [3 /*break*/, 3];
|
|
74
|
-
return [4 /*yield*/,
|
|
74
|
+
return [4 /*yield*/, fetch(options.openApiJsonUrl)];
|
|
75
75
|
case 1:
|
|
76
76
|
response = _a.sent();
|
|
77
77
|
return [4 /*yield*/, response.json()];
|
|
78
78
|
case 2:
|
|
79
|
-
apiDoc = _a.sent();
|
|
79
|
+
apiDoc = (_a.sent());
|
|
80
80
|
return [3 /*break*/, 4];
|
|
81
81
|
case 3:
|
|
82
82
|
if (options.openApiJsonFileName) {
|
|
@@ -100,10 +100,14 @@ function generateOutput(options, templateData) {
|
|
|
100
100
|
fs.mkdirSync(options.outputPath, { recursive: true });
|
|
101
101
|
var modelGenerator = new generators_1.ModelGenerator(options);
|
|
102
102
|
modelGenerator.generate(templateData);
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
if (options.genAngularFormGroups) {
|
|
104
|
+
var formGroupGenerator = new generators_1.FormGroupGenerator(options);
|
|
105
|
+
formGroupGenerator.generate(templateData);
|
|
106
|
+
}
|
|
105
107
|
var modelPropertiesGenerator = new generators_1.ModelPropertiesGenerator(options);
|
|
106
108
|
modelPropertiesGenerator.generate(templateData);
|
|
109
|
+
var endpointGenerator = new endpoints_generator_1.EndPointsGenerator(options);
|
|
110
|
+
endpointGenerator.generate(templateData);
|
|
107
111
|
var barrelGenerator = new generators_1.BarrelGenerator(options);
|
|
108
|
-
barrelGenerator.generate(
|
|
112
|
+
barrelGenerator.generate();
|
|
109
113
|
}
|
|
@@ -5,19 +5,20 @@ export interface IGeneratorOptions {
|
|
|
5
5
|
outputPath: string;
|
|
6
6
|
openApiJsonUrl?: string;
|
|
7
7
|
openApiJsonFileName?: string;
|
|
8
|
-
|
|
9
|
-
angular?: boolean | null;
|
|
8
|
+
genAngularFormGroups?: boolean;
|
|
10
9
|
typeFilterCallBack?: (entity: IEntity, index: number, array: IEntity[]) => boolean;
|
|
11
10
|
valuePropertyTypeFilterCallBack?: (valueProperty: IValueProperty, index: number, array: IValueProperty[]) => boolean;
|
|
12
11
|
referencePropertyTypeFilterCallBack?: (referenceProperty: IReferenceProperty, index: number, array: IReferenceProperty[]) => boolean;
|
|
12
|
+
pathUrlFormattingCallBack?: (url: string) => string;
|
|
13
13
|
templates?: ITemplates | null;
|
|
14
14
|
}
|
|
15
15
|
export interface ITemplates {
|
|
16
|
-
model
|
|
17
|
-
formGroupFactory
|
|
18
|
-
modelProperties
|
|
19
|
-
barrel
|
|
20
|
-
enum
|
|
16
|
+
model?: string;
|
|
17
|
+
formGroupFactory?: string;
|
|
18
|
+
modelProperties?: string;
|
|
19
|
+
barrel?: string;
|
|
20
|
+
enum?: string;
|
|
21
|
+
endpoints?: string;
|
|
21
22
|
}
|
|
22
23
|
export declare function defaultFilter(value: IEntity | IValueProperty | IReferenceProperty, index: number, array: IEntity[] | IValueProperty[] | IReferenceProperty[]): boolean;
|
|
23
24
|
export declare function setGeneratorOptionDefaults(options: IGeneratorOptions): IGeneratorOptions;
|
|
@@ -12,18 +12,19 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.setGeneratorOptionDefaults = exports.defaultFilter = void 0;
|
|
15
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
15
16
|
var path_1 = require("path");
|
|
16
17
|
function defaultFilter(value, index, array) {
|
|
17
18
|
return true;
|
|
18
19
|
}
|
|
19
20
|
exports.defaultFilter = defaultFilter;
|
|
20
21
|
function setGeneratorOptionDefaults(options) {
|
|
21
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
22
23
|
var templateFolder = path_1.resolve(__dirname + "/..", 'templates');
|
|
23
24
|
options.typeFilterCallBack = (_a = options.typeFilterCallBack) !== null && _a !== void 0 ? _a : defaultFilter;
|
|
24
25
|
options.valuePropertyTypeFilterCallBack = (_b = options.valuePropertyTypeFilterCallBack) !== null && _b !== void 0 ? _b : defaultFilter;
|
|
25
26
|
options.referencePropertyTypeFilterCallBack = (_c = options.referencePropertyTypeFilterCallBack) !== null && _c !== void 0 ? _c : defaultFilter;
|
|
26
|
-
options.templates = __assign(__assign({}, options.templates), { model: (_e = (_d = options.templates) === null || _d === void 0 ? void 0 : _d.model) !== null && _e !== void 0 ? _e : templateFolder + "/model.ts.hbs", formGroupFactory: (_g = (_f = options.templates) === null || _f === void 0 ? void 0 : _f.formGroupFactory) !== null && _g !== void 0 ? _g : templateFolder + "/form-group-factory.ts.hbs", barrel: (_j = (_h = options.templates) === null || _h === void 0 ? void 0 : _h.barrel) !== null && _j !== void 0 ? _j : templateFolder + "/index.ts.hbs", enum: (_l = (_k = options.templates) === null || _k === void 0 ? void 0 : _k.barrel) !== null && _l !== void 0 ? _l : templateFolder + "/enum.ts.hbs", modelProperties: (_o = (_m = options.templates) === null || _m === void 0 ? void 0 : _m.barrel) !== null && _o !== void 0 ? _o : templateFolder + "/model-properties.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 : templateFolder + "/model.ts.hbs", formGroupFactory: (_g = (_f = options.templates) === null || _f === void 0 ? void 0 : _f.formGroupFactory) !== null && _g !== void 0 ? _g : templateFolder + "/form-group-factory.ts.hbs", barrel: (_j = (_h = options.templates) === null || _h === void 0 ? void 0 : _h.barrel) !== null && _j !== void 0 ? _j : templateFolder + "/index.ts.hbs", enum: (_l = (_k = options.templates) === null || _k === void 0 ? void 0 : _k.barrel) !== null && _l !== void 0 ? _l : templateFolder + "/enum.ts.hbs", modelProperties: (_o = (_m = options.templates) === null || _m === void 0 ? void 0 : _m.barrel) !== null && _o !== void 0 ? _o : templateFolder + "/model-properties.ts.hbs", endpoints: (_q = (_p = options.templates) === null || _p === void 0 ? void 0 : _p.endpoints) !== null && _q !== void 0 ? _q : templateFolder + "/endpoints.ts.hbs" });
|
|
27
28
|
return options;
|
|
28
29
|
}
|
|
29
30
|
exports.setGeneratorOptionDefaults = setGeneratorOptionDefaults;
|
package/models/logger.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MockConsoleLogger = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
4
7
|
var MockConsoleLogger = /** @class */ (function () {
|
|
5
8
|
function MockConsoleLogger() {
|
|
6
|
-
// tslint:disable-next-line: no-empty
|
|
7
9
|
this.log = function (data) { };
|
|
8
|
-
// tslint:disable-next-line: no-empty
|
|
9
10
|
this.error = function (data) { };
|
|
10
|
-
// tslint:disable-next-line: no-empty
|
|
11
11
|
this.warn = function (data) { };
|
|
12
12
|
}
|
|
13
13
|
return MockConsoleLogger;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { OpenAPIObject } from 'openapi3-ts';
|
|
2
2
|
import { IGeneratorOptions } from './models/generator-options';
|
|
3
3
|
import { SchemaWrapperInfo } from './models/schema-info';
|
|
4
|
-
import { IEntity, IImportType, IReferenceProperty, ITemplateData, IValueProperty } from './models/template-data';
|
|
4
|
+
import { IEntity, IImportType, IPath, IReferenceProperty, ITemplateData, IValueProperty } from './models/template-data';
|
|
5
5
|
export declare class OpenApiDocConverter {
|
|
6
6
|
private readonly options;
|
|
7
7
|
private readonly apiDocument;
|
|
8
8
|
readonly regex: RegExp;
|
|
9
9
|
constructor(options: IGeneratorOptions, apiDocument: OpenAPIObject);
|
|
10
10
|
convertDocument(): ITemplateData;
|
|
11
|
+
convertPaths(): IPath[];
|
|
11
12
|
convertEntities(): IEntity[];
|
|
12
13
|
buildSchemaWrapperInfo(schemaWrapperInfo: SchemaWrapperInfo): void;
|
|
13
14
|
convertArray(propertyName: string, schemaWrapperInfo: SchemaWrapperInfo): void;
|
package/openapidoc-converter.js
CHANGED
|
@@ -12,9 +12,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.OpenApiDocConverter = void 0;
|
|
15
|
-
var _ = require("lodash");
|
|
16
15
|
var generator_options_1 = require("./models/generator-options");
|
|
17
16
|
var schema_info_1 = require("./models/schema-info");
|
|
17
|
+
var _ = require("lodash");
|
|
18
18
|
var OpenApiDocConverter = /** @class */ (function () {
|
|
19
19
|
function OpenApiDocConverter(options, apiDocument) {
|
|
20
20
|
this.options = options;
|
|
@@ -23,9 +23,23 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
23
23
|
}
|
|
24
24
|
OpenApiDocConverter.prototype.convertDocument = function () {
|
|
25
25
|
var entities = this.convertEntities();
|
|
26
|
-
var paths =
|
|
26
|
+
var paths = this.convertPaths();
|
|
27
27
|
return { entities: entities, paths: paths };
|
|
28
28
|
};
|
|
29
|
+
OpenApiDocConverter.prototype.convertPaths = function () {
|
|
30
|
+
var paths = [];
|
|
31
|
+
for (var key in this.apiDocument.paths) {
|
|
32
|
+
var path = this.apiDocument.paths[key] || {};
|
|
33
|
+
var tagLookup = path.get || path.post || path.put;
|
|
34
|
+
tagLookup = tagLookup || path.delete || path.patch;
|
|
35
|
+
var tag = ((tagLookup === null || tagLookup === void 0 ? void 0 : tagLookup.tags) || ['unknown_endpoint'])[0];
|
|
36
|
+
paths.push({
|
|
37
|
+
tag: _.snakeCase(tag),
|
|
38
|
+
endpoint: this.options.pathUrlFormattingCallBack ? this.options.pathUrlFormattingCallBack(key) : key,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return paths;
|
|
42
|
+
};
|
|
29
43
|
OpenApiDocConverter.prototype.convertEntities = function () {
|
|
30
44
|
var _a, _b, _c;
|
|
31
45
|
var entities = [];
|
|
@@ -47,16 +61,15 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
47
61
|
};
|
|
48
62
|
OpenApiDocConverter.prototype.buildSchemaWrapperInfo = function (schemaWrapperInfo) {
|
|
49
63
|
for (var propertyName in schemaWrapperInfo.componentSchemaObject.properties) {
|
|
50
|
-
if ((schemaWrapperInfo.propertySchemaObject = schemaWrapperInfo.componentSchemaObject.properties[ // NOSONAR
|
|
51
|
-
propertyName]).type &&
|
|
64
|
+
if ((schemaWrapperInfo.propertySchemaObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName]).type && // NOSONAR
|
|
52
65
|
schemaWrapperInfo.propertySchemaObject.type !== 'array') {
|
|
53
66
|
schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(propertyName, schemaWrapperInfo));
|
|
54
67
|
}
|
|
55
|
-
else if ((schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName])
|
|
68
|
+
else if ((schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName])
|
|
69
|
+
.$ref) {
|
|
56
70
|
schemaWrapperInfo.referenceProperties.push(this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo));
|
|
57
71
|
}
|
|
58
|
-
else if (schemaWrapperInfo.propertySchemaObject.type === 'array' &&
|
|
59
|
-
schemaWrapperInfo.propertySchemaObject.items) {
|
|
72
|
+
else if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
|
|
60
73
|
this.convertArray(propertyName, schemaWrapperInfo);
|
|
61
74
|
}
|
|
62
75
|
}
|
|
@@ -81,10 +94,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
81
94
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
82
95
|
maxLength: schemaWrapperInfo.propertySchemaObject.maxLength,
|
|
83
96
|
minLength: schemaWrapperInfo.propertySchemaObject.minLength,
|
|
84
|
-
hasMultipleValidators: +required +
|
|
85
|
-
+!!schemaWrapperInfo.propertySchemaObject.maxLength +
|
|
86
|
-
+!!schemaWrapperInfo.propertySchemaObject.minLength >
|
|
87
|
-
1,
|
|
97
|
+
hasMultipleValidators: +required + +!!schemaWrapperInfo.propertySchemaObject.maxLength + +!!schemaWrapperInfo.propertySchemaObject.minLength > 1,
|
|
88
98
|
};
|
|
89
99
|
};
|
|
90
100
|
OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (propertyName, schemaWrapperInfo) {
|
|
@@ -114,6 +124,9 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
114
124
|
if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
|
|
115
125
|
return schemaWrapperInfo.propertySchemaObject.items.type;
|
|
116
126
|
}
|
|
127
|
+
else if (schemaWrapperInfo.propertySchemaObject.type === 'integer' && schemaWrapperInfo.propertySchemaObject.enum) {
|
|
128
|
+
return 'string | number';
|
|
129
|
+
}
|
|
117
130
|
else if (schemaWrapperInfo.propertySchemaObject.type === 'integer') {
|
|
118
131
|
return 'number';
|
|
119
132
|
}
|
|
@@ -121,7 +134,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
121
134
|
return 'Date';
|
|
122
135
|
}
|
|
123
136
|
if (!schemaWrapperInfo.propertySchemaObject.type) {
|
|
124
|
-
throw new Error('Invalid
|
|
137
|
+
throw new Error('Invalid Property Type');
|
|
125
138
|
}
|
|
126
139
|
return schemaWrapperInfo.propertySchemaObject.type;
|
|
127
140
|
};
|
|
@@ -146,9 +159,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
146
159
|
};
|
|
147
160
|
OpenApiDocConverter.prototype.getIsRequired = function (propertyName, schemaWrapperInfo) {
|
|
148
161
|
return (((schemaWrapperInfo.componentSchemaObject.required || []).indexOf(propertyName) > -1 ||
|
|
149
|
-
(schemaWrapperInfo.propertySchemaObject.nullable === undefined
|
|
150
|
-
? false
|
|
151
|
-
: !schemaWrapperInfo.propertySchemaObject.nullable)) &&
|
|
162
|
+
(schemaWrapperInfo.propertySchemaObject.nullable === undefined ? false : !schemaWrapperInfo.propertySchemaObject.nullable)) &&
|
|
152
163
|
propertyName !== 'id');
|
|
153
164
|
};
|
|
154
165
|
return OpenApiDocConverter;
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-generator",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "Based on swagger-ts-generator, this is a type script model generator specifically for
|
|
3
|
+
"version": "3.26.4",
|
|
4
|
+
"description": "Based on swagger-ts-generator, this is a type script model generator specifically for services with OpenApi spec documentation.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npm run format && npm run lint && tsc && cp -rfv ./src/templates ./lib",
|
|
9
|
-
"format": "prettier --write \"src/**/*.ts\"
|
|
10
|
-
"lint": "
|
|
9
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
10
|
+
"lint": "eslint . --ext .ts --output-file ./eslint-report.html",
|
|
11
11
|
"test": "npm run build && jest --collect-coverage",
|
|
12
12
|
"prep:lib": "rm -rv ./lib/*.spec.* && rm -rv ./lib/**/*.spec.* && cp -v ./package.json ./lib/ && cp -v ./LICENSE ./lib/ && cp -v ./README.md ./lib/",
|
|
13
13
|
"debug": "npm run build && node --inspect-brk ./lib/app.js"
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"TypeScript",
|
|
25
25
|
"TS",
|
|
26
26
|
"Interfaces",
|
|
27
|
-
"Angular"
|
|
27
|
+
"Angular",
|
|
28
|
+
"Swagger"
|
|
28
29
|
],
|
|
29
30
|
"license": "MIT",
|
|
30
31
|
"bugs": {
|
|
@@ -35,29 +36,31 @@
|
|
|
35
36
|
],
|
|
36
37
|
"homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
|
|
37
38
|
"devDependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
39
|
+
"@types/jest": "^26.0.22",
|
|
40
|
+
"@types/lodash": "^4.14.168",
|
|
41
|
+
"@types/node": "^15.9.0",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "4.26",
|
|
43
|
+
"@typescript-eslint/parser": "4.26",
|
|
44
|
+
"eslint": "7.23",
|
|
45
|
+
"eslint-config-prettier": "^8.1.0",
|
|
46
|
+
"eslint-config-standard": "^16.0.2",
|
|
47
|
+
"eslint-plugin-import": "^2.23.4",
|
|
48
|
+
"eslint-plugin-node": "^11.1.0",
|
|
49
|
+
"eslint-plugin-promise": "^5.1.0",
|
|
50
|
+
"jest": "^27.0.3",
|
|
51
|
+
"jest-junit": "^12.1.0",
|
|
52
|
+
"openapi3-ts": "^2.0.1",
|
|
53
|
+
"prettier": "^2.2.1",
|
|
54
|
+
"rxjs": "^7.1.0",
|
|
55
|
+
"ts-jest": "^27.0.2",
|
|
56
|
+
"typescript": "^4.3.2"
|
|
52
57
|
},
|
|
53
58
|
"dependencies": {
|
|
54
|
-
"handlebars": "^4.
|
|
55
|
-
"lodash": "^4.
|
|
56
|
-
"node-fetch": "^2.6.1"
|
|
59
|
+
"handlebars": "^4.x",
|
|
60
|
+
"lodash": "^4.x"
|
|
57
61
|
},
|
|
58
62
|
"peerDependencies": {
|
|
59
63
|
"handlebars": "^4.x",
|
|
60
|
-
"lodash": "^4.x"
|
|
61
|
-
"node-fetch": "^2.x"
|
|
64
|
+
"lodash": "^4.x"
|
|
62
65
|
}
|
|
63
66
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is generated by the openapi-ts-generator
|
|
3
|
+
* #endpoints-ts.hbs
|
|
4
|
+
* For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
|
|
5
|
+
* Do not edit.
|
|
6
|
+
*/
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
export enum Endpoints {
|
|
9
|
+
{{#paths}}
|
|
10
|
+
{{tag}} = '{{endpoint}}',
|
|
11
|
+
{{/paths}}
|
|
12
|
+
}
|
|
13
|
+
export interface IEndpoints {
|
|
14
|
+
{{#paths}}
|
|
15
|
+
readonly {{tag}}: string;
|
|
16
|
+
{{/paths}}
|
|
17
|
+
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
|
|
5
5
|
* Do not edit.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms';
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
import { FormControl, FormArray, FormGroup, Validators } from '@angular/forms'; //NOSONAR
|
|
9
9
|
|
|
10
10
|
export function {{name}}FormGroupFac(): FormGroup {
|
|
11
11
|
return new FormGroup({
|
package/templates/model.ts.hbs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
|
|
5
5
|
* Do not edit.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
8
8
|
{{#if importTypes}}
|
|
9
9
|
{{#importTypes}}
|
|
10
10
|
import { I{{name}} } from './{{kebabCasedTypeName}}.model';
|