openapi-ts-generator 6.199.2 → 7.55.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/enums/enum-helpers.d.ts +25 -0
- package/enums/enum-helpers.js +38 -0
- package/enums/enum-properties.d.ts +5 -0
- package/enums/enum-properties.js +9 -0
- package/enums/enum-value.d.ts +5 -0
- package/enums/enum-value.js +2 -0
- package/enums/index.d.ts +3 -0
- package/enums/index.js +19 -0
- package/index.js +1 -1
- package/models/generator-options.d.ts +2 -1
- package/models/helper-context.d.ts +1 -1
- package/models/reference-property.d.ts +2 -1
- package/models/schema-info.d.ts +1 -1
- package/models/schema-info.js +2 -1
- package/openapidoc-converter.d.ts +1 -1
- package/openapidoc-converter.js +41 -18
- package/package.json +35 -23
- package/templates/endpoints.ts.hbs +1 -1
- package/templates/enum.ts.hbs +2 -1
- package/templates/form-group-factory.ts.hbs +7 -1
- package/templates/form.ts.hbs +3 -1
- package/templates/index.ts.hbs +1 -1
- package/templates/model-properties.ts.hbs +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
17
|
+
export declare function getEnumDisplayText(data: IEnumValue[], lookupValue: number | string): string | 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;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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
|
+
*/
|
|
11
|
+
function getEnumKey(data, lookupValue) {
|
|
12
|
+
var _a;
|
|
13
|
+
return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.key;
|
|
14
|
+
}
|
|
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
|
+
*/
|
|
23
|
+
function getEnumDisplayText(data, lookupValue) {
|
|
24
|
+
var _a;
|
|
25
|
+
return (_a = getEnum(data, lookupValue)) === null || _a === void 0 ? void 0 : _a.displayText;
|
|
26
|
+
}
|
|
27
|
+
exports.getEnumDisplayText = getEnumDisplayText;
|
|
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; });
|
|
37
|
+
}
|
|
38
|
+
exports.getEnum = getEnum;
|
|
@@ -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 = {}));
|
package/enums/index.d.ts
ADDED
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<
|
|
19
|
+
axiosConfig?: AxiosRequestConfig<unknown>;
|
|
19
20
|
}
|
|
20
21
|
export interface ITemplates {
|
|
21
22
|
model?: string;
|
package/models/schema-info.d.ts
CHANGED
|
@@ -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';
|
package/models/schema-info.js
CHANGED
|
@@ -13,7 +13,8 @@ var SchemaWrapperInfo = /** @class */ (function () {
|
|
|
13
13
|
this.enumValues = [];
|
|
14
14
|
}
|
|
15
15
|
SchemaWrapperInfo.prototype.updateReferenceProperties = function (options) {
|
|
16
|
-
|
|
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;
|
package/openapidoc-converter.js
CHANGED
|
@@ -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
|
|
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.
|
|
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.
|
|
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,18 +206,21 @@ 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)
|
|
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 = ((
|
|
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 || ((
|
|
213
|
-
var refObject = (((
|
|
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
|
-
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) {
|
|
216
224
|
return "".concat(schemaWrapperInfo.propertyReferenceObject['$ref'], ".").concat(defaultValue.split(' ').pop());
|
|
217
225
|
}
|
|
218
226
|
else if (refObject) {
|
|
@@ -230,6 +238,12 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
230
238
|
else if (typescriptType === 'boolean') {
|
|
231
239
|
return 'false';
|
|
232
240
|
}
|
|
241
|
+
else if (typescriptType === 'number' && schemaObject.type === 'array') {
|
|
242
|
+
return minValue ? "[".concat(minValue, "]") : '[0]';
|
|
243
|
+
}
|
|
244
|
+
else if (schemaObject.type === 'array') {
|
|
245
|
+
return defaultValue ? "[".concat(defaultValue, "]") : '[]';
|
|
246
|
+
}
|
|
233
247
|
else if (typescriptType === 'number') {
|
|
234
248
|
return minValue ? "".concat(minValue) : '0';
|
|
235
249
|
}
|
|
@@ -242,7 +256,9 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
242
256
|
}
|
|
243
257
|
};
|
|
244
258
|
OpenApiDocConverter.prototype.convertArrayObjectToReferencePropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
|
|
245
|
-
|
|
259
|
+
var refProperty = __assign(__assign({}, this.convertReferenceObjectToPropertyType(parentTypeName, propertyName, schemaWrapperInfo)), { isArray: true });
|
|
260
|
+
refProperty.isEnumAndArray = refProperty.isEnum && refProperty.isArray;
|
|
261
|
+
return refProperty;
|
|
246
262
|
};
|
|
247
263
|
OpenApiDocConverter.prototype.convertReferenceObjectToPropertyType = function (parentTypeName, propertyName, schemaWrapperInfo) {
|
|
248
264
|
var _a, _b, _c;
|
|
@@ -250,7 +266,9 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
250
266
|
var refSchema = (((_b = schemaWrapperInfo === null || schemaWrapperInfo === void 0 ? void 0 : schemaWrapperInfo.componentSchemaObject) === null || _b === void 0 ? void 0 : _b.properties) || {})[propertyName];
|
|
251
267
|
var required = this.getIsRequired(propertyName, schemaWrapperInfo);
|
|
252
268
|
var validatorCount = this.getValidatorCount(propertyName, schemaWrapperInfo);
|
|
253
|
-
var initialValue = this.
|
|
269
|
+
var initialValue = this.options.genAngularFormGroupsWithDefaultValues
|
|
270
|
+
? this.getInitialValue(propertyName, schemaWrapperInfo)
|
|
271
|
+
: 'undefined';
|
|
254
272
|
var initialTestValue = this.getInitialTestValue(parentTypeName, propertyName, schemaWrapperInfo);
|
|
255
273
|
var typeName = this.parseRef(schemaWrapperInfo);
|
|
256
274
|
return {
|
|
@@ -264,6 +282,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
264
282
|
typeScriptType: typeName,
|
|
265
283
|
isArray: false,
|
|
266
284
|
isEnum: ((_c = propertySchema === null || propertySchema === void 0 ? void 0 : propertySchema.enum) !== null && _c !== void 0 ? _c : []).length > 0,
|
|
285
|
+
isEnumAndArray: false,
|
|
267
286
|
hasValidators: validatorCount > 0,
|
|
268
287
|
hasMultipleValidators: validatorCount > 1,
|
|
269
288
|
maxLength: refSchema === null || refSchema === void 0 ? void 0 : refSchema.maxLength,
|
|
@@ -291,8 +310,10 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
291
310
|
+this.convertValidator(schemaWrapperInfo.propertySchemaObject.pattern));
|
|
292
311
|
};
|
|
293
312
|
OpenApiDocConverter.prototype.getPropertyTypeScriptType = function (schemaWrapperInfo) {
|
|
313
|
+
var _a;
|
|
294
314
|
if (schemaWrapperInfo.propertySchemaObject.type === 'array' && schemaWrapperInfo.propertySchemaObject.items) {
|
|
295
|
-
|
|
315
|
+
var type = schemaWrapperInfo.propertySchemaObject.items.type;
|
|
316
|
+
return type === 'integer' ? 'number' : type;
|
|
296
317
|
}
|
|
297
318
|
else if (schemaWrapperInfo.propertySchemaObject.type === 'integer' && schemaWrapperInfo.propertySchemaObject.enum) {
|
|
298
319
|
return 'string | number';
|
|
@@ -303,7 +324,7 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
303
324
|
else if (schemaWrapperInfo.propertySchemaObject.format === 'date' || schemaWrapperInfo.propertySchemaObject.format === 'date-time') {
|
|
304
325
|
return 'Date';
|
|
305
326
|
}
|
|
306
|
-
return schemaWrapperInfo.propertySchemaObject.type
|
|
327
|
+
return (_a = schemaWrapperInfo.propertySchemaObject.type) !== null && _a !== void 0 ? _a : 'string';
|
|
307
328
|
};
|
|
308
329
|
OpenApiDocConverter.prototype.parseRef = function (schemaWrapperInfo) {
|
|
309
330
|
var regexResult;
|
|
@@ -318,9 +339,10 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
318
339
|
return result || 'unknown';
|
|
319
340
|
};
|
|
320
341
|
OpenApiDocConverter.prototype.getImportTypes = function (entityName, schemaWrapperInfo) {
|
|
321
|
-
var _this = this;
|
|
322
342
|
var _a;
|
|
323
|
-
var
|
|
343
|
+
var _this = this;
|
|
344
|
+
var _b, _c, _d;
|
|
345
|
+
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
346
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
325
347
|
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
348
|
return schemaWrapperInfo.referenceProperties
|
|
@@ -341,7 +363,8 @@ var OpenApiDocConverter = /** @class */ (function () {
|
|
|
341
363
|
});
|
|
342
364
|
};
|
|
343
365
|
OpenApiDocConverter.prototype.getIsRequired = function (propertyName, schemaWrapperInfo) {
|
|
344
|
-
|
|
366
|
+
var _a;
|
|
367
|
+
return ((((_a = schemaWrapperInfo.componentSchemaObject.required) !== null && _a !== void 0 ? _a : []).indexOf(propertyName) > -1 ||
|
|
345
368
|
(schemaWrapperInfo.propertySchemaObject.nullable === undefined ? false : !schemaWrapperInfo.propertySchemaObject.nullable)) &&
|
|
346
369
|
propertyName !== 'id');
|
|
347
370
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.55.5",
|
|
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
|
-
"build": "
|
|
20
|
+
"build": "tsc && cp -rfv ./src/templates ./lib",
|
|
9
21
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
10
22
|
"lint": "eslint . --ext .ts --output-file ./eslint-report.json --format json && eslint . --ext .ts --output-file ./eslint-report.html --format html ",
|
|
11
23
|
"link": "npm run build && cd lib && npm link && cd ..",
|
|
@@ -37,36 +49,36 @@
|
|
|
37
49
|
],
|
|
38
50
|
"homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
|
|
39
51
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "^
|
|
41
|
-
"@types/lodash": "^4.
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"@types/pluralize": "^0.0.
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
45
|
-
"@typescript-eslint/parser": "^
|
|
46
|
-
"eslint": "
|
|
47
|
-
"eslint-config-prettier": "^
|
|
48
|
-
"eslint-config-standard": "^17.
|
|
49
|
-
"eslint-plugin-import": "^2.
|
|
52
|
+
"@types/jest": "^29.5.14",
|
|
53
|
+
"@types/lodash": "^4.17.15",
|
|
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.31.0",
|
|
50
62
|
"eslint-plugin-node": "^11.1.0",
|
|
51
|
-
"eslint-plugin-promise": "^6.
|
|
52
|
-
"jest": "^
|
|
53
|
-
"jest-junit": "^
|
|
54
|
-
"openapi3-ts": "^
|
|
55
|
-
"prettier": "^
|
|
56
|
-
"rxjs": "^7.
|
|
57
|
-
"ts-jest": "^
|
|
58
|
-
"typescript": "^4.
|
|
63
|
+
"eslint-plugin-promise": "^6.6.0",
|
|
64
|
+
"jest": "^29.7.0",
|
|
65
|
+
"jest-junit": "^16.0.0",
|
|
66
|
+
"openapi3-ts": "^4.4.0",
|
|
67
|
+
"prettier": "^3.5.2",
|
|
68
|
+
"rxjs": "^7.6.0",
|
|
69
|
+
"ts-jest": "^29.2.6",
|
|
70
|
+
"typescript": "^4.9.5"
|
|
59
71
|
},
|
|
60
72
|
"dependencies": {
|
|
61
|
-
"axios": ">=
|
|
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": ">=
|
|
79
|
+
"axios": ">=1.x",
|
|
68
80
|
"handlebars": ">=4.x",
|
|
69
81
|
"lodash": ">=4.x",
|
|
70
|
-
"rxjs": "
|
|
82
|
+
"rxjs": "*"
|
|
71
83
|
}
|
|
72
84
|
}
|
package/templates/enum.ts.hbs
CHANGED
|
@@ -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}}
|
|
@@ -31,7 +31,13 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
|
|
|
31
31
|
{{/if}}
|
|
32
32
|
{{/valueProperties}}
|
|
33
33
|
{{#referenceProperties}}
|
|
34
|
-
{{#if
|
|
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}}
|
package/templates/form.ts.hbs
CHANGED
|
@@ -19,7 +19,9 @@ export interface I{{name}}Form {
|
|
|
19
19
|
{{/if}}
|
|
20
20
|
{{/valueProperties}}
|
|
21
21
|
{{#referenceProperties}}
|
|
22
|
-
{{#if
|
|
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}}>;
|
package/templates/index.ts.hbs
CHANGED