openapi-ts-generator 10.41.1 → 10.49.3
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 +1 -1
- package/enums/enum-helpers.js +3 -8
- package/enums/enum-properties.js +2 -5
- package/enums/enum-value.js +1 -2
- package/enums/index.d.ts +3 -3
- package/enums/index.js +3 -19
- package/generators/barrel.generator.d.ts +3 -3
- package/generators/barrel.generator.js +6 -10
- package/generators/base.generator.d.ts +3 -2
- package/generators/base.generator.js +6 -10
- package/generators/endpoints.generator.d.ts +3 -3
- package/generators/endpoints.generator.js +6 -10
- package/generators/enum.generator.d.ts +4 -4
- package/generators/enum.generator.js +4 -8
- package/generators/form-group-factory.generator.d.ts +5 -5
- package/generators/form-group-factory.generator.js +6 -43
- package/generators/form.generator.d.ts +4 -4
- package/generators/form.generator.js +4 -8
- package/generators/index.d.ts +8 -8
- package/generators/index.js +8 -24
- package/generators/model-properties.generator.d.ts +4 -4
- package/generators/model-properties.generator.js +4 -8
- package/generators/model.generator.d.ts +5 -4
- package/generators/model.generator.js +6 -9
- package/generators/test-object-factory.generator.d.ts +5 -4
- package/generators/test-object-factory.generator.js +5 -8
- package/index.d.ts +2 -2
- package/index.js +19 -61
- package/jest.setup.d.ts +1 -0
- package/jest.setup.js +4 -0
- package/models/entity.d.ts +4 -4
- package/models/entity.js +1 -2
- package/models/enum-value.js +1 -2
- package/models/generator-options.d.ts +4 -4
- package/models/generator-options.js +6 -8
- package/models/helper-context.d.ts +1 -1
- package/models/helper-context.js +1 -2
- package/models/logger.js +1 -5
- package/models/nrsrx-filters.d.ts +2 -2
- package/models/nrsrx-filters.js +2 -6
- package/models/reference-property.js +1 -2
- package/models/schema-info.d.ts +4 -4
- package/models/schema-info.js +3 -7
- package/models/template-data.d.ts +1 -1
- package/models/template-data.js +1 -2
- package/models/utils.d.ts +1 -0
- package/models/utils.js +6 -0
- package/models/value-property.js +1 -2
- package/openapidoc-converter.d.ts +6 -6
- package/openapidoc-converter.js +32 -33
- package/package.json +5 -2
- package/templates/form-group-factory.ts.hbs +4 -4
package/enums/enum-helpers.d.ts
CHANGED
package/enums/enum-helpers.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnumKey = getEnumKey;
|
|
4
|
-
exports.getEnumDisplayText = getEnumDisplayText;
|
|
5
|
-
exports.getEnum = getEnum;
|
|
6
1
|
/**
|
|
7
2
|
* Retrieves the key of an enum value from a list of enum values.
|
|
8
3
|
*
|
|
@@ -10,7 +5,7 @@ exports.getEnum = getEnum;
|
|
|
10
5
|
* @param lookupValue - The value to look up in the enum, which can be a number or a string.
|
|
11
6
|
* @returns The key of the enum value if found, otherwise `undefined`.
|
|
12
7
|
*/
|
|
13
|
-
function getEnumKey(data, lookupValue) {
|
|
8
|
+
export function getEnumKey(data, lookupValue) {
|
|
14
9
|
return getEnum(data, lookupValue)?.key;
|
|
15
10
|
}
|
|
16
11
|
/**
|
|
@@ -20,7 +15,7 @@ function getEnumKey(data, lookupValue) {
|
|
|
20
15
|
* @param lookupValue - The value to look up in the enum, which can be a number or a string.
|
|
21
16
|
* @returns The display text associated with the given enum value, or `undefined` if not found.
|
|
22
17
|
*/
|
|
23
|
-
function getEnumDisplayText(data, lookupValue) {
|
|
18
|
+
export function getEnumDisplayText(data, lookupValue) {
|
|
24
19
|
return getEnum(data, lookupValue)?.displayText;
|
|
25
20
|
}
|
|
26
21
|
/**
|
|
@@ -30,6 +25,6 @@ function getEnumDisplayText(data, lookupValue) {
|
|
|
30
25
|
* @param lookupValue - The value to look up, which can be either a number or a string.
|
|
31
26
|
* @returns The matching enum value, or `undefined` if no match is found.
|
|
32
27
|
*/
|
|
33
|
-
function getEnum(data, lookupValue) {
|
|
28
|
+
export function getEnum(data, lookupValue) {
|
|
34
29
|
return data.find((f) => f.name === lookupValue || f.key === lookupValue);
|
|
35
30
|
}
|
package/enums/enum-properties.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnumProperties = void 0;
|
|
4
|
-
var EnumProperties;
|
|
1
|
+
export var EnumProperties;
|
|
5
2
|
(function (EnumProperties) {
|
|
6
3
|
EnumProperties["KEY"] = "key";
|
|
7
4
|
EnumProperties["NAME"] = "name";
|
|
8
5
|
EnumProperties["DISPLAY_TEXT"] = "displayText";
|
|
9
|
-
})(EnumProperties || (
|
|
6
|
+
})(EnumProperties || (EnumProperties = {}));
|
package/enums/enum-value.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/enums/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './enum-value';
|
|
2
|
-
export * from './enum-properties';
|
|
3
|
-
export * from './enum-helpers';
|
|
1
|
+
export * from './enum-value.ts';
|
|
2
|
+
export * from './enum-properties.ts';
|
|
3
|
+
export * from './enum-helpers.ts';
|
package/enums/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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);
|
|
1
|
+
export * from "./enum-value.js";
|
|
2
|
+
export * from "./enum-properties.js";
|
|
3
|
+
export * from "./enum-helpers.js";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
3
3
|
export declare class BarrelGenerator extends BaseGenerator<{
|
|
4
4
|
fileNames: string[];
|
|
5
5
|
}> {
|
|
6
6
|
readonly GeneratorName = "BarrelGenerator";
|
|
7
7
|
private readonly tsRegex;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(generatorOptions: IGeneratorOptions);
|
|
9
9
|
generate(): string | null;
|
|
10
10
|
}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BarrelGenerator extends base_generator_1.BaseGenerator {
|
|
7
|
-
constructor(options) {
|
|
8
|
-
super(options, options.templates?.barrel);
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class BarrelGenerator extends BaseGenerator {
|
|
4
|
+
constructor(generatorOptions) {
|
|
5
|
+
super(generatorOptions, generatorOptions.templates?.barrel);
|
|
9
6
|
this.GeneratorName = 'BarrelGenerator';
|
|
10
7
|
this.tsRegex = /.ts$/;
|
|
11
8
|
}
|
|
12
9
|
generate() {
|
|
13
|
-
let fileNames =
|
|
10
|
+
let fileNames = readdirSync(this.generatorOptions.outputPath).map((value) => value.replace(this.tsRegex, ''));
|
|
14
11
|
fileNames = fileNames.filter((x) => x !== 'endpoints');
|
|
15
12
|
return super.generateFile(`${this.generatorOptions.outputPath}/index.ts`, fileNames.length ? { fileNames } : null);
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.BarrelGenerator = BarrelGenerator;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import handlebars from 'handlebars';
|
|
2
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
3
|
export declare abstract class BaseGenerator<TContextSchema> {
|
|
3
4
|
readonly generatorOptions: IGeneratorOptions;
|
|
4
5
|
readonly templateFilePath: string | undefined;
|
|
5
6
|
abstract readonly GeneratorName: string;
|
|
6
|
-
readonly template?:
|
|
7
|
+
readonly template?: handlebars.TemplateDelegate<TContextSchema>;
|
|
7
8
|
readonly emptyArrayRegex: RegExp;
|
|
8
9
|
constructor(generatorOptions: IGeneratorOptions, templateFilePath: string | undefined);
|
|
9
10
|
protected generateFile(outputFilePath: string, context: TContextSchema | null): string | null;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const handlebars_1 = require("handlebars");
|
|
6
|
-
class BaseGenerator {
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import handlebars from 'handlebars';
|
|
3
|
+
export class BaseGenerator {
|
|
7
4
|
constructor(generatorOptions, templateFilePath) {
|
|
8
5
|
this.generatorOptions = generatorOptions;
|
|
9
6
|
this.templateFilePath = templateFilePath;
|
|
10
7
|
this.emptyArrayRegex = /, ]/g;
|
|
11
8
|
if (templateFilePath) {
|
|
12
|
-
const templateSource =
|
|
13
|
-
this.template =
|
|
9
|
+
const templateSource = readFileSync(templateFilePath, { encoding: 'utf8' });
|
|
10
|
+
this.template = handlebars.compile(templateSource);
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
13
|
generateFile(outputFilePath, context) {
|
|
@@ -23,7 +20,7 @@ class BaseGenerator {
|
|
|
23
20
|
else {
|
|
24
21
|
try {
|
|
25
22
|
const content = this.template(context).replace(this.emptyArrayRegex, ']');
|
|
26
|
-
|
|
23
|
+
writeFileSync(outputFilePath, content, { encoding: 'utf8' });
|
|
27
24
|
return content;
|
|
28
25
|
}
|
|
29
26
|
catch (err) {
|
|
@@ -38,4 +35,3 @@ class BaseGenerator {
|
|
|
38
35
|
return null;
|
|
39
36
|
}
|
|
40
37
|
}
|
|
41
|
-
exports.BaseGenerator = BaseGenerator;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { IPath, ITemplateData } from '../models/template-data';
|
|
3
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { IPath, ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
4
4
|
export declare class EndPointsGenerator extends BaseGenerator<{
|
|
5
5
|
paths: IPath[];
|
|
6
6
|
}> {
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const base_generator_1 = require("./base.generator");
|
|
5
|
-
const lodash_1 = require("lodash");
|
|
6
|
-
class EndPointsGenerator extends base_generator_1.BaseGenerator {
|
|
1
|
+
import lodash from 'lodash';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class EndPointsGenerator extends BaseGenerator {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super(options, options.templates?.endpoints);
|
|
9
6
|
this.GeneratorName = 'EndPointsGenerator';
|
|
10
|
-
this.endpointIdentifierRegex = /[A-z0-9_-]*$/;
|
|
7
|
+
this.endpointIdentifierRegex = /[A-Za-z0-9_-]*$/;
|
|
11
8
|
}
|
|
12
9
|
generate(templateData) {
|
|
13
10
|
const paths = this.eliminateDupes(templateData);
|
|
@@ -17,13 +14,13 @@ class EndPointsGenerator extends base_generator_1.BaseGenerator {
|
|
|
17
14
|
const sortedTemplateData = [...templateData.paths].sort((x, y) => (x.endpoint.toUpperCase() < y.endpoint.toUpperCase() ? -1 : 1));
|
|
18
15
|
const result = [];
|
|
19
16
|
sortedTemplateData.forEach((val) => {
|
|
20
|
-
val = { ...val, tag:
|
|
17
|
+
val = { ...val, tag: lodash.camelCase(val.tag) };
|
|
21
18
|
const dupeIndex = result.findIndex((f) => f.tag === val.tag);
|
|
22
19
|
if (dupeIndex > -1) {
|
|
23
20
|
const dupeCount = result.filter((f) => f.tag === val.tag).length + 1;
|
|
24
21
|
const endpointIdentifier = (this.endpointIdentifierRegex.exec(val.endpoint) || [])[0];
|
|
25
22
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
26
|
-
result.push({ ...val, tag:
|
|
23
|
+
result.push({ ...val, tag: lodash.camelCase(`${val.tag}_${endpointIdentifier || dupeCount}`) });
|
|
27
24
|
}
|
|
28
25
|
else {
|
|
29
26
|
result.push(val);
|
|
@@ -32,4 +29,3 @@ class EndPointsGenerator extends base_generator_1.BaseGenerator {
|
|
|
32
29
|
return result;
|
|
33
30
|
}
|
|
34
31
|
}
|
|
35
|
-
exports.EndPointsGenerator = EndPointsGenerator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
|
-
import { IEntity } from '../models/entity';
|
|
4
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { IEntity } from '../models/entity.ts';
|
|
4
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
5
5
|
export declare class EnumGenerator extends BaseGenerator<IEntity> {
|
|
6
6
|
readonly GeneratorName = "EnumGenerator";
|
|
7
7
|
constructor(options: IGeneratorOptions);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const base_generator_1 = require("./base.generator");
|
|
6
|
-
class EnumGenerator extends base_generator_1.BaseGenerator {
|
|
1
|
+
import lodash from 'lodash';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class EnumGenerator extends BaseGenerator {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super(options, options.templates?.enum);
|
|
9
6
|
this.GeneratorName = 'EnumGenerator';
|
|
@@ -12,8 +9,7 @@ class EnumGenerator extends base_generator_1.BaseGenerator {
|
|
|
12
9
|
templateData.entities
|
|
13
10
|
?.filter((entity) => entity.isEnum)
|
|
14
11
|
.forEach((entity) => {
|
|
15
|
-
super.generateFile(`${this.generatorOptions.outputPath}/${
|
|
12
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${lodash.kebabCase(entity.name)}.enum.ts`, entity);
|
|
16
13
|
});
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.EnumGenerator = EnumGenerator;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
|
-
import { IEntity } from '../models/entity';
|
|
4
|
-
import { BaseGenerator } from './base.generator';
|
|
5
|
-
import { IHelperContext, PropertyType } from '../models/helper-context';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { IEntity } from '../models/entity.ts';
|
|
4
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
5
|
+
import { IHelperContext, PropertyType } from '../models/helper-context.ts';
|
|
6
6
|
export declare class FormGroupFactoryGenerator extends BaseGenerator<IEntity> {
|
|
7
7
|
readonly GeneratorName = "FormGroupFactoryGenerator";
|
|
8
8
|
constructor(options: IGeneratorOptions);
|
|
@@ -1,44 +1,8 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.FormGroupFactoryGenerator = void 0;
|
|
37
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class FormGroupFactoryGenerator extends
|
|
2
|
+
import handlebars from 'handlebars';
|
|
3
|
+
import lodash from 'lodash';
|
|
4
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
5
|
+
export class FormGroupFactoryGenerator extends BaseGenerator {
|
|
42
6
|
constructor(options) {
|
|
43
7
|
super(options, options.templates?.formGroupFactory);
|
|
44
8
|
this.GeneratorName = 'FormGroupFactoryGenerator';
|
|
@@ -48,7 +12,7 @@ class FormGroupFactoryGenerator extends base_generator_1.BaseGenerator {
|
|
|
48
12
|
templateData.entities
|
|
49
13
|
?.filter((val) => val.valueProperties?.length + val.referenceProperties?.length > 0)
|
|
50
14
|
.forEach((entity) => {
|
|
51
|
-
super.generateFile(`${this.generatorOptions.outputPath}/${
|
|
15
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${lodash.kebabCase(entity.name)}.form-group-fac.ts`, entity);
|
|
52
16
|
});
|
|
53
17
|
}
|
|
54
18
|
registerHelpers() {
|
|
@@ -61,7 +25,7 @@ class FormGroupFactoryGenerator extends base_generator_1.BaseGenerator {
|
|
|
61
25
|
this.registerValidatorHelper('pattern');
|
|
62
26
|
}
|
|
63
27
|
registerValidatorHelper(validatorName, angularValidatorName = validatorName) {
|
|
64
|
-
|
|
28
|
+
handlebars.registerHelper(`${validatorName}Validator`, (x, y) => this.validatorFactory(x, y, validatorName, angularValidatorName));
|
|
65
29
|
}
|
|
66
30
|
validatorFactory(propertyCollection, propertyContext, validationName, angularValidatorFunctionName) {
|
|
67
31
|
const props = propertyContext.data.root[propertyCollection];
|
|
@@ -76,4 +40,3 @@ class FormGroupFactoryGenerator extends base_generator_1.BaseGenerator {
|
|
|
76
40
|
return '';
|
|
77
41
|
}
|
|
78
42
|
}
|
|
79
|
-
exports.FormGroupFactoryGenerator = FormGroupFactoryGenerator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
|
-
import { IEntity } from '../models/entity';
|
|
4
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { IEntity } from '../models/entity.ts';
|
|
4
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
5
5
|
export declare class FormGenerator extends BaseGenerator<IEntity> {
|
|
6
6
|
readonly GeneratorName = "FormGenerator";
|
|
7
7
|
constructor(options: IGeneratorOptions);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FormGenerator = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class FormGenerator extends
|
|
2
|
+
import lodash from 'lodash';
|
|
3
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
4
|
+
export class FormGenerator extends BaseGenerator {
|
|
8
5
|
constructor(options) {
|
|
9
6
|
super(options, options.templates?.form);
|
|
10
7
|
this.GeneratorName = 'FormGenerator';
|
|
@@ -13,8 +10,7 @@ class FormGenerator extends base_generator_1.BaseGenerator {
|
|
|
13
10
|
templateData.entities
|
|
14
11
|
?.filter((val) => val.valueProperties?.length + val.referenceProperties?.length > 0)
|
|
15
12
|
.forEach((entity) => {
|
|
16
|
-
super.generateFile(`${this.generatorOptions.outputPath}/${
|
|
13
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${lodash.kebabCase(entity.name)}.form.ts`, entity);
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.FormGenerator = FormGenerator;
|
package/generators/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './model.generator';
|
|
2
|
-
export * from './form-group-factory.generator';
|
|
3
|
-
export * from './model-properties.generator';
|
|
4
|
-
export * from './barrel.generator';
|
|
5
|
-
export * from './enum.generator';
|
|
6
|
-
export * from './form.generator';
|
|
7
|
-
export * from './test-object-factory.generator';
|
|
8
|
-
export * from './endpoints.generator';
|
|
1
|
+
export * from './model.generator.ts';
|
|
2
|
+
export * from './form-group-factory.generator.ts';
|
|
3
|
+
export * from './model-properties.generator.ts';
|
|
4
|
+
export * from './barrel.generator.ts';
|
|
5
|
+
export * from './enum.generator.ts';
|
|
6
|
+
export * from './form.generator.ts';
|
|
7
|
+
export * from './test-object-factory.generator.ts';
|
|
8
|
+
export * from './endpoints.generator.ts';
|
package/generators/index.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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("./model.generator"), exports);
|
|
18
|
-
__exportStar(require("./form-group-factory.generator"), exports);
|
|
19
|
-
__exportStar(require("./model-properties.generator"), exports);
|
|
20
|
-
__exportStar(require("./barrel.generator"), exports);
|
|
21
|
-
__exportStar(require("./enum.generator"), exports);
|
|
22
|
-
__exportStar(require("./form.generator"), exports);
|
|
23
|
-
__exportStar(require("./test-object-factory.generator"), exports);
|
|
24
|
-
__exportStar(require("./endpoints.generator"), exports);
|
|
1
|
+
export * from "./model.generator.js";
|
|
2
|
+
export * from "./form-group-factory.generator.js";
|
|
3
|
+
export * from "./model-properties.generator.js";
|
|
4
|
+
export * from "./barrel.generator.js";
|
|
5
|
+
export * from "./enum.generator.js";
|
|
6
|
+
export * from "./form.generator.js";
|
|
7
|
+
export * from "./test-object-factory.generator.js";
|
|
8
|
+
export * from "./endpoints.generator.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
|
-
import { IEntity } from '../models/entity';
|
|
4
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { IEntity } from '../models/entity.ts';
|
|
4
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
5
5
|
export declare class ModelPropertiesGenerator extends BaseGenerator<IEntity> {
|
|
6
6
|
readonly GeneratorName = "ModelPropertiesGenerator";
|
|
7
7
|
constructor(options: IGeneratorOptions);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelPropertiesGenerator = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ModelPropertiesGenerator extends
|
|
2
|
+
import lodash from 'lodash';
|
|
3
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
4
|
+
export class ModelPropertiesGenerator extends BaseGenerator {
|
|
8
5
|
constructor(options) {
|
|
9
6
|
super(options, options.templates?.modelProperties);
|
|
10
7
|
this.GeneratorName = 'ModelPropertiesGenerator';
|
|
@@ -14,8 +11,7 @@ class ModelPropertiesGenerator extends base_generator_1.BaseGenerator {
|
|
|
14
11
|
?.filter((entity) => !entity.isEnum)
|
|
15
12
|
.filter((val) => val.valueProperties?.length > 0 || val.referenceProperties?.length > 0)
|
|
16
13
|
.forEach((entity) => {
|
|
17
|
-
super.generateFile(`${this.generatorOptions.outputPath}/${
|
|
14
|
+
super.generateFile(`${this.generatorOptions.outputPath}/${lodash.kebabCase(entity.name)}.properties.ts`, entity);
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
|
-
exports.ModelPropertiesGenerator = ModelPropertiesGenerator;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
|
-
import { IEntity } from '../models/entity';
|
|
4
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { IEntity } from '../models/entity.ts';
|
|
4
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
5
5
|
export declare class ModelGenerator extends BaseGenerator<IEntity> {
|
|
6
|
+
private readonly options;
|
|
6
7
|
readonly GeneratorName = "ModelGenerator";
|
|
7
8
|
constructor(options: IGeneratorOptions);
|
|
8
9
|
generate(templateData: ITemplateData): void;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const base_generator_1 = require("./base.generator");
|
|
6
|
-
class ModelGenerator extends base_generator_1.BaseGenerator {
|
|
1
|
+
import lodash from 'lodash';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class ModelGenerator extends BaseGenerator {
|
|
7
4
|
constructor(options) {
|
|
8
5
|
super(options, options.genClasses ? options.templates?.entity : options.templates?.model);
|
|
6
|
+
this.options = options;
|
|
9
7
|
this.GeneratorName = 'ModelGenerator';
|
|
10
8
|
}
|
|
11
9
|
generate(templateData) {
|
|
12
|
-
const fileSuffix = this.
|
|
10
|
+
const fileSuffix = this.options.genClasses ? '.entity.ts' : '.model.ts';
|
|
13
11
|
templateData.entities
|
|
14
12
|
?.filter((entity) => !entity.isEnum)
|
|
15
13
|
.forEach((entity) => {
|
|
16
|
-
super.generateFile(`${this.
|
|
14
|
+
super.generateFile(`${this.options.outputPath}/${lodash.kebabCase(entity.name)}${fileSuffix}`, entity);
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
exports.ModelGenerator = ModelGenerator;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
2
|
-
import { ITemplateData } from '../models/template-data';
|
|
3
|
-
import { IEntity } from '../models/entity';
|
|
4
|
-
import { BaseGenerator } from './base.generator';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
|
+
import { ITemplateData } from '../models/template-data.ts';
|
|
3
|
+
import { IEntity } from '../models/entity.ts';
|
|
4
|
+
import { BaseGenerator } from './base.generator.ts';
|
|
5
5
|
export declare class TestObjectFactoryGenerator extends BaseGenerator<IEntity> {
|
|
6
|
+
private readonly options;
|
|
6
7
|
readonly GeneratorName = "TestObjectFactoryGenerator";
|
|
7
8
|
constructor(options: IGeneratorOptions);
|
|
8
9
|
generate(templateData: ITemplateData): void;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const base_generator_1 = require("./base.generator");
|
|
7
|
-
class TestObjectFactoryGenerator extends base_generator_1.BaseGenerator {
|
|
2
|
+
import lodash from 'lodash';
|
|
3
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
4
|
+
export class TestObjectFactoryGenerator extends BaseGenerator {
|
|
8
5
|
constructor(options) {
|
|
9
6
|
super(options, options.templates?.testObjectFactory);
|
|
7
|
+
this.options = options;
|
|
10
8
|
this.GeneratorName = 'TestObjectFactoryGenerator';
|
|
11
9
|
}
|
|
12
10
|
generate(templateData) {
|
|
13
11
|
templateData.entities
|
|
14
12
|
?.filter((val) => val.valueProperties?.length + val.referenceProperties?.length > 0)
|
|
15
13
|
.forEach((entity) => {
|
|
16
|
-
super.generateFile(`${this.
|
|
14
|
+
super.generateFile(`${this.options.outputPath}/${lodash.kebabCase(entity.name)}.test-obj-fac.ts`, entity);
|
|
17
15
|
});
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
|
-
exports.TestObjectFactoryGenerator = TestObjectFactoryGenerator;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { IGeneratorOptions } from './models/generator-options';
|
|
2
|
-
export { nrsrxTypeFilterCallBack, nrsrxValuePropertyTypeFilterCallBack } from './models/nrsrx-filters';
|
|
1
|
+
import { IGeneratorOptions } from './models/generator-options.ts';
|
|
2
|
+
export { nrsrxTypeFilterCallBack, nrsrxValuePropertyTypeFilterCallBack } from './models/nrsrx-filters.ts';
|
|
3
3
|
export declare function generateTsModels(options: IGeneratorOptions): Promise<void>;
|
package/index.js
CHANGED
|
@@ -1,62 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.nrsrxValuePropertyTypeFilterCallBack = exports.nrsrxTypeFilterCallBack = void 0;
|
|
40
|
-
exports.generateTsModels = generateTsModels;
|
|
41
|
-
const fs = __importStar(require("node:fs"));
|
|
42
|
-
const generators_1 = require("./generators");
|
|
43
|
-
const generator_options_1 = require("./models/generator-options");
|
|
44
|
-
const openapidoc_converter_1 = require("./openapidoc-converter");
|
|
45
|
-
const axios_1 = __importDefault(require("axios"));
|
|
46
|
-
var nrsrx_filters_1 = require("./models/nrsrx-filters");
|
|
47
|
-
Object.defineProperty(exports, "nrsrxTypeFilterCallBack", { enumerable: true, get: function () { return nrsrx_filters_1.nrsrxTypeFilterCallBack; } });
|
|
48
|
-
Object.defineProperty(exports, "nrsrxValuePropertyTypeFilterCallBack", { enumerable: true, get: function () { return nrsrx_filters_1.nrsrxValuePropertyTypeFilterCallBack; } });
|
|
49
|
-
async function generateTsModels(options) {
|
|
50
|
-
options = (0, generator_options_1.setGeneratorOptionDefaults)(options);
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import { FormGenerator, EndPointsGenerator, BarrelGenerator, FormGroupFactoryGenerator, ModelGenerator, ModelPropertiesGenerator, EnumGenerator, TestObjectFactoryGenerator, } from "./generators/index.js";
|
|
3
|
+
import { setGeneratorOptionDefaults } from "./models/generator-options.js";
|
|
4
|
+
import { OpenApiDocConverter } from "./openapidoc-converter.js";
|
|
5
|
+
import Axios from 'axios';
|
|
6
|
+
export { nrsrxTypeFilterCallBack, nrsrxValuePropertyTypeFilterCallBack } from "./models/nrsrx-filters.js";
|
|
7
|
+
export async function generateTsModels(options) {
|
|
8
|
+
options = setGeneratorOptionDefaults(options);
|
|
51
9
|
const apiDocument = await getOpenApiDocumentAsync(options);
|
|
52
|
-
const converter = new
|
|
10
|
+
const converter = new OpenApiDocConverter(options, apiDocument);
|
|
53
11
|
const templateData = converter.convertDocument();
|
|
54
12
|
generateOutput(options, templateData);
|
|
55
13
|
}
|
|
56
14
|
async function getOpenApiDocumentAsync(options) {
|
|
57
15
|
let apiDoc;
|
|
58
16
|
if (options.openApiJsonUrl) {
|
|
59
|
-
const response = await
|
|
17
|
+
const response = await Axios.get(options.openApiJsonUrl, options.axiosConfig);
|
|
60
18
|
apiDoc = response.data;
|
|
61
19
|
}
|
|
62
20
|
else if (options.openApiJsonFileName) {
|
|
@@ -73,25 +31,25 @@ function generateOutput(options, templateData) {
|
|
|
73
31
|
fs.readdirSync(options.outputPath).forEach((file) => {
|
|
74
32
|
fs.unlinkSync(`${options.outputPath}/${file}`);
|
|
75
33
|
});
|
|
76
|
-
fs.
|
|
34
|
+
fs.rmSync(options.outputPath, { recursive: true });
|
|
77
35
|
}
|
|
78
36
|
fs.mkdirSync(options.outputPath, { recursive: true });
|
|
79
|
-
const modelGenerator = new
|
|
37
|
+
const modelGenerator = new ModelGenerator(options);
|
|
80
38
|
modelGenerator.generate(templateData);
|
|
81
39
|
if (options.genAngularFormGroups) {
|
|
82
|
-
const formGroupGenerator = new
|
|
40
|
+
const formGroupGenerator = new FormGroupFactoryGenerator(options);
|
|
83
41
|
formGroupGenerator.generate(templateData);
|
|
84
|
-
const formGenerator = new
|
|
42
|
+
const formGenerator = new FormGenerator(options);
|
|
85
43
|
formGenerator.generate(templateData);
|
|
86
44
|
}
|
|
87
|
-
const modelPropertiesGenerator = new
|
|
45
|
+
const modelPropertiesGenerator = new ModelPropertiesGenerator(options);
|
|
88
46
|
modelPropertiesGenerator.generate(templateData);
|
|
89
|
-
const endpointGenerator = new
|
|
47
|
+
const endpointGenerator = new EndPointsGenerator(options);
|
|
90
48
|
endpointGenerator.generate(templateData);
|
|
91
|
-
const barrelGenerator = new
|
|
92
|
-
const enumGenerator = new
|
|
49
|
+
const barrelGenerator = new BarrelGenerator(options);
|
|
50
|
+
const enumGenerator = new EnumGenerator(options);
|
|
93
51
|
enumGenerator.generate(templateData);
|
|
94
|
-
const testObjFacGenerator = new
|
|
52
|
+
const testObjFacGenerator = new TestObjectFactoryGenerator(options);
|
|
95
53
|
testObjFacGenerator.generate(templateData);
|
|
96
54
|
barrelGenerator.generate();
|
|
97
55
|
}
|
package/jest.setup.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/jest.setup.js
ADDED
package/models/entity.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IReferenceProperty } from './reference-property';
|
|
2
|
-
import { IValueProperty } from './value-property';
|
|
3
|
-
import { IImportType } from './template-data';
|
|
4
|
-
import { IEnumValue } from './enum-value';
|
|
1
|
+
import { IReferenceProperty } from './reference-property.ts';
|
|
2
|
+
import { IValueProperty } from './value-property.ts';
|
|
3
|
+
import { IImportType } from './template-data.ts';
|
|
4
|
+
import { IEnumValue } from './enum-value.ts';
|
|
5
5
|
export interface IEntity {
|
|
6
6
|
isEnum?: boolean;
|
|
7
7
|
isCharEnum: boolean;
|
package/models/entity.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/models/enum-value.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ILogger } from './logger';
|
|
2
|
-
import { IEntity } from './entity';
|
|
3
|
-
import { IReferenceProperty } from './reference-property';
|
|
4
|
-
import { IValueProperty } from './value-property';
|
|
1
|
+
import { ILogger } from './logger.ts';
|
|
2
|
+
import { IEntity } from './entity.ts';
|
|
3
|
+
import { IReferenceProperty } from './reference-property.ts';
|
|
4
|
+
import { IValueProperty } from './value-property.ts';
|
|
5
5
|
import { AxiosRequestConfig } from 'axios';
|
|
6
6
|
export interface IGeneratorOptions {
|
|
7
7
|
logger?: ILogger;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultFilter = defaultFilter;
|
|
4
|
-
exports.setGeneratorOptionDefaults = setGeneratorOptionDefaults;
|
|
5
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { resolve, } from 'node:path';
|
|
3
|
+
import { getDirName } from "./utils.js";
|
|
4
|
+
export function defaultFilter(_value, _index, _array) {
|
|
8
5
|
return true;
|
|
9
6
|
}
|
|
10
|
-
function setGeneratorOptionDefaults(options) {
|
|
11
|
-
const
|
|
7
|
+
export function setGeneratorOptionDefaults(options) {
|
|
8
|
+
const __dirname = getDirName();
|
|
9
|
+
const templateFolder = resolve(`${__dirname}/..`, 'templates');
|
|
12
10
|
options.typeFilterCallBack = options.typeFilterCallBack ?? defaultFilter;
|
|
13
11
|
options.valuePropertyTypeFilterCallBack = options.valuePropertyTypeFilterCallBack ?? defaultFilter;
|
|
14
12
|
options.referencePropertyTypeFilterCallBack = options.referencePropertyTypeFilterCallBack ?? defaultFilter;
|
package/models/helper-context.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/models/logger.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockConsoleLogger = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
|
-
class MockConsoleLogger {
|
|
2
|
+
export class MockConsoleLogger {
|
|
6
3
|
constructor() {
|
|
7
4
|
this.log = (data) => { };
|
|
8
5
|
this.error = (data) => { };
|
|
9
6
|
this.warn = (data) => { };
|
|
10
7
|
}
|
|
11
8
|
}
|
|
12
|
-
exports.MockConsoleLogger = MockConsoleLogger;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IEntity } from './entity';
|
|
2
|
-
import { IValueProperty } from './value-property';
|
|
1
|
+
import { IEntity } from './entity.ts';
|
|
2
|
+
import { IValueProperty } from './value-property.ts';
|
|
3
3
|
export declare function nrsrxTypeFilterCallBack(val: IEntity, _i: number, _arr: IEntity[]): boolean;
|
|
4
4
|
export declare function nrsrxValuePropertyTypeFilterCallBack(val: IValueProperty, _i: number, _arr: IValueProperty[]): boolean;
|
package/models/nrsrx-filters.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nrsrxTypeFilterCallBack = nrsrxTypeFilterCallBack;
|
|
4
|
-
exports.nrsrxValuePropertyTypeFilterCallBack = nrsrxValuePropertyTypeFilterCallBack;
|
|
5
1
|
const edmRegex = /^Edm[A-z]*Kind$/;
|
|
6
|
-
function nrsrxTypeFilterCallBack(val, _i, _arr) {
|
|
2
|
+
export function nrsrxTypeFilterCallBack(val, _i, _arr) {
|
|
7
3
|
return !val.name.endsWith('ODataEnvelope') && !edmRegex.test(val.name);
|
|
8
4
|
}
|
|
9
|
-
function nrsrxValuePropertyTypeFilterCallBack(val, _i, _arr) {
|
|
5
|
+
export function nrsrxValuePropertyTypeFilterCallBack(val, _i, _arr) {
|
|
10
6
|
return !val.name.startsWith('created') && !val.name.startsWith('updated');
|
|
11
7
|
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/models/schema-info.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ReferenceObject, SchemaObject } from 'openapi3-ts/oas31';
|
|
2
|
-
import { IEnumValue } from './enum-value';
|
|
3
|
-
import { IGeneratorOptions } from './generator-options';
|
|
4
|
-
import { IReferenceProperty } from './reference-property';
|
|
5
|
-
import { IValueProperty } from './value-property';
|
|
2
|
+
import { IEnumValue } from './enum-value.ts';
|
|
3
|
+
import { IGeneratorOptions } from './generator-options.ts';
|
|
4
|
+
import { IReferenceProperty } from './reference-property.ts';
|
|
5
|
+
import { IValueProperty } from './value-property.ts';
|
|
6
6
|
export declare class SchemaWrapperInfo {
|
|
7
7
|
propertySchemaObject: SchemaObject;
|
|
8
8
|
propertyReferenceObject: ReferenceObject;
|
package/models/schema-info.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SchemaWrapperInfo = void 0;
|
|
4
|
-
const generator_options_1 = require("./generator-options");
|
|
5
|
-
class SchemaWrapperInfo {
|
|
1
|
+
import { defaultFilter } from "./generator-options.js";
|
|
2
|
+
export class SchemaWrapperInfo {
|
|
6
3
|
constructor(schemaItem) {
|
|
7
4
|
this.propertySchemaObject = {};
|
|
8
5
|
this.propertyReferenceObject = { $ref: '' };
|
|
@@ -14,7 +11,6 @@ class SchemaWrapperInfo {
|
|
|
14
11
|
this.enumValues = [];
|
|
15
12
|
}
|
|
16
13
|
updateReferenceProperties(options) {
|
|
17
|
-
this.referenceProperties = this.referenceProperties.filter(options.referencePropertyTypeFilterCallBack ??
|
|
14
|
+
this.referenceProperties = this.referenceProperties.filter(options.referencePropertyTypeFilterCallBack ?? defaultFilter);
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
exports.SchemaWrapperInfo = SchemaWrapperInfo;
|
package/models/template-data.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDirName: () => string;
|
package/models/utils.js
ADDED
package/models/value-property.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { IGeneratorOptions } from './models/generator-options';
|
|
2
|
-
import { SchemaWrapperInfo } from './models/schema-info';
|
|
3
|
-
import { IImportType, IPath, ITemplateData } from './models/template-data';
|
|
4
|
-
import { IEntity } from './models/entity';
|
|
5
|
-
import { IReferenceProperty } from './models/reference-property';
|
|
6
|
-
import { IValueProperty } from './models/value-property';
|
|
7
1
|
import { OpenAPIObject } from 'openapi3-ts/oas31';
|
|
2
|
+
import { IGeneratorOptions } from './models/generator-options.ts';
|
|
3
|
+
import { SchemaWrapperInfo } from './models/schema-info.ts';
|
|
4
|
+
import { IImportType, IPath, ITemplateData } from './models/template-data.ts';
|
|
5
|
+
import { IEntity } from './models/entity.ts';
|
|
6
|
+
import { IReferenceProperty } from './models/reference-property.ts';
|
|
7
|
+
import { IValueProperty } from './models/value-property.ts';
|
|
8
8
|
export declare class OpenApiDocConverter {
|
|
9
9
|
private readonly options;
|
|
10
10
|
private readonly apiDocument;
|
package/openapidoc-converter.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenApiDocConverter = void 0;
|
|
4
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-type-conversion */
|
|
5
2
|
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
6
3
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class OpenApiDocConverter {
|
|
4
|
+
import pluralize from 'pluralize';
|
|
5
|
+
import lodash from 'lodash';
|
|
6
|
+
import { defaultFilter } from "./models/generator-options.js";
|
|
7
|
+
import { SchemaWrapperInfo } from "./models/schema-info.js";
|
|
8
|
+
export class OpenApiDocConverter {
|
|
12
9
|
constructor(options, apiDocument) {
|
|
13
10
|
this.options = options;
|
|
14
11
|
this.apiDocument = apiDocument;
|
|
@@ -28,7 +25,7 @@ class OpenApiDocConverter {
|
|
|
28
25
|
tagLookup = tagLookup || path.delete || path.patch;
|
|
29
26
|
const tag = (tagLookup?.tags || ['unknown_endpoint'])[0];
|
|
30
27
|
paths.push({
|
|
31
|
-
tag:
|
|
28
|
+
tag: lodash.snakeCase(tag),
|
|
32
29
|
endpoint: this.options.pathUrlFormattingCallBack ? this.options.pathUrlFormattingCallBack(key) : key,
|
|
33
30
|
});
|
|
34
31
|
}
|
|
@@ -38,7 +35,7 @@ class OpenApiDocConverter {
|
|
|
38
35
|
const entities = [];
|
|
39
36
|
for (const schemaName in this.apiDocument.components?.schemas) {
|
|
40
37
|
if (this.apiDocument.components.schemas[schemaName]) {
|
|
41
|
-
const schemaWrapperInfo = new
|
|
38
|
+
const schemaWrapperInfo = new SchemaWrapperInfo(this.apiDocument.components?.schemas[schemaName]);
|
|
42
39
|
if (schemaWrapperInfo.componentSchemaObject.enum) {
|
|
43
40
|
this.buildSchemaWrapperInfoForEnum(schemaWrapperInfo);
|
|
44
41
|
}
|
|
@@ -56,40 +53,43 @@ class OpenApiDocConverter {
|
|
|
56
53
|
key: schemaWrapperInfo.isCharEnum ? t.key : +t.key,
|
|
57
54
|
}),
|
|
58
55
|
name: schemaName,
|
|
59
|
-
kebabCasedName:
|
|
60
|
-
singularName:
|
|
61
|
-
camelSingularName:
|
|
56
|
+
kebabCasedName: lodash.kebabCase(schemaName),
|
|
57
|
+
singularName: pluralize.singular(schemaName),
|
|
58
|
+
camelSingularName: lodash.camelCase(pluralize.singular(schemaName)),
|
|
62
59
|
description: schemaWrapperInfo.description,
|
|
63
60
|
referenceProperties: schemaWrapperInfo.referenceProperties,
|
|
64
|
-
valueProperties: schemaWrapperInfo.valueProperties.filter(this.options.valuePropertyTypeFilterCallBack ||
|
|
61
|
+
valueProperties: schemaWrapperInfo.valueProperties.filter(this.options.valuePropertyTypeFilterCallBack || defaultFilter),
|
|
65
62
|
importTypes: this.getImportTypes(schemaName, schemaWrapperInfo),
|
|
66
63
|
};
|
|
67
64
|
entities.push(entity);
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
|
-
return entities.filter(this.options.typeFilterCallBack ||
|
|
67
|
+
return entities.filter(this.options.typeFilterCallBack || defaultFilter);
|
|
71
68
|
}
|
|
72
69
|
buildSchemaWrapperInfoForEnum(schemaWrapperInfo) {
|
|
73
70
|
schemaWrapperInfo.isEnum = true;
|
|
74
|
-
let enumValues = [
|
|
71
|
+
let enumValues = [
|
|
72
|
+
...(schemaWrapperInfo.componentSchemaObject.enum || []).map((x) => {
|
|
75
73
|
const key = this.startNumberregex.exec(x)?.at(0);
|
|
76
74
|
const name = this.endAlphaNumRegex.exec(x)?.at(0) ?? '';
|
|
77
75
|
return {
|
|
78
76
|
key: key ? +key : 0,
|
|
79
77
|
name,
|
|
80
|
-
titleName:
|
|
81
|
-
snakeCaseName:
|
|
78
|
+
titleName: lodash.startCase(name),
|
|
79
|
+
snakeCaseName: lodash.snakeCase(name).toUpperCase(),
|
|
82
80
|
};
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
83
|
+
schemaWrapperInfo.isCharEnum =
|
|
84
|
+
enumValues.length > 0 &&
|
|
85
|
+
enumValues
|
|
86
|
+
.filter((enumVal) => typeof enumVal !== 'string' && typeof enumVal.key === 'number')
|
|
87
|
+
.map((enumVal) => enumVal.key)
|
|
88
|
+
.every((val) => val >= 65 && val <= 90); // A-Z ASCII range
|
|
89
89
|
if (schemaWrapperInfo.isCharEnum) {
|
|
90
|
-
enumValues = enumValues.map(enumvalue => ({
|
|
90
|
+
enumValues = enumValues.map((enumvalue) => ({
|
|
91
91
|
...enumvalue,
|
|
92
|
-
key: String.fromCharCode(enumvalue.key)
|
|
92
|
+
key: String.fromCharCode(enumvalue.key),
|
|
93
93
|
}));
|
|
94
94
|
}
|
|
95
95
|
schemaWrapperInfo.enumValues.push(...enumValues);
|
|
@@ -134,7 +134,7 @@ class OpenApiDocConverter {
|
|
|
134
134
|
initialValue,
|
|
135
135
|
initialTestValue,
|
|
136
136
|
isArray: false,
|
|
137
|
-
snakeCaseName:
|
|
137
|
+
snakeCaseName: lodash.snakeCase(propertyName).toUpperCase(),
|
|
138
138
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
139
139
|
maxLength: schemaWrapperInfo.propertySchemaObject.maxLength,
|
|
140
140
|
minLength: schemaWrapperInfo.propertySchemaObject.minLength,
|
|
@@ -170,7 +170,7 @@ class OpenApiDocConverter {
|
|
|
170
170
|
email: false,
|
|
171
171
|
uri: false,
|
|
172
172
|
isArray: true,
|
|
173
|
-
snakeCaseName:
|
|
173
|
+
snakeCaseName: lodash.snakeCase(propertyName).toUpperCase(),
|
|
174
174
|
hasMultipleValidators: false,
|
|
175
175
|
hasValidators: validatorCount > 0,
|
|
176
176
|
};
|
|
@@ -226,7 +226,7 @@ class OpenApiDocConverter {
|
|
|
226
226
|
return `'${defaultValue.split(' ').pop()}'`;
|
|
227
227
|
}
|
|
228
228
|
else if (email) {
|
|
229
|
-
return `'${
|
|
229
|
+
return `'${lodash.kebabCase(parentTypeName)}@email.org'`;
|
|
230
230
|
}
|
|
231
231
|
else if (typescriptType === 'Date') {
|
|
232
232
|
return 'new Date()';
|
|
@@ -244,7 +244,7 @@ class OpenApiDocConverter {
|
|
|
244
244
|
return minValue ? `${minValue}` : '0';
|
|
245
245
|
}
|
|
246
246
|
else {
|
|
247
|
-
let retValue =
|
|
247
|
+
let retValue = lodash.snakeCase(propertyName).toUpperCase();
|
|
248
248
|
while (minLength && retValue.length < minLength) {
|
|
249
249
|
retValue = `${retValue}_${retValue}`;
|
|
250
250
|
}
|
|
@@ -275,7 +275,7 @@ class OpenApiDocConverter {
|
|
|
275
275
|
isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
|
|
276
276
|
initialValue,
|
|
277
277
|
initialTestValue,
|
|
278
|
-
snakeCaseName:
|
|
278
|
+
snakeCaseName: lodash.snakeCase(propertyName).toUpperCase(),
|
|
279
279
|
referenceTypeName: typeName,
|
|
280
280
|
typeScriptType: typeName,
|
|
281
281
|
isArray: false,
|
|
@@ -351,7 +351,7 @@ class OpenApiDocConverter {
|
|
|
351
351
|
const props = properties.filter((t) => t.items.$ref === value || t.$ref === value);
|
|
352
352
|
return {
|
|
353
353
|
name: value,
|
|
354
|
-
kebabCasedTypeName:
|
|
354
|
+
kebabCasedTypeName: lodash.kebabCase(value),
|
|
355
355
|
isEnum: (refSchema?.enum ?? []).length > 0,
|
|
356
356
|
areAllArrays: props.every((val) => val.type === 'array'),
|
|
357
357
|
hasArrays: props.some((val) => val.type === 'array'),
|
|
@@ -367,4 +367,3 @@ class OpenApiDocConverter {
|
|
|
367
367
|
propertyName !== 'id');
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
|
-
exports.OpenApiDocConverter = OpenApiDocConverter;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-generator",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.49.3",
|
|
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
|
+
"type": "module",
|
|
6
7
|
"types": "index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
@@ -19,7 +20,8 @@
|
|
|
19
20
|
"scripts": {
|
|
20
21
|
"build": "tsc && cp -rfv ./src/templates ./lib",
|
|
21
22
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
22
|
-
"lint": "eslint
|
|
23
|
+
"lint-json": "eslint --output-file ./eslint-report.json --format json",
|
|
24
|
+
"lint-html": "eslint --output-file ./eslint-report.html --format html",
|
|
23
25
|
"link": "npm run build && cd lib && npm link && cd ..",
|
|
24
26
|
"test": "npm run build && jest --collect-coverage",
|
|
25
27
|
"prep:lib": "rm -rv ./lib/*.spec.* && rm -rv ./lib/**/*.spec.* && cp -v ./package.json ./lib/ && cp -v ./LICENSE ./lib/ && cp -v ./README.md ./lib/",
|
|
@@ -50,6 +52,7 @@
|
|
|
50
52
|
"homepage": "https://github.com/ikemtz/OpenApi-TS-Generator#readme",
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@eslint/js": "^9.39.2",
|
|
55
|
+
"@jest/globals": "^30.2.0",
|
|
53
56
|
"@types/jest": "^30.0.0",
|
|
54
57
|
"@types/lodash": "^4.17.23",
|
|
55
58
|
"@types/node": "^22.19.7",
|
|
@@ -23,9 +23,9 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
|
|
|
23
23
|
{{name}}: new FormArray<FormControl<{{typeScriptType}}>>([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}} }{{/if}}),
|
|
24
24
|
{{/if}}
|
|
25
25
|
{{else}}
|
|
26
|
-
{{#if hasMultipleValidators}}
|
|
26
|
+
{{#if hasMultipleValidators}}
|
|
27
27
|
{{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{#if email}}Validators.email, {{/if}}{{#if uri}}Validators.pattern('(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?'), {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
|
|
28
|
-
{{else}}
|
|
28
|
+
{{else}}
|
|
29
29
|
{{name}}: new FormControl<{{typeScriptType}}{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{#if email}}Validators.email {{/if}}{{#if uri}}Validators.pattern('(https?://)?([\\da-z.-]+)\\.([a-z.]{2,6})[/\\w .-]*/?') {{/if}}{{minLengthValidator "valueProperties"}}{{maxLengthValidator "valueProperties"}}{{minimumValidator "valueProperties"}}{{maximumValidator "valueProperties"}}{{minItemsValidator "valueProperties"}}{{maxItemsValidator "valueProperties"}}{{{patternValidator "valueProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
|
|
30
30
|
{{/if}}
|
|
31
31
|
{{/if}}
|
|
@@ -44,9 +44,9 @@ export function {{name}}FormGroupFac(): FormGroup<I{{name}}Form> {
|
|
|
44
44
|
{{name}}: new FormArray<FormGroup<I{{typeScriptType}}Form>>([]{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}} } {{/if}}),
|
|
45
45
|
{{/if}}
|
|
46
46
|
{{else if isEnum}}
|
|
47
|
-
{{#if hasMultipleValidators}}
|
|
47
|
+
{{#if hasMultipleValidators}}
|
|
48
48
|
{{name}}: new FormControl<{{typeScriptType}} | string{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}, { validators: Validators.compose([{{#if required}}Validators.required, {{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}]){{#if required}}, nonNullable: true{{/if}} }),
|
|
49
|
-
{{else}}
|
|
49
|
+
{{else}}
|
|
50
50
|
{{name}}: new FormControl<{{typeScriptType}} | string{{#unless required}} | null | undefined{{/unless}}>({{{initialValue}}}{{#if hasValidators}}, { validators: {{#if required}}Validators.required{{/if}}{{minLengthValidator "referenceProperties"}}{{maxLengthValidator "referenceProperties"}}{{minimumValidator "referenceProperties"}}{{maximumValidator "referenceProperties"}}{{minItemsValidator "referenceProperties"}}{{maxItemsValidator "referenceProperties"}}{{{patternValidator "referenceProperties"}}}{{#if required}}, nonNullable: true{{/if}} } {{/if}}),
|
|
51
51
|
{{/if}}
|
|
52
52
|
{{else}}
|