openapi-ts-generator 3.11.6 → 3.26.5

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 CHANGED
@@ -1,4 +1,4 @@
1
- [![Build Status](https://ikemtz.visualstudio.com/CI%20CD/_apis/build/status/openapi-ts-generator?branchName=master)](https://ikemtz.visualstudio.com/CI%20CD/_build/latest?definitionId=20&branchName=master) [![npm version](https://badge.fury.io/js/openapi-ts-generator.svg)](https://www.npmjs.com/package/openapi-ts-generator) [![npm downloads](https://img.shields.io/npm/dt/openapi-ts-generator)](https://www.npmjs.com/package/openapi-ts-generator) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=open-api-ts-generator&metric=alert_status)](https://sonarcloud.io/dashboard?id=open-api-ts-generator) [![Issues](https://img.shields.io/github/issues-raw/ikemtz/OpenApi-TS-Generator)](https://github.com/ikemtz/openapi-ts-generator/issues) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=open-api-ts-generator&metric=coverage)](https://sonarcloud.io/dashboard?id=open-api-ts-generator) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=open-api-ts-generator&metric=ncloc)](https://sonarcloud.io/dashboard?id=open-api-ts-generator) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=open-api-ts-generator&metric=security_rating)](https://sonarcloud.io/dashboard?id=open-api-ts-generator)
1
+ [![Build Status](https://ikemtz.visualstudio.com/CI%20CD/_apis/build/status/openapi-ts-generator?branchName=master)](https://ikemtz.visualstudio.com/CI%20CD/_build/latest?definitionId=20&branchName=master) [![npm version](https://badge.fury.io/js/openapi-ts-generator.svg)](https://www.npmjs.com/package/openapi-ts-generator) [![npm downloads](https://img.shields.io/npm/dt/openapi-ts-generator)](https://www.npmjs.com/package/openapi-ts-generator) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=alert_status)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Issues](https://img.shields.io/github/issues-raw/ikemtz/OpenApi-TS-Generator)](https://github.com/ikemtz/openapi-ts-generator/issues) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=coverage)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=ncloc)](https://sonarcloud.io/dashboard?id=ikemtz_openapi-ts-generator) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=ikemtz_openapi-ts-generator&metric=security_rating)](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(templateData: ITemplateData): string | null;
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
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,10 +27,10 @@ var BarrelGenerator = /** @class */ (function (_super) {
25
27
  _this.tsRegex = /.ts$/;
26
28
  return _this;
27
29
  }
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- BarrelGenerator.prototype.generate = function (templateData) {
30
+ BarrelGenerator.prototype.generate = function () {
30
31
  var _this = this;
31
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'; });
32
34
  return _super.prototype.generateFile.call(this, this.generatorOptions.outputPath + "/index.ts", { fileNames: fileNames });
33
35
  };
34
36
  return BarrelGenerator;
@@ -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
- (_b = this.generatorOptions.logger) === null || _b === void 0 ? void 0 : _b.error("This is likely an issue with the template.");
27
- (_c = this.generatorOptions.logger) === null || _c === void 0 ? void 0 : _c.error("Data: " + JSON.stringify(context));
28
- (_d = this.generatorOptions.logger) === null || _d === void 0 ? void 0 : _d.error("Goto: https://github.com/ikemtz/openapi-ts-generator to report an issue if necessary.");
29
- (_e = this.generatorOptions.logger) === null || _e === void 0 ? void 0 : _e.error(err);
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
- (_f = this.generatorOptions.logger) === null || _f === void 0 ? void 0 : _f.warn("Template for " + this.GeneratorName + " has not been specified");
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
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 __());
@@ -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" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
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*/, node_fetch_1.default(options.openApiJsonUrl)];
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
- var formGroupGenerator = new generators_1.FormGroupGenerator(options);
104
- formGroupGenerator.generate(templateData);
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(templateData);
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
- messageFormat?: string | null;
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: string;
17
- formGroupFactory: string;
18
- modelProperties: string;
19
- barrel: string;
20
- enum: string;
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;
@@ -19,12 +19,12 @@ function defaultFilter(value, index, array) {
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;
22
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
23
23
  var templateFolder = path_1.resolve(__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 + "/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" });
28
28
  return options;
29
29
  }
30
30
  exports.setGeneratorOptionDefaults = setGeneratorOptionDefaults;
package/models/logger.js CHANGED
@@ -1,6 +1,9 @@
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
9
  this.log = function (data) { };
@@ -1,6 +1,10 @@
1
1
  export interface ITemplateData {
2
2
  entities?: IEntity[];
3
- paths: string[];
3
+ paths: IPath[];
4
+ }
5
+ export interface IPath {
6
+ tag: string;
7
+ endpoint: string;
4
8
  }
5
9
  export interface IEntity {
6
10
  name: string;
@@ -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;
@@ -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 = [];
@@ -51,12 +65,14 @@ var OpenApiDocConverter = /** @class */ (function () {
51
65
  schemaWrapperInfo.propertySchemaObject.type !== 'array') {
52
66
  schemaWrapperInfo.valueProperties.push(this.convertSchemaObjectToPropertyType(propertyName, schemaWrapperInfo));
53
67
  }
54
- else if ((schemaWrapperInfo.propertyReferenceObject = schemaWrapperInfo.componentSchemaObject.properties[propertyName])
55
- .$ref) {
56
- schemaWrapperInfo.referenceProperties.push(this.convertReferenceObjectToPropertyType(propertyName, schemaWrapperInfo));
57
- }
58
- else if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
59
- this.convertArray(propertyName, schemaWrapperInfo);
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
+ }
60
76
  }
61
77
  }
62
78
  };
@@ -110,6 +126,9 @@ var OpenApiDocConverter = /** @class */ (function () {
110
126
  if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
111
127
  return schemaWrapperInfo.propertySchemaObject.items.type;
112
128
  }
129
+ else if (schemaWrapperInfo.propertySchemaObject.type === 'integer' && schemaWrapperInfo.propertySchemaObject.enum) {
130
+ return 'string | number';
131
+ }
113
132
  else if (schemaWrapperInfo.propertySchemaObject.type === 'integer') {
114
133
  return 'number';
115
134
  }
@@ -117,7 +136,7 @@ var OpenApiDocConverter = /** @class */ (function () {
117
136
  return 'Date';
118
137
  }
119
138
  if (!schemaWrapperInfo.propertySchemaObject.type) {
120
- throw new Error('Invalid Propety Type');
139
+ throw new Error('Invalid Property Type');
121
140
  }
122
141
  return schemaWrapperInfo.propertySchemaObject.type;
123
142
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "3.011.06",
4
- "description": "Based on swagger-ts-generator, this is a type script model generator specifically for OData endpoints documented by swagger.",
3
+ "version": "3.26.5",
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\" \"src/**/*.js\"",
10
- "lint": "eslint . --ext .ts",
9
+ "format": "prettier --write \"src/**/*.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"
@@ -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,33 +36,31 @@
35
36
  ],
36
37
  "homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
37
38
  "devDependencies": {
38
- "@angular/forms": "^10.2.3",
39
- "@types/jest": "^24.9.1",
40
- "@types/lodash": "^4.14.165",
41
- "@types/node": "^11.15.38",
42
- "@types/node-fetch": "^2.5.7",
43
- "@typescript-eslint/eslint-plugin": "^4.13.0",
44
- "@typescript-eslint/parser": "^4.13.0",
45
- "eslint": "^7.17.0",
46
- "eslint-config-prettier": "^7.1.0",
47
- "jest": "^26.6.3",
48
- "jest-junit": "^9.0.0",
49
- "openapi3-ts": "^1.4.0",
50
- "prettier": "^1.19.1",
51
- "rxjs": "^6.6.3",
52
- "ts-jest": "^26.4.4",
53
- "tslint": "^5.20.1",
54
- "tslint-config-prettier": "^1.18.0",
55
- "typescript": "^3.9.7"
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"
56
57
  },
57
58
  "dependencies": {
58
- "handlebars": "^4.7.6",
59
- "lodash": "^4.17.20",
60
- "node-fetch": "^2.6.1"
59
+ "handlebars": "^4.x",
60
+ "lodash": "^4.x"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "handlebars": "^4.x",
64
- "lodash": "^4.x",
65
- "node-fetch": "^2.x"
64
+ "lodash": "^4.x"
66
65
  }
67
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,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
- /* tslint:disable */
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';