openapi-ts-generator 7.339.6 → 8.55.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.
@@ -1,4 +1,25 @@
1
1
  import { IEnumValue } from './enum-value';
2
+ /**
3
+ * Retrieves the key of an enum value from a list of enum values.
4
+ *
5
+ * @param data - An array of enum values implementing the `IEnumValue` interface.
6
+ * @param lookupValue - The value to look up in the enum, which can be a number or a string.
7
+ * @returns The key of the enum value if found, otherwise `undefined`.
8
+ */
2
9
  export declare function getEnumKey(data: IEnumValue[], lookupValue: number | string): number | undefined;
10
+ /**
11
+ * Retrieves the display text for a given enum value.
12
+ *
13
+ * @param data - An array of enum values implementing the `IEnumValue` interface.
14
+ * @param lookupValue - The value to look up in the enum, which can be a number or a string.
15
+ * @returns The display text associated with the given enum value, or `undefined` if not found.
16
+ */
3
17
  export declare function getEnumDisplayText(data: IEnumValue[], lookupValue: number | string): string | undefined;
4
- export declare function getEnum(data: IEnumValue[], looupValue: number | string): IEnumValue | undefined;
18
+ /**
19
+ * Retrieves an enum value from a list of enum values based on a lookup value.
20
+ *
21
+ * @param data - An array of enum values to search within.
22
+ * @param lookupValue - The value to look up, which can be either a number or a string.
23
+ * @returns The matching enum value, or `undefined` if no match is found.
24
+ */
25
+ export declare function getEnum(data: IEnumValue[], lookupValue: number | string): IEnumValue | undefined;
@@ -1,17 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getEnum = exports.getEnumDisplayText = exports.getEnumKey = void 0;
4
+ /**
5
+ * Retrieves the key of an enum value from a list of enum values.
6
+ *
7
+ * @param data - An array of enum values implementing the `IEnumValue` interface.
8
+ * @param lookupValue - The value to look up in the enum, which can be a number or a string.
9
+ * @returns The key of the enum value if found, otherwise `undefined`.
10
+ */
4
11
  function getEnumKey(data, lookupValue) {
5
12
  var _a;
6
13
  return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.key;
7
14
  }
8
15
  exports.getEnumKey = getEnumKey;
16
+ /**
17
+ * Retrieves the display text for a given enum value.
18
+ *
19
+ * @param data - An array of enum values implementing the `IEnumValue` interface.
20
+ * @param lookupValue - The value to look up in the enum, which can be a number or a string.
21
+ * @returns The display text associated with the given enum value, or `undefined` if not found.
22
+ */
9
23
  function getEnumDisplayText(data, lookupValue) {
10
24
  var _a;
11
25
  return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.displayText;
12
26
  }
13
27
  exports.getEnumDisplayText = getEnumDisplayText;
14
- function getEnum(data, looupValue) {
15
- return data.find(function (f) { return f.name === looupValue || f.key === looupValue; });
28
+ /**
29
+ * Retrieves an enum value from a list of enum values based on a lookup value.
30
+ *
31
+ * @param data - An array of enum values to search within.
32
+ * @param lookupValue - The value to look up, which can be either a number or a string.
33
+ * @returns The matching enum value, or `undefined` if no match is found.
34
+ */
35
+ function getEnum(data, lookupValue) {
36
+ return data.find(function (f) { return f.name === lookupValue || f.key === lookupValue; });
16
37
  }
17
38
  exports.getEnum = getEnum;
@@ -14,7 +14,8 @@ export interface IReferenceProperty {
14
14
  minimum?: number;
15
15
  isArray: boolean;
16
16
  required: boolean;
17
- isEnum?: boolean;
17
+ isEnum: boolean;
18
+ isEnumAndArray: boolean;
18
19
  initialValue: string;
19
20
  initialTestValue: string;
20
21
  }
@@ -217,7 +217,10 @@ var OpenApiDocConverter = /** @class */ (function () {
217
217
  var refName = (schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.$ref) || ((_d = schemaObject.items) === null || _d === void 0 ? void 0 : _d.$ref);
218
218
  var refObject = ((_f = (_e = this.apiDocument.components) === null || _e === void 0 ? void 0 : _e.schemas) !== null && _f !== void 0 ? _f : {})[refName];
219
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]);
220
- if (defaultValue && refObject.enum) {
220
+ if (defaultValue && refObject.enum && schemaObject.type === 'array') {
221
+ return "[".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop(), "]");
222
+ }
223
+ else if (defaultValue && refObject.enum) {
221
224
  return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
222
225
  }
223
226
  else if (refObject) {
@@ -253,7 +256,9 @@ var OpenApiDocConverter = /** @class */ (function () {
253
256
  }
254
257
  };
255
258
  OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
256
- return __assign(__assign({}, this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo)), { isArray: true });
259
+ var refProperty = __assign(__assign({}, this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo)), { isArray: true });
260
+ refProperty.isEnumAndArray = refProperty.isEnum && refProperty.isArray;
261
+ return refProperty;
257
262
  };
258
263
  OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
259
264
  var _a, _b, _c;
@@ -277,6 +282,7 @@ var OpenApiDocConverter = /** @class */ (function () {
277
282
  typeScriptType: typeName,
278
283
  isArray: false,
279
284
  isEnum: ((_c = propertySchema === null || propertySchema === void 0 ? void 0 : propertySchema.enum) !== null && _c !== void 0 ? _c : []).length > 0,
285
+ isEnumAndArray: false,
280
286
  hasValidators: validatorCount > 0,
281
287
  hasMultipleValidators: validatorCount > 1,
282
288
  maxLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxLength,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-generator",
3
- "version": "7.339.6",
3
+ "version": "8.55.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",
@@ -17,7 +17,7 @@
17
17
  }
18
18
  },
19
19
  "scripts": {
20
- "build": "npm run format && npm run lint && tsc && cp -rfv ./src/templates ./lib",
20
+ "build": "tsc && cp -rfv ./src/templates ./lib",
21
21
  "format": "prettier --write \"src/**/*.ts\"",
22
22
  "lint": "eslint . --ext .ts --output-file ./eslint-report.json --format json && eslint . --ext .ts --output-file ./eslint-report.html --format html ",
23
23
  "link": "npm run build && cd lib && npm link && cd ..",
@@ -49,8 +49,8 @@
49
49
  ],
50
50
  "homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
51
51
  "devDependencies": {
52
- "@types/jest": "^27.5.2",
53
- "@types/lodash": "^4.17.10",
52
+ "@types/jest": "^29.5.14",
53
+ "@types/lodash": "^4.17.15",
54
54
  "@types/node": "^20.11.21",
55
55
  "@types/pluralize": "^0.0.33",
56
56
  "@typescript-eslint/eslint-plugin": "^7.1.0",
@@ -58,19 +58,19 @@
58
58
  "eslint": "8.56",
59
59
  "eslint-config-prettier": "^9.1.0",
60
60
  "eslint-config-standard": "^17.1.0",
61
- "eslint-plugin-import": "^2.29.1",
61
+ "eslint-plugin-import": "^2.31.0",
62
62
  "eslint-plugin-node": "^11.1.0",
63
63
  "eslint-plugin-promise": "^6.6.0",
64
64
  "jest": "^29.7.0",
65
- "jest-junit": "^13.2.0",
66
- "openapi3-ts": "^4.2.2",
67
- "prettier": "^3.3.3",
65
+ "jest-junit": "^16.0.0",
66
+ "openapi3-ts": "^4.4.0",
67
+ "prettier": "^3.5.2",
68
68
  "rxjs": "^7.6.0",
69
- "ts-jest": "^29.2.5",
69
+ "ts-jest": "^29.2.6",
70
70
  "typescript": "^4.9.5"
71
71
  },
72
72
  "dependencies": {
73
- "axios": ">=1.7.8",
73
+ "axios": ">=1.7.9",
74
74
  "handlebars": ">=4.x",
75
75
  "lodash": ">=4.x",
76
76
  "pluralize": "^8.0.0"
@@ -31,7 +31,13 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
31
31
  {{/if}}
32
32
  {{/valueProperties}}
33
33
  {{#referenceProperties}}
34
- {{#if isArray}}
34
+ {{#if isEnumAndArray}}
35
+ {{#if hasMultipleValidators}}
36
+ {{name}}: new FormArray<{{typeScriptType}}>([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]) }),
37
+ {{else}}
38
+ {{name}}: new FormArray<{{typeScriptType}}>([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
39
+ {{/if}}
40
+ {{else if isArray}}
35
41
  {{#if hasMultipleValidators}}
36
42
  {{name}}: new FormArray<FormGroup<I{{typeScriptType}}Form>>([], { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]) }),
37
43
  {{else}}
@@ -19,7 +19,9 @@ export interface I{{name}}Form {
19
19
  {{/if}}
20
20
  {{/valueProperties}}
21
21
  {{#referenceProperties}}
22
- {{#if isArray}}
22
+ {{#if isEnumAndArray}}
23
+ {{name}}: FormArray<{{typeScriptType}}>;
24
+ {{else if isArray}}
23
25
  {{name}}: FormArray<FormGroup<I{{typeScriptType}}Form>>;
24
26
  {{else if isEnum}}
25
27
  {{name}}: FormControl<{{typeScriptType}} | string{{#unless required}} | null | undefined{{/unless}}>;