openapi-ts-generator 3.197.4 → 4.55.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/generators/barrel-generator.js +3 -2
- package/generators/base-generator.js +7 -7
- package/generators/endpoints-generator.js +11 -7
- package/generators/form-group-generator.js +1 -1
- package/generators/model-generator.js +1 -1
- package/generators/model-properties-generator.js +1 -1
- package/index.js +4 -5
- package/models/generator-options.js +2 -2
- package/openapidoc-converter.js +8 -6
- package/package.json +20 -23
- package/templates/endpoints.ts.hbs +1 -1
|
@@ -29,8 +29,9 @@ var BarrelGenerator = /** @class */ (function (_super) {
|
|
|
29
29
|
}
|
|
30
30
|
BarrelGenerator.prototype.generate = function () {
|
|
31
31
|
var _this = this;
|
|
32
|
-
var fileNames = fs_1.readdirSync(this.generatorOptions.outputPath).map(function (value) { return value.replace(_this.tsRegex, ''); });
|
|
33
|
-
|
|
32
|
+
var fileNames = (0, fs_1.readdirSync)(this.generatorOptions.outputPath).map(function (value) { return value.replace(_this.tsRegex, ''); });
|
|
33
|
+
fileNames = fileNames.filter(function (x) { return x !== 'endpoints'; });
|
|
34
|
+
return _super.prototype.generateFile.call(this, "".concat(this.generatorOptions.outputPath, "/index.ts"), { fileNames: fileNames });
|
|
34
35
|
};
|
|
35
36
|
return BarrelGenerator;
|
|
36
37
|
}(base_generator_1.BaseGenerator));
|
|
@@ -9,8 +9,8 @@ var BaseGenerator = /** @class */ (function () {
|
|
|
9
9
|
this.templateFilePath = templateFilePath;
|
|
10
10
|
this.emptyArrayRegex = /, ]/g;
|
|
11
11
|
if (templateFilePath) {
|
|
12
|
-
var templateSource = fs_1.readFileSync(templateFilePath, { encoding: 'utf8' });
|
|
13
|
-
this.template = handlebars_1.compile(templateSource);
|
|
12
|
+
var templateSource = (0, fs_1.readFileSync)(templateFilePath, { encoding: 'utf8' });
|
|
13
|
+
this.template = (0, handlebars_1.compile)(templateSource);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
BaseGenerator.prototype.generateFile = function (outputFilePath, context) {
|
|
@@ -18,20 +18,20 @@ var BaseGenerator = /** @class */ (function () {
|
|
|
18
18
|
if (this.template) {
|
|
19
19
|
try {
|
|
20
20
|
var content = this.template(context).replace(this.emptyArrayRegex, ']');
|
|
21
|
-
fs_1.writeFileSync(outputFilePath, content, { encoding: 'utf8' });
|
|
21
|
+
(0, fs_1.writeFileSync)(outputFilePath, content, { encoding: 'utf8' });
|
|
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: "
|
|
25
|
+
(_a = this.generatorOptions.logger) === null || _a === void 0 ? void 0 : _a.error("Error executing template: ".concat((_b = this.templateFilePath) !== null && _b !== void 0 ? _b : 'undefined', "."));
|
|
26
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: "
|
|
27
|
+
(_d = this.generatorOptions.logger) === null || _d === void 0 ? void 0 : _d.error("Data: ".concat(JSON.stringify(context)));
|
|
28
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);
|
|
29
|
+
(_f = this.generatorOptions.logger) === null || _f === void 0 ? void 0 : _f.error(JSON.stringify(err));
|
|
30
30
|
throw err;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
(_g = this.generatorOptions.logger) === null || _g === void 0 ? void 0 : _g.warn("Template for "
|
|
34
|
+
(_g = this.generatorOptions.logger) === null || _g === void 0 ? void 0 : _g.warn("Template for ".concat(this.GeneratorName, " has not been specified"));
|
|
35
35
|
}
|
|
36
36
|
return null;
|
|
37
37
|
};
|
|
@@ -25,10 +25,14 @@ var __assign = (this && this.__assign) || function () {
|
|
|
25
25
|
};
|
|
26
26
|
return __assign.apply(this, arguments);
|
|
27
27
|
};
|
|
28
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
29
|
-
for (var i = 0,
|
|
30
|
-
|
|
31
|
-
|
|
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));
|
|
32
36
|
};
|
|
33
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
38
|
exports.EndPointsGenerator = void 0;
|
|
@@ -45,11 +49,11 @@ var EndPointsGenerator = /** @class */ (function (_super) {
|
|
|
45
49
|
}
|
|
46
50
|
EndPointsGenerator.prototype.generate = function (templateData) {
|
|
47
51
|
var paths = this.eliminateDupes(templateData);
|
|
48
|
-
return _super.prototype.generateFile.call(this, this.generatorOptions.outputPath
|
|
52
|
+
return _super.prototype.generateFile.call(this, "".concat(this.generatorOptions.outputPath, "/endpoints.ts"), { paths: paths });
|
|
49
53
|
};
|
|
50
54
|
EndPointsGenerator.prototype.eliminateDupes = function (templateData) {
|
|
51
55
|
var _this = this;
|
|
52
|
-
var sortedTemplateData = __spreadArray([], templateData.paths).sort(function (x, y) { return (x.endpoint.toUpperCase() < y.endpoint.toUpperCase() ? -1 : 1); });
|
|
56
|
+
var sortedTemplateData = __spreadArray([], templateData.paths, true).sort(function (x, y) { return (x.endpoint.toUpperCase() < y.endpoint.toUpperCase() ? -1 : 1); });
|
|
53
57
|
var result = [];
|
|
54
58
|
sortedTemplateData.forEach(function (val) {
|
|
55
59
|
val = __assign(__assign({}, val), { tag: _.camelCase(val.tag) });
|
|
@@ -57,7 +61,7 @@ var EndPointsGenerator = /** @class */ (function (_super) {
|
|
|
57
61
|
if (dupeIndex > -1) {
|
|
58
62
|
var dupeCount = result.filter(function (f) { return f.tag === val.tag; }).length + 1;
|
|
59
63
|
var endpointIdentifier = (_this.endpointIdentifierRegex.exec(val.endpoint) || [])[0];
|
|
60
|
-
result.push(__assign(__assign({}, val), { tag: _.camelCase(val.tag
|
|
64
|
+
result.push(__assign(__assign({}, val), { tag: _.camelCase("".concat(val.tag, "_").concat(endpointIdentifier || dupeCount)) }));
|
|
61
65
|
}
|
|
62
66
|
else {
|
|
63
67
|
result.push(val);
|
|
@@ -30,7 +30,7 @@ var FormGroupGenerator = /** @class */ (function (_super) {
|
|
|
30
30
|
var _this = this;
|
|
31
31
|
var _a;
|
|
32
32
|
(_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) {
|
|
33
|
-
_super.prototype.generateFile.call(_this, _this.generatorOptions.outputPath
|
|
33
|
+
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".form-group-fac.ts"), entity);
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
return FormGroupGenerator;
|
|
@@ -30,7 +30,7 @@ var ModelGenerator = /** @class */ (function (_super) {
|
|
|
30
30
|
var _this = this;
|
|
31
31
|
var _a;
|
|
32
32
|
(_a = templateData.entities) === null || _a === void 0 ? void 0 : _a.forEach(function (entity) {
|
|
33
|
-
_super.prototype.generateFile.call(_this, _this.generatorOptions.outputPath
|
|
33
|
+
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".model.ts"), entity);
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
return ModelGenerator;
|
|
@@ -30,7 +30,7 @@ var ModelPropertiesGenerator = /** @class */ (function (_super) {
|
|
|
30
30
|
var _this = this;
|
|
31
31
|
var _a;
|
|
32
32
|
(_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) > 0 || ((_b = val.referenceProperties) === null || _b === void 0 ? void 0 : _b.length) > 0; }).forEach(function (entity) {
|
|
33
|
-
_super.prototype.generateFile.call(_this, _this.generatorOptions.outputPath
|
|
33
|
+
_super.prototype.generateFile.call(_this, "".concat(_this.generatorOptions.outputPath, "/").concat(_.kebabCase(entity.name), ".properties.ts"), entity);
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
36
|
return ModelPropertiesGenerator;
|
package/index.js
CHANGED
|
@@ -38,7 +38,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
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");
|
|
43
42
|
var endpoints_generator_1 = require("./generators/endpoints-generator");
|
|
44
43
|
var generator_options_1 = require("./models/generator-options");
|
|
@@ -52,7 +51,7 @@ function generateTsModels(options) {
|
|
|
52
51
|
return __generator(this, function (_a) {
|
|
53
52
|
switch (_a.label) {
|
|
54
53
|
case 0:
|
|
55
|
-
options = generator_options_1.setGeneratorOptionDefaults(options);
|
|
54
|
+
options = (0, generator_options_1.setGeneratorOptionDefaults)(options);
|
|
56
55
|
return [4 /*yield*/, getOpenApiDocumentAsync(options)];
|
|
57
56
|
case 1:
|
|
58
57
|
apiDocument = _a.sent();
|
|
@@ -72,7 +71,7 @@ function getOpenApiDocumentAsync(options) {
|
|
|
72
71
|
switch (_a.label) {
|
|
73
72
|
case 0:
|
|
74
73
|
if (!options.openApiJsonUrl) return [3 /*break*/, 3];
|
|
75
|
-
return [4 /*yield*/,
|
|
74
|
+
return [4 /*yield*/, fetch(options.openApiJsonUrl)];
|
|
76
75
|
case 1:
|
|
77
76
|
response = _a.sent();
|
|
78
77
|
return [4 /*yield*/, response.json()];
|
|
@@ -81,7 +80,7 @@ function getOpenApiDocumentAsync(options) {
|
|
|
81
80
|
return [3 /*break*/, 4];
|
|
82
81
|
case 3:
|
|
83
82
|
if (options.openApiJsonFileName) {
|
|
84
|
-
response = fs.readFileSync(__dirname
|
|
83
|
+
response = fs.readFileSync("".concat(__dirname, "/").concat(options.openApiJsonFileName));
|
|
85
84
|
apiDoc = JSON.parse(response.toString());
|
|
86
85
|
}
|
|
87
86
|
else {
|
|
@@ -95,7 +94,7 @@ function getOpenApiDocumentAsync(options) {
|
|
|
95
94
|
}
|
|
96
95
|
function generateOutput(options, templateData) {
|
|
97
96
|
if (fs.existsSync(options.outputPath)) {
|
|
98
|
-
fs.readdirSync(options.outputPath).forEach(function (file) { return fs.unlinkSync(options.outputPath
|
|
97
|
+
fs.readdirSync(options.outputPath).forEach(function (file) { return fs.unlinkSync("".concat(options.outputPath, "/").concat(file)); });
|
|
99
98
|
fs.rmdirSync(options.outputPath);
|
|
100
99
|
}
|
|
101
100
|
fs.mkdirSync(options.outputPath, { recursive: true });
|
|
@@ -20,11 +20,11 @@ function defaultFilter(value, index, array) {
|
|
|
20
20
|
exports.defaultFilter = defaultFilter;
|
|
21
21
|
function setGeneratorOptionDefaults(options) {
|
|
22
22
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
23
|
-
var templateFolder = path_1.resolve(__dirname
|
|
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 : templateFolder
|
|
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"), formGroupFactory: (_g = (_f = options.templates) === null || _f === void 0 ? void 0 : _f.formGroupFactory) !== null && _g !== void 0 ? _g : "".concat(templateFolder, "/form-group-factory.ts.hbs"), barrel: (_j = (_h = options.templates) === null || _h === void 0 ? void 0 : _h.barrel) !== null && _j !== void 0 ? _j : "".concat(templateFolder, "/index.ts.hbs"), enum: (_l = (_k = options.templates) === null || _k === void 0 ? void 0 : _k.barrel) !== null && _l !== void 0 ? _l : "".concat(templateFolder, "/enum.ts.hbs"), modelProperties: (_o = (_m = options.templates) === null || _m === void 0 ? void 0 : _m.barrel) !== null && _o !== void 0 ? _o : "".concat(templateFolder, "/model-properties.ts.hbs"), endpoints: (_q = (_p = options.templates) === null || _p === void 0 ? void 0 : _p.endpoints) !== null && _q !== void 0 ? _q : "".concat(templateFolder, "/endpoints.ts.hbs") });
|
|
28
28
|
return options;
|
|
29
29
|
}
|
|
30
30
|
exports.setGeneratorOptionDefaults = setGeneratorOptionDefaults;
|
package/openapidoc-converter.js
CHANGED
|
@@ -65,12 +65,14 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
65
65
|
schemaWrapperInfo.propertySchemaObject.type !== 'array') {
|
|
66
66
|
schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(propertyName, schemaWrapperInfo));
|
|
67
67
|
}
|
|
68
|
-
else
|
|
69
|
-
|
|
70
|
-
schemaWrapperInfo.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
else {
|
|
69
|
+
schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName];
|
|
70
|
+
if (schemaWrapperInfo.propertyReferenceObject.$ref) {
|
|
71
|
+
schemaWrapperInfo.referenceProperties.push(this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo));
|
|
72
|
+
}
|
|
73
|
+
else if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
|
|
74
|
+
this.convertArray(propertyName, schemaWrapperInfo);
|
|
75
|
+
}
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.55.2",
|
|
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
9
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
10
|
-
"lint": "eslint . --ext .ts",
|
|
10
|
+
"lint": "eslint . --ext .ts --output-file ./eslint-report.json --format json",
|
|
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"
|
|
@@ -36,34 +36,31 @@
|
|
|
36
36
|
],
|
|
37
37
|
"homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/jest": "^
|
|
40
|
-
"@types/lodash": "^4.14.
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@
|
|
43
|
-
"@typescript-eslint/
|
|
44
|
-
"
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"eslint-config-prettier": "^8.1.0",
|
|
39
|
+
"@types/jest": "^27.4.1",
|
|
40
|
+
"@types/lodash": "^4.14.178",
|
|
41
|
+
"@types/node": "^16.11.25",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
|
43
|
+
"@typescript-eslint/parser": "^5.12.1",
|
|
44
|
+
"eslint": "^8.9.0",
|
|
45
|
+
"eslint-config-prettier": "^8.4.0",
|
|
47
46
|
"eslint-config-standard": "^16.0.2",
|
|
48
|
-
"eslint-plugin-import": "^2.
|
|
47
|
+
"eslint-plugin-import": "^2.25.4",
|
|
49
48
|
"eslint-plugin-node": "^11.1.0",
|
|
50
|
-
"eslint-plugin-promise": "^
|
|
51
|
-
"jest": "^27.
|
|
52
|
-
"jest-junit": "^
|
|
53
|
-
"openapi3-ts": "^2.0.
|
|
54
|
-
"prettier": "^2.
|
|
55
|
-
"rxjs": "^7.
|
|
56
|
-
"ts-jest": "^27.
|
|
57
|
-
"typescript": "^4.
|
|
49
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
50
|
+
"jest": "^27.5.1",
|
|
51
|
+
"jest-junit": "^13.0.0",
|
|
52
|
+
"openapi3-ts": "^2.0.2",
|
|
53
|
+
"prettier": "^2.5.1",
|
|
54
|
+
"rxjs": "^7.5.4",
|
|
55
|
+
"ts-jest": "^27.1.3",
|
|
56
|
+
"typescript": "^4.5.5"
|
|
58
57
|
},
|
|
59
58
|
"dependencies": {
|
|
60
59
|
"handlebars": "^4.x",
|
|
61
|
-
"lodash": "^4.x"
|
|
62
|
-
"node-fetch": "^2.x"
|
|
60
|
+
"lodash": "^4.x"
|
|
63
61
|
},
|
|
64
62
|
"peerDependencies": {
|
|
65
63
|
"handlebars": "^4.x",
|
|
66
|
-
"lodash": "^4.x"
|
|
67
|
-
"node-fetch": "^2.x"
|
|
64
|
+
"lodash": "^4.x"
|
|
68
65
|
}
|
|
69
66
|
}
|