openapi-ts-generator 10.37.1 → 10.48.14
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 +8 -12
- package/generators/base.generator.d.ts +1 -1
- package/generators/base.generator.js +10 -11
- package/generators/endpoints.generator.d.ts +3 -3
- package/generators/endpoints.generator.js +7 -11
- package/generators/enum.generator.d.ts +4 -4
- package/generators/enum.generator.js +5 -9
- 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 +5 -9
- 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 +5 -9
- package/generators/model.generator.d.ts +5 -4
- package/generators/model.generator.js +8 -10
- package/generators/test-object-factory.generator.d.ts +5 -4
- package/generators/test-object-factory.generator.js +7 -9
- package/index.d.ts +2 -2
- package/index.js +19 -61
- 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 +4 -8
- package/models/helper-context.d.ts +1 -1
- package/models/helper-context.js +1 -2
- package/models/logger.js +4 -10
- 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 +12 -10
- package/models/template-data.d.ts +1 -1
- package/models/template-data.js +1 -2
- package/models/value-property.js +1 -2
- package/openapidoc-converter.d.ts +6 -6
- package/openapidoc-converter.js +36 -35
- package/package.json +9 -7
- 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
|
-
|
|
7
|
-
|
|
8
|
-
super(options, options.templates?.barrel);
|
|
9
|
-
this.GeneratorName = 'BarrelGenerator';
|
|
10
|
-
this.tsRegex = /.ts$/;
|
|
1
|
+
import { readdirSync } from 'node:fs';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class BarrelGenerator extends BaseGenerator {
|
|
4
|
+
GeneratorName = 'BarrelGenerator';
|
|
5
|
+
tsRegex = /.ts$/;
|
|
6
|
+
constructor(generatorOptions) {
|
|
7
|
+
super(generatorOptions, generatorOptions.templates?.barrel);
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { IGeneratorOptions } from '../models/generator-options';
|
|
1
|
+
import { IGeneratorOptions } from '../models/generator-options.ts';
|
|
2
2
|
export declare abstract class BaseGenerator<TContextSchema> {
|
|
3
3
|
readonly generatorOptions: IGeneratorOptions;
|
|
4
4
|
readonly templateFilePath: string | undefined;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { compile } from 'handlebars';
|
|
3
|
+
export class BaseGenerator {
|
|
4
|
+
generatorOptions;
|
|
5
|
+
templateFilePath;
|
|
6
|
+
template;
|
|
7
|
+
emptyArrayRegex = /, ]/g;
|
|
7
8
|
constructor(generatorOptions, templateFilePath) {
|
|
8
9
|
this.generatorOptions = generatorOptions;
|
|
9
10
|
this.templateFilePath = templateFilePath;
|
|
10
|
-
this.emptyArrayRegex = /, ]/g;
|
|
11
11
|
if (templateFilePath) {
|
|
12
|
-
const templateSource =
|
|
13
|
-
this.template =
|
|
12
|
+
const templateSource = readFileSync(templateFilePath, { encoding: 'utf8' });
|
|
13
|
+
this.template = compile(templateSource);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
generateFile(outputFilePath, context) {
|
|
@@ -23,7 +23,7 @@ class BaseGenerator {
|
|
|
23
23
|
else {
|
|
24
24
|
try {
|
|
25
25
|
const content = this.template(context).replace(this.emptyArrayRegex, ']');
|
|
26
|
-
|
|
26
|
+
writeFileSync(outputFilePath, content, { encoding: 'utf8' });
|
|
27
27
|
return content;
|
|
28
28
|
}
|
|
29
29
|
catch (err) {
|
|
@@ -38,4 +38,3 @@ class BaseGenerator {
|
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
class EndPointsGenerator extends base_generator_1.BaseGenerator {
|
|
1
|
+
import { camelCase } from 'lodash';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class EndPointsGenerator extends BaseGenerator {
|
|
4
|
+
GeneratorName = 'EndPointsGenerator';
|
|
5
|
+
endpointIdentifierRegex = /[A-z0-9_-]*$/;
|
|
7
6
|
constructor(options) {
|
|
8
7
|
super(options, options.templates?.endpoints);
|
|
9
|
-
this.GeneratorName = 'EndPointsGenerator';
|
|
10
|
-
this.endpointIdentifierRegex = /[A-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: 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: 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,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const base_generator_1 = require("./base.generator");
|
|
6
|
-
class EnumGenerator extends base_generator_1.BaseGenerator {
|
|
1
|
+
import { kebabCase } from 'lodash';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class EnumGenerator extends BaseGenerator {
|
|
4
|
+
GeneratorName = 'EnumGenerator';
|
|
7
5
|
constructor(options) {
|
|
8
6
|
super(options, options.templates?.enum);
|
|
9
|
-
this.GeneratorName = 'EnumGenerator';
|
|
10
7
|
}
|
|
11
8
|
generate(templateData) {
|
|
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}/${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,54 +1,18 @@
|
|
|
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 * as HandleBars from 'handlebars';
|
|
3
|
+
import { kebabCase } from 'lodash';
|
|
4
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
5
|
+
export class FormGroupFactoryGenerator extends BaseGenerator {
|
|
6
|
+
GeneratorName = 'FormGroupFactoryGenerator';
|
|
42
7
|
constructor(options) {
|
|
43
8
|
super(options, options.templates?.formGroupFactory);
|
|
44
|
-
this.GeneratorName = 'FormGroupFactoryGenerator';
|
|
45
9
|
}
|
|
46
10
|
generate(templateData) {
|
|
47
11
|
this.registerHelpers();
|
|
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}/${kebabCase(entity.name)}.form-group-fac.ts`, entity);
|
|
52
16
|
});
|
|
53
17
|
}
|
|
54
18
|
registerHelpers() {
|
|
@@ -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,20 +1,16 @@
|
|
|
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 { kebabCase } from 'lodash';
|
|
3
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
4
|
+
export class FormGenerator extends BaseGenerator {
|
|
5
|
+
GeneratorName = 'FormGenerator';
|
|
8
6
|
constructor(options) {
|
|
9
7
|
super(options, options.templates?.form);
|
|
10
|
-
this.GeneratorName = 'FormGenerator';
|
|
11
8
|
}
|
|
12
9
|
generate(templateData) {
|
|
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}/${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,21 +1,17 @@
|
|
|
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 { kebabCase } from 'lodash';
|
|
3
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
4
|
+
export class ModelPropertiesGenerator extends BaseGenerator {
|
|
5
|
+
GeneratorName = 'ModelPropertiesGenerator';
|
|
8
6
|
constructor(options) {
|
|
9
7
|
super(options, options.templates?.modelProperties);
|
|
10
|
-
this.GeneratorName = 'ModelPropertiesGenerator';
|
|
11
8
|
}
|
|
12
9
|
generate(templateData) {
|
|
13
10
|
templateData.entities
|
|
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}/${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,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ModelGenerator extends base_generator_1.BaseGenerator {
|
|
1
|
+
import { kebabCase } from 'lodash';
|
|
2
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
3
|
+
export class ModelGenerator extends BaseGenerator {
|
|
4
|
+
options;
|
|
5
|
+
GeneratorName = 'ModelGenerator';
|
|
7
6
|
constructor(options) {
|
|
8
7
|
super(options, options.genClasses ? options.templates?.entity : options.templates?.model);
|
|
9
|
-
this.
|
|
8
|
+
this.options = options;
|
|
10
9
|
}
|
|
11
10
|
generate(templateData) {
|
|
12
|
-
const fileSuffix = this.
|
|
11
|
+
const fileSuffix = this.options.genClasses ? '.entity.ts' : '.model.ts';
|
|
13
12
|
templateData.entities
|
|
14
13
|
?.filter((entity) => !entity.isEnum)
|
|
15
14
|
.forEach((entity) => {
|
|
16
|
-
super.generateFile(`${this.
|
|
15
|
+
super.generateFile(`${this.options.outputPath}/${kebabCase(entity.name)}${fileSuffix}`, entity);
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
18
|
}
|
|
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,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { kebabCase } from 'lodash';
|
|
3
|
+
import { BaseGenerator } from "./base.generator.js";
|
|
4
|
+
export class TestObjectFactoryGenerator extends BaseGenerator {
|
|
5
|
+
options;
|
|
6
|
+
GeneratorName = 'TestObjectFactoryGenerator';
|
|
8
7
|
constructor(options) {
|
|
9
8
|
super(options, options.templates?.testObjectFactory);
|
|
10
|
-
this.
|
|
9
|
+
this.options = options;
|
|
11
10
|
}
|
|
12
11
|
generate(templateData) {
|
|
13
12
|
templateData.entities
|
|
14
13
|
?.filter((val) => val.valueProperties?.length + val.referenceProperties?.length > 0)
|
|
15
14
|
.forEach((entity) => {
|
|
16
|
-
super.generateFile(`${this.
|
|
15
|
+
super.generateFile(`${this.options.outputPath}/${kebabCase(entity.name)}.test-obj-fac.ts`, entity);
|
|
17
16
|
});
|
|
18
17
|
}
|
|
19
18
|
}
|
|
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/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,10 @@
|
|
|
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
|
-
function defaultFilter(_value, _index, _array) {
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
export function defaultFilter(_value, _index, _array) {
|
|
8
4
|
return true;
|
|
9
5
|
}
|
|
10
|
-
function setGeneratorOptionDefaults(options) {
|
|
11
|
-
const templateFolder =
|
|
6
|
+
export function setGeneratorOptionDefaults(options) {
|
|
7
|
+
const templateFolder = resolve(`${__dirname}/..`, 'templates');
|
|
12
8
|
options.typeFilterCallBack = options.typeFilterCallBack ?? defaultFilter;
|
|
13
9
|
options.valuePropertyTypeFilterCallBack = options.valuePropertyTypeFilterCallBack ?? defaultFilter;
|
|
14
10
|
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,6 @@
|
|
|
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 {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.warn = (data) => { };
|
|
10
|
-
}
|
|
2
|
+
export class MockConsoleLogger {
|
|
3
|
+
log = (data) => { };
|
|
4
|
+
error = (data) => { };
|
|
5
|
+
warn = (data) => { };
|
|
11
6
|
}
|
|
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,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { defaultFilter } from "./generator-options.js";
|
|
2
|
+
export class SchemaWrapperInfo {
|
|
3
|
+
propertySchemaObject = {};
|
|
4
|
+
propertyReferenceObject = { $ref: '' };
|
|
5
|
+
isEnum;
|
|
6
|
+
isCharEnum = false;
|
|
7
|
+
enumValues;
|
|
8
|
+
componentSchemaObject;
|
|
9
|
+
valueProperties;
|
|
10
|
+
referenceProperties;
|
|
11
|
+
description;
|
|
6
12
|
constructor(schemaItem) {
|
|
7
|
-
this.propertySchemaObject = {};
|
|
8
|
-
this.propertyReferenceObject = { $ref: '' };
|
|
9
|
-
this.isCharEnum = false;
|
|
10
13
|
this.componentSchemaObject = schemaItem;
|
|
11
14
|
this.description = schemaItem.description;
|
|
12
15
|
this.valueProperties = [];
|
|
@@ -14,7 +17,6 @@ class SchemaWrapperInfo {
|
|
|
14
17
|
this.enumValues = [];
|
|
15
18
|
}
|
|
16
19
|
updateReferenceProperties(options) {
|
|
17
|
-
this.referenceProperties = this.referenceProperties.filter(options.referencePropertyTypeFilterCallBack ??
|
|
20
|
+
this.referenceProperties = this.referenceProperties.filter(options.referencePropertyTypeFilterCallBack ?? defaultFilter);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
|
-
exports.SchemaWrapperInfo = SchemaWrapperInfo;
|
package/models/template-data.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
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,19 +1,18 @@
|
|
|
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 { singular } from 'pluralize';
|
|
5
|
+
import { camelCase, kebabCase, snakeCase, startCase } from 'lodash';
|
|
6
|
+
import { defaultFilter } from "./models/generator-options.js";
|
|
7
|
+
import { SchemaWrapperInfo } from "./models/schema-info.js";
|
|
8
|
+
export class OpenApiDocConverter {
|
|
9
|
+
options;
|
|
10
|
+
apiDocument;
|
|
11
|
+
endAlphaNumRegex = /[A-z0-9]*$/s;
|
|
12
|
+
startNumberregex = /^\d*/;
|
|
12
13
|
constructor(options, apiDocument) {
|
|
13
14
|
this.options = options;
|
|
14
15
|
this.apiDocument = apiDocument;
|
|
15
|
-
this.endAlphaNumRegex = /[A-z0-9]*$/s;
|
|
16
|
-
this.startNumberregex = /^\d*/;
|
|
17
16
|
}
|
|
18
17
|
convertDocument() {
|
|
19
18
|
const entities = this.convertEntities();
|
|
@@ -28,7 +27,7 @@ class OpenApiDocConverter {
|
|
|
28
27
|
tagLookup = tagLookup || path.delete || path.patch;
|
|
29
28
|
const tag = (tagLookup?.tags || ['unknown_endpoint'])[0];
|
|
30
29
|
paths.push({
|
|
31
|
-
tag:
|
|
30
|
+
tag: snakeCase(tag),
|
|
32
31
|
endpoint: this.options.pathUrlFormattingCallBack ? this.options.pathUrlFormattingCallBack(key) : key,
|
|
33
32
|
});
|
|
34
33
|
}
|
|
@@ -38,7 +37,7 @@ class OpenApiDocConverter {
|
|
|
38
37
|
const entities = [];
|
|
39
38
|
for (const schemaName in this.apiDocument.components?.schemas) {
|
|
40
39
|
if (this.apiDocument.components.schemas[schemaName]) {
|
|
41
|
-
const schemaWrapperInfo = new
|
|
40
|
+
const schemaWrapperInfo = new SchemaWrapperInfo(this.apiDocument.components?.schemas[schemaName]);
|
|
42
41
|
if (schemaWrapperInfo.componentSchemaObject.enum) {
|
|
43
42
|
this.buildSchemaWrapperInfoForEnum(schemaWrapperInfo);
|
|
44
43
|
}
|
|
@@ -56,40 +55,43 @@ class OpenApiDocConverter {
|
|
|
56
55
|
key: schemaWrapperInfo.isCharEnum ? t.key : +t.key,
|
|
57
56
|
}),
|
|
58
57
|
name: schemaName,
|
|
59
|
-
kebabCasedName:
|
|
60
|
-
singularName:
|
|
61
|
-
camelSingularName:
|
|
58
|
+
kebabCasedName: kebabCase(schemaName),
|
|
59
|
+
singularName: singular(schemaName),
|
|
60
|
+
camelSingularName: camelCase(singular(schemaName)),
|
|
62
61
|
description: schemaWrapperInfo.description,
|
|
63
62
|
referenceProperties: schemaWrapperInfo.referenceProperties,
|
|
64
|
-
valueProperties: schemaWrapperInfo.valueProperties.filter(this.options.valuePropertyTypeFilterCallBack ||
|
|
63
|
+
valueProperties: schemaWrapperInfo.valueProperties.filter(this.options.valuePropertyTypeFilterCallBack || defaultFilter),
|
|
65
64
|
importTypes: this.getImportTypes(schemaName, schemaWrapperInfo),
|
|
66
65
|
};
|
|
67
66
|
entities.push(entity);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
|
-
return entities.filter(this.options.typeFilterCallBack ||
|
|
69
|
+
return entities.filter(this.options.typeFilterCallBack || defaultFilter);
|
|
71
70
|
}
|
|
72
71
|
buildSchemaWrapperInfoForEnum(schemaWrapperInfo) {
|
|
73
72
|
schemaWrapperInfo.isEnum = true;
|
|
74
|
-
let enumValues = [
|
|
73
|
+
let enumValues = [
|
|
74
|
+
...(schemaWrapperInfo.componentSchemaObject.enum || []).map((x) => {
|
|
75
75
|
const key = this.startNumberregex.exec(x)?.at(0);
|
|
76
76
|
const name = this.endAlphaNumRegex.exec(x)?.at(0) ?? '';
|
|
77
77
|
return {
|
|
78
78
|
key: key ? +key : 0,
|
|
79
79
|
name,
|
|
80
|
-
titleName:
|
|
81
|
-
snakeCaseName:
|
|
80
|
+
titleName: startCase(name),
|
|
81
|
+
snakeCaseName: snakeCase(name).toUpperCase(),
|
|
82
82
|
};
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
}),
|
|
84
|
+
];
|
|
85
|
+
schemaWrapperInfo.isCharEnum =
|
|
86
|
+
enumValues.length > 0 &&
|
|
87
|
+
enumValues
|
|
88
|
+
.filter((enumVal) => typeof enumVal !== 'string' && typeof enumVal.key === 'number')
|
|
89
|
+
.map((enumVal) => enumVal.key)
|
|
90
|
+
.every((val) => val >= 65 && val <= 90); // A-Z ASCII range
|
|
89
91
|
if (schemaWrapperInfo.isCharEnum) {
|
|
90
|
-
enumValues = enumValues.map(enumvalue => ({
|
|
92
|
+
enumValues = enumValues.map((enumvalue) => ({
|
|
91
93
|
...enumvalue,
|
|
92
|
-
key: String.fromCharCode(enumvalue.key)
|
|
94
|
+
key: String.fromCharCode(enumvalue.key),
|
|
93
95
|
}));
|
|
94
96
|
}
|
|
95
97
|
schemaWrapperInfo.enumValues.push(...enumValues);
|
|
@@ -134,7 +136,7 @@ class OpenApiDocConverter {
|
|
|
134
136
|
initialValue,
|
|
135
137
|
initialTestValue,
|
|
136
138
|
isArray: false,
|
|
137
|
-
snakeCaseName:
|
|
139
|
+
snakeCaseName: snakeCase(propertyName).toUpperCase(),
|
|
138
140
|
typeScriptType: this.getPropertyTypeScriptType(schemaWrapperInfo),
|
|
139
141
|
maxLength: schemaWrapperInfo.propertySchemaObject.maxLength,
|
|
140
142
|
minLength: schemaWrapperInfo.propertySchemaObject.minLength,
|
|
@@ -170,7 +172,7 @@ class OpenApiDocConverter {
|
|
|
170
172
|
email: false,
|
|
171
173
|
uri: false,
|
|
172
174
|
isArray: true,
|
|
173
|
-
snakeCaseName:
|
|
175
|
+
snakeCaseName: snakeCase(propertyName).toUpperCase(),
|
|
174
176
|
hasMultipleValidators: false,
|
|
175
177
|
hasValidators: validatorCount > 0,
|
|
176
178
|
};
|
|
@@ -226,7 +228,7 @@ class OpenApiDocConverter {
|
|
|
226
228
|
return `'${defaultValue.split(' ').pop()}'`;
|
|
227
229
|
}
|
|
228
230
|
else if (email) {
|
|
229
|
-
return `'${
|
|
231
|
+
return `'${kebabCase(parentTypeName)}@email.org'`;
|
|
230
232
|
}
|
|
231
233
|
else if (typescriptType === 'Date') {
|
|
232
234
|
return 'new Date()';
|
|
@@ -244,7 +246,7 @@ class OpenApiDocConverter {
|
|
|
244
246
|
return minValue ? `${minValue}` : '0';
|
|
245
247
|
}
|
|
246
248
|
else {
|
|
247
|
-
let retValue =
|
|
249
|
+
let retValue = snakeCase(propertyName).toUpperCase();
|
|
248
250
|
while (minLength && retValue.length < minLength) {
|
|
249
251
|
retValue = `${retValue}_${retValue}`;
|
|
250
252
|
}
|
|
@@ -275,7 +277,7 @@ class OpenApiDocConverter {
|
|
|
275
277
|
isSameAsParentTypescriptType: parentTypeName.toLowerCase() === typeName.toLowerCase(),
|
|
276
278
|
initialValue,
|
|
277
279
|
initialTestValue,
|
|
278
|
-
snakeCaseName:
|
|
280
|
+
snakeCaseName: snakeCase(propertyName).toUpperCase(),
|
|
279
281
|
referenceTypeName: typeName,
|
|
280
282
|
typeScriptType: typeName,
|
|
281
283
|
isArray: false,
|
|
@@ -351,7 +353,7 @@ class OpenApiDocConverter {
|
|
|
351
353
|
const props = properties.filter((t) => t.items.$ref === value || t.$ref === value);
|
|
352
354
|
return {
|
|
353
355
|
name: value,
|
|
354
|
-
kebabCasedTypeName:
|
|
356
|
+
kebabCasedTypeName: kebabCase(value),
|
|
355
357
|
isEnum: (refSchema?.enum ?? []).length > 0,
|
|
356
358
|
areAllArrays: props.every((val) => val.type === 'array'),
|
|
357
359
|
hasArrays: props.some((val) => val.type === 'array'),
|
|
@@ -367,4 +369,3 @@ class OpenApiDocConverter {
|
|
|
367
369
|
propertyName !== 'id');
|
|
368
370
|
}
|
|
369
371
|
}
|
|
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.48.14",
|
|
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,12 +52,13 @@
|
|
|
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",
|
|
56
59
|
"@types/pluralize": "^0.0.33",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
58
|
-
"@typescript-eslint/parser": "^8.
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^8.55.0",
|
|
61
|
+
"@typescript-eslint/parser": "^8.55.0",
|
|
59
62
|
"eslint": "^9.39.2",
|
|
60
63
|
"eslint-config-prettier": "^10.1.8",
|
|
61
64
|
"eslint-plugin-import": "^2.32.0",
|
|
@@ -69,16 +72,15 @@
|
|
|
69
72
|
"rxjs": "^7.6.0",
|
|
70
73
|
"ts-jest": "^29.4.6",
|
|
71
74
|
"typescript": "^5.9.3",
|
|
72
|
-
"typescript-eslint": "^8.
|
|
75
|
+
"typescript-eslint": "^8.55.0"
|
|
73
76
|
},
|
|
74
77
|
"dependencies": {
|
|
75
|
-
"axios": "
|
|
78
|
+
"axios": "^1.13.5",
|
|
76
79
|
"handlebars": ">=4.x",
|
|
77
80
|
"lodash": "^4.17.23",
|
|
78
81
|
"pluralize": ">=8.x"
|
|
79
82
|
},
|
|
80
83
|
"peerDependencies": {
|
|
81
|
-
"axios": ">=1.13.x",
|
|
82
84
|
"handlebars": ">=4.x",
|
|
83
85
|
"pluralize": ">=8.x",
|
|
84
86
|
"rxjs": "*"
|
|
@@ -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}}
|