openapi-ts-generator 6.176.3 → 7.36.1

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.
@@ -0,0 +1,4 @@
1
+ import { IEnumValue } from './enum-value';
2
+ export declare function getEnumKey(data: IEnumValue[], lookupValue: number | string): number | undefined;
3
+ export declare function getEnumDisplayText(data: IEnumValue[], lookupValue: number | string): string | undefined;
4
+ export declare function getEnum(data: IEnumValue[], looupValue: number | string): IEnumValue | undefined;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEnum = exports.getEnumDisplayText = exports.getEnumKey = void 0;
4
+ function getEnumKey(data, lookupValue) {
5
+ var _a;
6
+ return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.key;
7
+ }
8
+ exports.getEnumKey = getEnumKey;
9
+ function getEnumDisplayText(data, lookupValue) {
10
+ var _a;
11
+ return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.displayText;
12
+ }
13
+ exports.getEnumDisplayText = getEnumDisplayText;
14
+ function getEnum(data, looupValue) {
15
+ return data.find(function (f) { return f.name === looupValue || f.key === looupValue; });
16
+ }
17
+ exports.getEnum = getEnum;
@@ -0,0 +1,5 @@
1
+ export declare enum EnumProperties {
2
+ KEY = "key",
3
+ NAME = "name",
4
+ DISPLAY_TEXT = "displayText"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EnumProperties = void 0;
4
+ var EnumProperties;
5
+ (function (EnumProperties) {
6
+ EnumProperties["KEY"] = "key";
7
+ EnumProperties["NAME"] = "name";
8
+ EnumProperties["DISPLAY_TEXT"] = "displayText";
9
+ })(EnumProperties = exports.EnumProperties || (exports.EnumProperties = {}));
@@ -0,0 +1,5 @@
1
+ export interface IEnumValue {
2
+ key: number;
3
+ name: string;
4
+ displayText: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export * from './enum-value';
2
+ export * from './enum-properties';
3
+ export * from './enum-helpers';
package/enums/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./enum-value"), exports);
18
+ __exportStar(require("./enum-properties"), exports);
19
+ __exportStar(require("./enum-helpers"), exports);
package/index.js CHANGED
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -9,13 +9,14 @@ export interface IGeneratorOptions {
9
9
  openApiJsonUrl?: string;
10
10
  openApiJsonFileName?: string;
11
11
  genAngularFormGroups?: boolean;
12
+ genAngularFormGroupsWithDefaultValues?: boolean;
12
13
  genClasses?: boolean;
13
14
  typeFilterCallBack?: (entity: IEntity, index: number, array: IEntity[]) => boolean;
14
15
  valuePropertyTypeFilterCallBack?: (valueProperty: IValueProperty, index: number, array: IValueProperty[]) => boolean;
15
16
  referencePropertyTypeFilterCallBack?: (referenceProperty: IReferenceProperty, index: number, array: IReferenceProperty[]) => boolean;
16
17
  pathUrlFormattingCallBack?: (url: string) => string;
17
18
  templates?: ITemplates | null;
18
- axiosConfig?: AxiosRequestConfig<any>;
19
+ axiosConfig?: AxiosRequestConfig<unknown>;
19
20
  }
20
21
  export interface ITemplates {
21
22
  model?: string;
@@ -8,4 +8,4 @@ export interface IHelperContext {
8
8
  };
9
9
  name: string;
10
10
  }
11
- export declare type PropertyType = 'valueProperties' | 'referenceProperties';
11
+ export type PropertyType = 'valueProperties' | 'referenceProperties';
@@ -1,4 +1,4 @@
1
- import { ReferenceObject, SchemaObject } from 'openapi3-ts';
1
+ import { ReferenceObject, SchemaObject } from 'openapi3-ts/dist/oas30';
2
2
  import { IEnumValue } from './enum-value';
3
3
  import { IGeneratorOptions } from './generator-options';
4
4
  import { IReferenceProperty } from './reference-property';
@@ -13,7 +13,8 @@ var SchemaWrapperInfo = /** @class */ (function () {
13
13
  this.enumValues = [];
14
14
  }
15
15
  SchemaWrapperInfo.prototype.updateReferenceProperties = function (options) {
16
- this.referenceProperties = this.referenceProperties.filter(options.referencePropertyTypeFilterCallBack || generator_options_1.defaultFilter);
16
+ var _a;
17
+ this.referenceProperties = this.referenceProperties.filter((_a = options.referencePropertyTypeFilterCallBack) !== null && _a !== void 0 ? _a : generator_options_1.defaultFilter);
17
18
  };
18
19
  return SchemaWrapperInfo;
19
20
  }());
@@ -1,10 +1,10 @@
1
- import { OpenAPIObject } from 'openapi3-ts';
2
1
  import { IGeneratorOptions } from './models/generator-options';
3
2
  import { SchemaWrapperInfo } from './models/schema-info';
4
3
  import { IImportType, IPath, ITemplateData } from './models/template-data';
5
4
  import { IEntity } from './models/entity';
6
5
  import { IReferenceProperty } from './models/reference-property';
7
6
  import { IValueProperty } from './models/value-property';
7
+ import { OpenAPIObject } from 'openapi3-ts/dist/oas30';
8
8
  export declare class OpenApiDocConverter {
9
9
  private readonly options;
10
10
  private readonly apiDocument;
@@ -58,9 +58,10 @@ var OpenApiDocConverter = /** @class */ (function () {
58
58
  var entity = {
59
59
  isEnum: schemaWrapperInfo.isEnum,
60
60
  enumValues: schemaWrapperInfo.enumValues.map(function (t) {
61
+ var _a;
61
62
  return typeof t === 'string' || t instanceof String
62
63
  ? t
63
- : __assign(__assign({}, t), { key: t.key || 0 });
64
+ : __assign(__assign({}, t), { key: (_a = t.key) !== null && _a !== void 0 ? _a : 0 });
64
65
  }),
65
66
  name: schemaName,
66
67
  kebabCasedName: (0, lodash_1.kebabCase)(schemaName),
@@ -81,9 +82,9 @@ var OpenApiDocConverter = /** @class */ (function () {
81
82
  var _this = this;
82
83
  schemaWrapperInfo.isEnum = true;
83
84
  (_a = schemaWrapperInfo.enumValues).push.apply(_a, (schemaWrapperInfo.componentSchemaObject.enum || []).map(function (x) {
84
- var _a, _b;
85
+ var _a, _b, _c;
85
86
  var key = (_a = _this.startNumberregex.exec(x)) === null || _a === void 0 ? void 0 : _a.at(0);
86
- var name = ((_b = _this.endAlphaNumRegex.exec(x)) === null || _b === void 0 ? void 0 : _b.at(0)) || '';
87
+ var name = (_c = (_b = _this.endAlphaNumRegex.exec(x)) === null || _b === void 0 ? void 0 : _b.at(0)) !== null && _c !== void 0 ? _c : '';
87
88
  return {
88
89
  key: key ? +key : 0,
89
90
  name: name,
@@ -123,7 +124,9 @@ var OpenApiDocConverter = /** @class */ (function () {
123
124
  var _a, _b;
124
125
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
125
126
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
126
- var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
127
+ var initialValue = this.options.genAngularFormGroupsWithDefaultValues
128
+ ? this.getInitialValue(propertyName, schemaWrapperInfo)
129
+ : 'undefined';
127
130
  var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
128
131
  return {
129
132
  required: required,
@@ -154,7 +157,9 @@ var OpenApiDocConverter = /** @class */ (function () {
154
157
  OpenApiDocConverter.prototype.convertArrayObjectToValuePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
155
158
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
156
159
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
157
- var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
160
+ var initialValue = this.options.genAngularFormGroupsWithDefaultValues
161
+ ? this.getInitialValue(propertyName, schemaWrapperInfo)
162
+ : 'undefined';
158
163
  var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
159
164
  return {
160
165
  required: required,
@@ -201,16 +206,16 @@ var OpenApiDocConverter = /** @class */ (function () {
201
206
  }
202
207
  };
203
208
  OpenApiDocConverter.prototype.getInitialTestValue = function (parentTypeName, propertyName, schemaWrapperInfo) {
204
- var _a, _b, _c, _d;
209
+ var _a, _b, _c, _d, _e, _f;
205
210
  var typescriptType = this.getPropertyTypeScriptType(schemaWrapperInfo);
206
- var schemaObject = (((_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) || {})[propertyName];
211
+ var schemaObject = ((_b = (_a = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {})[propertyName];
207
212
  var maxLength = schemaWrapperInfo.propertySchemaObject.maxLength;
208
213
  var minLength = schemaWrapperInfo.propertySchemaObject.minLength;
209
214
  var minValue = schemaWrapperInfo.propertySchemaObject.minimum;
210
- var email = ((_b = schemaWrapperInfo.propertySchemaObject.format) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'email';
215
+ var email = ((_c = schemaWrapperInfo.propertySchemaObject.format) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'email';
211
216
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
212
- var refName = schemaObject.$ref || ((_c = schemaObject.items) === null || _c === void 0 ? void 0 : _c.$ref);
213
- var refObject = (((_d = this.apiDocument.components) === null || _d === void 0 ? void 0 : _d.schemas) || {})[refName];
217
+ var refName = (schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.$ref) || ((_d = schemaObject.items) === null || _d === void 0 ? void 0 : _d.$ref);
218
+ var refObject = ((_f = (_e = this.apiDocument.components) === null || _e === void 0 ? void 0 : _e.schemas) !== null && _f !== void 0 ? _f : {})[refName];
214
219
  var defaultValue = (schemaWrapperInfo.componentSchemaObject.default || (refObject === null || refObject === void 0 ? void 0 : refObject.default) || ((refObject === null || refObject === void 0 ? void 0 : refObject.enum) || [])[0]);
215
220
  if (defaultValue && refObject.enum) {
216
221
  return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
@@ -230,6 +235,12 @@ var OpenApiDocConverter = /** @class */ (function () {
230
235
  else if (typescriptType === 'boolean') {
231
236
  return 'false';
232
237
  }
238
+ else if (typescriptType === 'number' && schemaObject.type === 'array') {
239
+ return minValue ? "[".concat(minValue, "]") : '[0]';
240
+ }
241
+ else if (schemaObject.type === 'array') {
242
+ return defaultValue ? "[".concat(defaultValue, "]") : '[]';
243
+ }
233
244
  else if (typescriptType === 'number') {
234
245
  return minValue ? "".concat(minValue) : '0';
235
246
  }
@@ -250,7 +261,9 @@ var OpenApiDocConverter = /** @class */ (function () {
250
261
  var refSchema = (((_b = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _b === void 0 ? void 0 : _b.properties) || {})[propertyName];
251
262
  var required = this.getIsRequired(propertyName, schemaWrapperInfo);
252
263
  var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
253
- var initialValue = this.getInitialValue(propertyName, schemaWrapperInfo);
264
+ var initialValue = this.options.genAngularFormGroupsWithDefaultValues
265
+ ? this.getInitialValue(propertyName, schemaWrapperInfo)
266
+ : 'undefined';
254
267
  var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
255
268
  var typeName = this.parseRef(schemaWrapperInfo);
256
269
  return {
@@ -291,8 +304,10 @@ var OpenApiDocConverter = /** @class */ (function () {
291
304
  +this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
292
305
  };
293
306
  OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
307
+ var _a;
294
308
  if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
295
- return schemaWrapperInfo.propertySchemaObject.items.type;
309
+ var type = schemaWrapperInfo.propertySchemaObject.items.type;
310
+ return type === 'integer' ? 'number' : type;
296
311
  }
297
312
  else if (schemaWrapperInfo.propertySchemaObject.type === 'integer' && schemaWrapperInfo.propertySchemaObject.enum) {
298
313
  return 'string | number';
@@ -303,7 +318,7 @@ var OpenApiDocConverter = /** @class */ (function () {
303
318
  else if (schemaWrapperInfo.propertySchemaObject.format === 'date' || schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
304
319
  return 'Date';
305
320
  }
306
- return schemaWrapperInfo.propertySchemaObject.type || 'string';
321
+ return (_a = schemaWrapperInfo.propertySchemaObject.type) !== null && _a !== void 0 ? _a : 'string';
307
322
  };
308
323
  OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
309
324
  var regexResult;
@@ -318,9 +333,10 @@ var OpenApiDocConverter = /** @class */ (function () {
318
333
  return result || 'unknown';
319
334
  };
320
335
  OpenApiDocConverter.prototype.getImportTypes = function (entityName, schemaWrapperInfo) {
321
- var _this = this;
322
336
  var _a;
323
- var schemaProperties = (((_a = this.apiDocument.components) === null || _a === void 0 ? void 0 : _a.schemas) || { properties: {} })[entityName].properties || {};
337
+ var _this = this;
338
+ var _b, _c, _d;
339
+ var schemaProperties = (_d = ((_c = (_b = this.apiDocument.components) === null || _b === void 0 ? void 0 : _b.schemas) !== null && _c !== void 0 ? _c : (_a = {}, _a[entityName] = { properties: {} }, _a))[entityName].properties) !== null && _d !== void 0 ? _d : {};
324
340
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
325
341
  var properties = Object.keys(schemaProperties).map(function (key) { return (__assign(__assign({ key: key }, schemaProperties[key]), { $ref: schemaProperties[key].$ref, items: schemaProperties[key].items || {}, type: schemaProperties[key].type })); });
326
342
  return schemaWrapperInfo.referenceProperties
@@ -341,7 +357,8 @@ var OpenApiDocConverter = /** @class */ (function () {
341
357
  });
342
358
  };
343
359
  OpenApiDocConverter.prototype.getIsRequired = function (propertyName, schemaWrapperInfo) {
344
- return (((schemaWrapperInfo.componentSchemaObject.required || []).indexOf(propertyName) > -1 ||
360
+ var _a;
361
+ return ((((_a = schemaWrapperInfo.componentSchemaObject.required) !== null && _a !== void 0 ? _a : []).indexOf(propertyName) > -1 ||
345
362
  (schemaWrapperInfo.propertySchemaObject.nullable === undefined ? false : !schemaWrapperInfo.propertySchemaObject.nullable)) &&
346
363
  propertyName !== 'id');
347
364
  };
package/package.json CHANGED
@@ -1,9 +1,21 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "6.176.3",
3
+ "version": "7.36.1",
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
+ "exports": {
8
+ ".": {
9
+ "import": "./index.js",
10
+ "require": "./index.js",
11
+ "types": "./index.d.ts"
12
+ },
13
+ "./enums": {
14
+ "import": "./enums/index.js",
15
+ "require": "./enums/index.js",
16
+ "types": "./enums/index.d.ts"
17
+ }
18
+ },
7
19
  "scripts": {
8
20
  "build": "npm run format && npm run lint && tsc && cp -rfv ./src/templates ./lib",
9
21
  "format": "prettier --write \"src/**/*.ts\"",
@@ -37,36 +49,36 @@
37
49
  ],
38
50
  "homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
39
51
  "devDependencies": {
40
- "@types/jest": "^27.4.1",
41
- "@types/lodash": "^4.14.182",
42
- "@types/node": "^16.11.27",
43
- "@types/pluralize": "^0.0.29",
44
- "@typescript-eslint/eslint-plugin": "^5.32.0",
45
- "@typescript-eslint/parser": "^5.32.0",
46
- "eslint": "^8.21.0",
47
- "eslint-config-prettier": "^8.5.0",
48
- "eslint-config-standard": "^17.0.0",
49
- "eslint-plugin-import": "^2.26.0",
52
+ "@types/jest": "^27.5.2",
53
+ "@types/lodash": "^4.17.10",
54
+ "@types/node": "^20.11.21",
55
+ "@types/pluralize": "^0.0.33",
56
+ "@typescript-eslint/eslint-plugin": "^7.1.0",
57
+ "@typescript-eslint/parser": "^7.1.0",
58
+ "eslint": "8.56",
59
+ "eslint-config-prettier": "^9.1.0",
60
+ "eslint-config-standard": "^17.1.0",
61
+ "eslint-plugin-import": "^2.29.1",
50
62
  "eslint-plugin-node": "^11.1.0",
51
- "eslint-plugin-promise": "^6.0.0",
52
- "jest": "^27.5.1",
63
+ "eslint-plugin-promise": "^6.6.0",
64
+ "jest": "^29.7.0",
53
65
  "jest-junit": "^13.2.0",
54
- "openapi3-ts": "^2.0.2",
55
- "prettier": "^2.7.1",
56
- "rxjs": "^7.5.7",
57
- "ts-jest": "^27.1.3",
58
- "typescript": "^4.6.3"
66
+ "openapi3-ts": "^4.2.2",
67
+ "prettier": "^3.3.3",
68
+ "rxjs": "^7.6.0",
69
+ "ts-jest": "^29.2.5",
70
+ "typescript": "^4.9.5"
59
71
  },
60
72
  "dependencies": {
61
- "axios": ">=0.x",
73
+ "axios": ">=1.7.9",
62
74
  "handlebars": ">=4.x",
63
75
  "lodash": ">=4.x",
64
76
  "pluralize": "^8.0.0"
65
77
  },
66
78
  "peerDependencies": {
67
- "axios": ">=0.x",
79
+ "axios": ">=1.x",
68
80
  "handlebars": ">=4.x",
69
81
  "lodash": ">=4.x",
70
- "rxjs": ">=6.x"
82
+ "rxjs": "*"
71
83
  }
72
84
  }
@@ -5,7 +5,7 @@
5
5
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
6
  * Do not edit.
7
7
  */
8
- /* tslint:disable */
8
+ /* eslint-disable */
9
9
  export enum Endpoints {
10
10
  {{#paths}}
11
11
  {{tag}} = '{{endpoint}}',
@@ -5,6 +5,7 @@
5
5
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
6
  * Do not edit.
7
7
  */
8
+ import { IEnumValue } from 'openapi-ts-generator/enums';
8
9
 
9
10
  {{#if description}}/**
10
11
  * {{description}}
@@ -30,7 +31,7 @@
30
31
  {{/enumValues}}
31
32
  }
32
33
 
33
- export const {{{camelSingularName}}}Values = [
34
+ export const {{{camelSingularName}}}Values : IEnumValue[] = [
34
35
  {{#enumValues}}
35
36
  { key: {{key}}, name: '{{name}}', displayText: '{{titleName}}'},
36
37
  {{/enumValues}}
@@ -5,7 +5,7 @@
5
5
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
6
  * Do not edit.
7
7
  */
8
- /* tslint:disable */
8
+ /* eslint-disable */
9
9
  {{#fileNames}}
10
10
  export * from './{{this}}';
11
11
  {{/fileNames}}
@@ -5,7 +5,7 @@
5
5
  * For issues or feature request, visit the repo: https://github.com/ikemtz/openapi-ts-generator
6
6
  * Do not edit.
7
7
  */
8
- /* tslint:disable */
8
+ /* eslint-disable */
9
9
  {{#if description}}/**
10
10
  * {{description}}
11
11
  */