@devlearning/swagger-generator 1.0.26 → 1.0.28
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/.vscode/launch.json +28 -22
- package/README.md +209 -209
- package/dist/api.constants.js +22 -22
- package/dist/generators-writers/angular/api-angular-writer.js +15 -15
- package/dist/generators-writers/angular/constants.js +24 -24
- package/dist/generators-writers/angular/model-angular-writer.js +6 -6
- package/dist/generators-writers/dart/templates/api.mustache +36 -36
- package/dist/generators-writers/dart/templates/enum.mustache +14 -13
- package/dist/generators-writers/dart/templates/model.mustache +17 -17
- package/dist/generators-writers/nextjs/api-nextjs-writer.js +12 -12
- package/dist/generators-writers/nextjs/constants.js +4 -4
- package/dist/generators-writers/nextjs/model-nextjs-writer.js +6 -6
- package/dist/models/swagger-component-property.js +1 -0
- package/dist/models/swagger-component.js +1 -0
- package/dist/models/swagger-content.js +1 -0
- package/dist/models/swagger-info.js +1 -0
- package/dist/models/swagger-method.js +1 -0
- package/dist/models/swagger-schema.js +1 -0
- package/dist/models/swagger.js +1 -0
- package/package.json +45 -45
- package/src/api.constants.ts +26 -26
- package/src/generator-old.ts +449 -449
- package/src/generator.ts +582 -582
- package/src/generators-writers/angular/api-angular-writer.ts +141 -141
- package/src/generators-writers/angular/constants.ts +36 -36
- package/src/generators-writers/angular/model-angular-writer.ts +62 -62
- package/src/generators-writers/dart/api-dart-writer.ts +190 -190
- package/src/generators-writers/dart/model-dart-writer.ts +162 -162
- package/src/generators-writers/dart/models/import-definition-dart.ts +5 -5
- package/src/generators-writers/dart/normalizator.ts +72 -72
- package/src/generators-writers/dart/templates/api.mustache +36 -36
- package/src/generators-writers/dart/templates/enum.mustache +14 -13
- package/src/generators-writers/dart/templates/model.mustache +17 -17
- package/src/generators-writers/nextjs/api-nextjs-writer.ts +156 -156
- package/src/generators-writers/nextjs/constants.ts +5 -5
- package/src/generators-writers/nextjs/model-nextjs-writer.ts +61 -61
- package/src/generators-writers/utils.ts +78 -78
- package/src/index.ts +96 -96
- package/src/models/api-dto.ts +17 -17
- package/src/models/enum-value-dto.ts +3 -3
- package/src/models/model-dto.ts +9 -9
- package/src/models/parameter-dto.ts +7 -7
- package/src/models/property-dto.ts +4 -4
- package/src/models/swagger/swagger-component-property.ts +11 -11
- package/src/models/swagger/swagger-component.ts +17 -17
- package/src/models/swagger/swagger-content.ts +4 -4
- package/src/models/swagger/swagger-info.ts +3 -3
- package/src/models/swagger/swagger-method.ts +7 -7
- package/src/models/swagger/swagger-schema.ts +20 -20
- package/src/models/swagger/swagger.ts +38 -38
- package/src/models/type-dto.ts +7 -7
- package/src/swagger-downloader.ts +12 -12
- package/tsconfig.json +28 -28
- package/autogen/identity/api/identity_api.dart +0 -100
- package/autogen/identity/models/auth_activate_command.dart +0 -14
- package/autogen/identity/models/auth_app_authenticate_command.dart +0 -16
- package/autogen/identity/models/auth_generate_reset_password_code_command.dart +0 -15
- package/autogen/identity/models/auth_refresh_token_command.dart +0 -15
- package/autogen/identity/models/auth_reset_password_command.dart +0 -16
- package/autogen/identity/models/auth_user_authenticate_command.dart +0 -15
- package/autogen/identity/models/auth_user_dto.dart +0 -18
- package/autogen/identity/models/auth_verify_reset_password_code_command.dart +0 -14
- package/autogen/identity/models/authentication_token.dart +0 -17
- package/autogen/mvc/models/problem_details.dart +0 -17
- package/autogen/product/api/product_api.dart +0 -70
- package/autogen/product/models/geoposition.dart +0 -14
- package/autogen/product/models/product_category_dto.dart +0 -15
- package/autogen/product/models/product_category_list_query_response.dart +0 -14
- package/autogen/product/models/product_category_save_command.dart +0 -15
- package/autogen/product/models/product_list_nearby_query.dart +0 -20
- package/autogen/product/models/product_list_nearby_query_filter.dart +0 -15
- package/autogen/product/models/product_list_nearby_query_order_by.dart +0 -10
- package/autogen/product/models/product_save_command.dart +0 -13
- package/autogen/service_defaults/models/application_exception.dart +0 -14
- package/autogen/service_defaults/models/result.dart +0 -17
- package/autogen/service_defaults/models/sort_direction.dart +0 -10
- package/autogen/user_profile/api/user_profile_api.dart +0 -51
- package/autogen/user_profile/models/user_general_info_save_command.dart +0 -17
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
import fs, { writeFileSync } from 'fs';
|
|
2
|
-
import { ApiDto } from '@src/models/api-dto.js';
|
|
3
|
-
import { Utils } from '../utils.js';
|
|
4
|
-
import { ParameterDto } from '@src/models/parameter-dto.js';
|
|
5
|
-
import * as Mustache from 'mustache';
|
|
6
|
-
import { CommandLineArgs } from '@src/index.js';
|
|
7
|
-
import { ModelDto } from '@src/models/model-dto.js';
|
|
8
|
-
import { TypeDto } from '@src/models/type-dto.js';
|
|
9
|
-
import { ImportDefinitionDart } from './models/import-definition-dart.js';
|
|
10
|
-
import { Normalizator } from './normalizator.js';
|
|
11
|
-
import path from 'path';
|
|
12
|
-
import { fileURLToPath } from 'url';
|
|
13
|
-
|
|
14
|
-
interface ApiDefinitionDart {
|
|
15
|
-
package: string;
|
|
16
|
-
outputDirectory: string;
|
|
17
|
-
filename: string;
|
|
18
|
-
apiClassName: string;
|
|
19
|
-
imports: string[];
|
|
20
|
-
endpoints: EndpointDefinitionDart[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface EndpointDefinitionDart {
|
|
24
|
-
methodName: string;
|
|
25
|
-
httpMethod: HttpMethodDart;
|
|
26
|
-
path: string;
|
|
27
|
-
responseType: string;
|
|
28
|
-
haveRequest: boolean;
|
|
29
|
-
requestType?: string; // solo se haveRequest è true
|
|
30
|
-
queryParams?: Parameter[],
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface Parameter {
|
|
34
|
-
name: string;
|
|
35
|
-
type: string; // "string", "int", ecc
|
|
36
|
-
nullable: boolean;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type HttpMethodDart = 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export class ApiDartWriter {
|
|
43
|
-
private _commandLineArgs: CommandLineArgs;
|
|
44
|
-
|
|
45
|
-
constructor(commandLineArgs: CommandLineArgs) {
|
|
46
|
-
this._commandLineArgs = commandLineArgs;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
write(apis: ApiDto[], models: ModelDto[]) {
|
|
50
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
51
|
-
const __dirname = path.dirname(__filename);
|
|
52
|
-
const templatePath = path.join(__dirname, 'templates', 'api.mustache');
|
|
53
|
-
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
54
|
-
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
55
|
-
if (importDirectory.startsWith('lib/')) {
|
|
56
|
-
importDirectory = importDirectory.slice('lib/'.length);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const grouped = this._groupByTag(apis);
|
|
60
|
-
|
|
61
|
-
for (const [tag, apis] of Object.entries(grouped)) {
|
|
62
|
-
console.log(`Api: ${tag}`);
|
|
63
|
-
|
|
64
|
-
let subPath = '';
|
|
65
|
-
let filename = '';
|
|
66
|
-
let apiClassName = '';
|
|
67
|
-
|
|
68
|
-
subPath = Utils.toDartFileName(tag);
|
|
69
|
-
filename = `${Utils.toDartFileName(tag + 'Api')}`;
|
|
70
|
-
apiClassName = `${Utils.toDartClassName(tag + 'Api')}`;
|
|
71
|
-
|
|
72
|
-
var apiDefinition = <ApiDefinitionDart>{
|
|
73
|
-
package: this._commandLineArgs.package,
|
|
74
|
-
outputDirectory: this._commandLineArgs.outputDirectory,
|
|
75
|
-
filename: filename,
|
|
76
|
-
apiClassName: apiClassName,
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var endpoints = <EndpointDefinitionDart[]>[];
|
|
80
|
-
var imports = <ImportDefinitionDart[]>[];
|
|
81
|
-
|
|
82
|
-
for (const api of apis) {
|
|
83
|
-
var requestType: string | undefined = undefined;
|
|
84
|
-
requestType = api.haveRequest ? api.parameters[0]?.typeName || 'void' : undefined;
|
|
85
|
-
requestType = requestType?.split('.').pop()!
|
|
86
|
-
requestType = Utils.toDartClassName(requestType);
|
|
87
|
-
|
|
88
|
-
var responseType: string = 'void';
|
|
89
|
-
responseType = api.returnType ? api.returnType.typeName : 'void';
|
|
90
|
-
responseType = responseType?.split('.').pop()!;
|
|
91
|
-
responseType = Utils.toDartClassName(responseType) ?? responseType;
|
|
92
|
-
|
|
93
|
-
var methodName = Utils.getNormalizedApiPath(api.name);
|
|
94
|
-
if (methodName.startsWith(Utils.toFirstLetterLowercase(tag))) {
|
|
95
|
-
methodName = methodName.slice(tag.length);
|
|
96
|
-
methodName = Utils.toFirstLetterLowercase(methodName);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// console.debug(`\tAPI - ${apiName} - ${apiMethod}`);
|
|
100
|
-
if (methodName == "userGeneralInfoTestSave") {
|
|
101
|
-
debugger
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const endpoint = <EndpointDefinitionDart>{
|
|
105
|
-
methodName: methodName,
|
|
106
|
-
httpMethod: api.method.toLowerCase() as HttpMethodDart,
|
|
107
|
-
path: api.url,
|
|
108
|
-
responseType: responseType,
|
|
109
|
-
haveRequest: api.haveRequest,
|
|
110
|
-
requestType: requestType,
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
if (api.parameters && api.parameters.length > 0 && !api.haveRequest) {
|
|
114
|
-
endpoint.queryParams = api.parameters
|
|
115
|
-
.map(p => ({
|
|
116
|
-
name: p.name,
|
|
117
|
-
type: p.typeName ? Normalizator.mapTsTypeToDart(p.typeName)! : 'String',
|
|
118
|
-
nullable: p.nullable
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (api.haveRequest && api.parameters[0]?.typeName) {
|
|
123
|
-
if (imports.findIndex(x => x.type.typeName == api.parameters[0]?.typeName) == -1) {
|
|
124
|
-
models.forEach(model => {
|
|
125
|
-
if (model.typeName === api.parameters[0]?.typeName) {
|
|
126
|
-
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
127
|
-
imports.push({
|
|
128
|
-
type: api.parameters[0],
|
|
129
|
-
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (api.returnType && !api.returnType.isNativeType) {
|
|
137
|
-
if (imports.findIndex(x => x.type.typeName == api.returnType!.typeName) == -1) {
|
|
138
|
-
models.forEach(model => {
|
|
139
|
-
if (model.typeName === api.returnType!.typeName) {
|
|
140
|
-
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
141
|
-
imports.push({
|
|
142
|
-
type: api.returnType!,
|
|
143
|
-
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
endpoints.push(endpoint);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
apiDefinition.endpoints = endpoints;
|
|
154
|
-
apiDefinition.imports = imports.map(i => i.import);
|
|
155
|
-
|
|
156
|
-
let destinationPath = `${this._commandLineArgs.outputDirectory}/${subPath}/api`;
|
|
157
|
-
|
|
158
|
-
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
159
|
-
|
|
160
|
-
var result = Mustache.default.render(template, apiDefinition);
|
|
161
|
-
writeFileSync(`${destinationPath}/${apiDefinition.filename}.dart`, result, 'utf-8');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private _toPascalCase(input: string): string {
|
|
166
|
-
return input
|
|
167
|
-
.replace(/[_\- ]+/g, ' ') // sostituisce underscore, dash e spazi con uno spazio singolo
|
|
168
|
-
.trim() // rimuove spazi iniziali/finali
|
|
169
|
-
.split(' ') // divide in parole
|
|
170
|
-
.map(word =>
|
|
171
|
-
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
172
|
-
)
|
|
173
|
-
.join('');
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
private _normalizeApiClassName(input: string): string {
|
|
177
|
-
return input
|
|
178
|
-
.replace(/\./g, '');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
private _groupByTag(apis: ApiDto[]) {
|
|
182
|
-
const groupedByRole = apis.reduce<Record<string, ApiDto[]>>((acc, api) => {
|
|
183
|
-
if (!acc[api.tag]) {
|
|
184
|
-
acc[api.tag] = [];
|
|
185
|
-
}
|
|
186
|
-
acc[api.tag].push(api);
|
|
187
|
-
return acc;
|
|
188
|
-
}, {});
|
|
189
|
-
return groupedByRole;
|
|
190
|
-
}
|
|
1
|
+
import fs, { writeFileSync } from 'fs';
|
|
2
|
+
import { ApiDto } from '@src/models/api-dto.js';
|
|
3
|
+
import { Utils } from '../utils.js';
|
|
4
|
+
import { ParameterDto } from '@src/models/parameter-dto.js';
|
|
5
|
+
import * as Mustache from 'mustache';
|
|
6
|
+
import { CommandLineArgs } from '@src/index.js';
|
|
7
|
+
import { ModelDto } from '@src/models/model-dto.js';
|
|
8
|
+
import { TypeDto } from '@src/models/type-dto.js';
|
|
9
|
+
import { ImportDefinitionDart } from './models/import-definition-dart.js';
|
|
10
|
+
import { Normalizator } from './normalizator.js';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
|
|
14
|
+
interface ApiDefinitionDart {
|
|
15
|
+
package: string;
|
|
16
|
+
outputDirectory: string;
|
|
17
|
+
filename: string;
|
|
18
|
+
apiClassName: string;
|
|
19
|
+
imports: string[];
|
|
20
|
+
endpoints: EndpointDefinitionDart[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface EndpointDefinitionDart {
|
|
24
|
+
methodName: string;
|
|
25
|
+
httpMethod: HttpMethodDart;
|
|
26
|
+
path: string;
|
|
27
|
+
responseType: string;
|
|
28
|
+
haveRequest: boolean;
|
|
29
|
+
requestType?: string; // solo se haveRequest è true
|
|
30
|
+
queryParams?: Parameter[],
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Parameter {
|
|
34
|
+
name: string;
|
|
35
|
+
type: string; // "string", "int", ecc
|
|
36
|
+
nullable: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
type HttpMethodDart = 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export class ApiDartWriter {
|
|
43
|
+
private _commandLineArgs: CommandLineArgs;
|
|
44
|
+
|
|
45
|
+
constructor(commandLineArgs: CommandLineArgs) {
|
|
46
|
+
this._commandLineArgs = commandLineArgs;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
write(apis: ApiDto[], models: ModelDto[]) {
|
|
50
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
51
|
+
const __dirname = path.dirname(__filename);
|
|
52
|
+
const templatePath = path.join(__dirname, 'templates', 'api.mustache');
|
|
53
|
+
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
54
|
+
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
55
|
+
if (importDirectory.startsWith('lib/')) {
|
|
56
|
+
importDirectory = importDirectory.slice('lib/'.length);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const grouped = this._groupByTag(apis);
|
|
60
|
+
|
|
61
|
+
for (const [tag, apis] of Object.entries(grouped)) {
|
|
62
|
+
console.log(`Api: ${tag}`);
|
|
63
|
+
|
|
64
|
+
let subPath = '';
|
|
65
|
+
let filename = '';
|
|
66
|
+
let apiClassName = '';
|
|
67
|
+
|
|
68
|
+
subPath = Utils.toDartFileName(tag);
|
|
69
|
+
filename = `${Utils.toDartFileName(tag + 'Api')}`;
|
|
70
|
+
apiClassName = `${Utils.toDartClassName(tag + 'Api')}`;
|
|
71
|
+
|
|
72
|
+
var apiDefinition = <ApiDefinitionDart>{
|
|
73
|
+
package: this._commandLineArgs.package,
|
|
74
|
+
outputDirectory: this._commandLineArgs.outputDirectory,
|
|
75
|
+
filename: filename,
|
|
76
|
+
apiClassName: apiClassName,
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var endpoints = <EndpointDefinitionDart[]>[];
|
|
80
|
+
var imports = <ImportDefinitionDart[]>[];
|
|
81
|
+
|
|
82
|
+
for (const api of apis) {
|
|
83
|
+
var requestType: string | undefined = undefined;
|
|
84
|
+
requestType = api.haveRequest ? api.parameters[0]?.typeName || 'void' : undefined;
|
|
85
|
+
requestType = requestType?.split('.').pop()!
|
|
86
|
+
requestType = Utils.toDartClassName(requestType);
|
|
87
|
+
|
|
88
|
+
var responseType: string = 'void';
|
|
89
|
+
responseType = api.returnType ? api.returnType.typeName : 'void';
|
|
90
|
+
responseType = responseType?.split('.').pop()!;
|
|
91
|
+
responseType = Utils.toDartClassName(responseType) ?? responseType;
|
|
92
|
+
|
|
93
|
+
var methodName = Utils.getNormalizedApiPath(api.name);
|
|
94
|
+
if (methodName.startsWith(Utils.toFirstLetterLowercase(tag))) {
|
|
95
|
+
methodName = methodName.slice(tag.length);
|
|
96
|
+
methodName = Utils.toFirstLetterLowercase(methodName);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// console.debug(`\tAPI - ${apiName} - ${apiMethod}`);
|
|
100
|
+
if (methodName == "userGeneralInfoTestSave") {
|
|
101
|
+
debugger
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const endpoint = <EndpointDefinitionDart>{
|
|
105
|
+
methodName: methodName,
|
|
106
|
+
httpMethod: api.method.toLowerCase() as HttpMethodDart,
|
|
107
|
+
path: api.url,
|
|
108
|
+
responseType: responseType,
|
|
109
|
+
haveRequest: api.haveRequest,
|
|
110
|
+
requestType: requestType,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
if (api.parameters && api.parameters.length > 0 && !api.haveRequest) {
|
|
114
|
+
endpoint.queryParams = api.parameters
|
|
115
|
+
.map(p => ({
|
|
116
|
+
name: p.name,
|
|
117
|
+
type: p.typeName ? Normalizator.mapTsTypeToDart(p.typeName)! : 'String',
|
|
118
|
+
nullable: p.nullable
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (api.haveRequest && api.parameters[0]?.typeName) {
|
|
123
|
+
if (imports.findIndex(x => x.type.typeName == api.parameters[0]?.typeName) == -1) {
|
|
124
|
+
models.forEach(model => {
|
|
125
|
+
if (model.typeName === api.parameters[0]?.typeName) {
|
|
126
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
127
|
+
imports.push({
|
|
128
|
+
type: api.parameters[0],
|
|
129
|
+
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (api.returnType && !api.returnType.isNativeType) {
|
|
137
|
+
if (imports.findIndex(x => x.type.typeName == api.returnType!.typeName) == -1) {
|
|
138
|
+
models.forEach(model => {
|
|
139
|
+
if (model.typeName === api.returnType!.typeName) {
|
|
140
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
141
|
+
imports.push({
|
|
142
|
+
type: api.returnType!,
|
|
143
|
+
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
endpoints.push(endpoint);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
apiDefinition.endpoints = endpoints;
|
|
154
|
+
apiDefinition.imports = imports.map(i => i.import);
|
|
155
|
+
|
|
156
|
+
let destinationPath = `${this._commandLineArgs.outputDirectory}/${subPath}/api`;
|
|
157
|
+
|
|
158
|
+
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
159
|
+
|
|
160
|
+
var result = Mustache.default.render(template, apiDefinition);
|
|
161
|
+
writeFileSync(`${destinationPath}/${apiDefinition.filename}.dart`, result, 'utf-8');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private _toPascalCase(input: string): string {
|
|
166
|
+
return input
|
|
167
|
+
.replace(/[_\- ]+/g, ' ') // sostituisce underscore, dash e spazi con uno spazio singolo
|
|
168
|
+
.trim() // rimuove spazi iniziali/finali
|
|
169
|
+
.split(' ') // divide in parole
|
|
170
|
+
.map(word =>
|
|
171
|
+
word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
172
|
+
)
|
|
173
|
+
.join('');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private _normalizeApiClassName(input: string): string {
|
|
177
|
+
return input
|
|
178
|
+
.replace(/\./g, '');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private _groupByTag(apis: ApiDto[]) {
|
|
182
|
+
const groupedByRole = apis.reduce<Record<string, ApiDto[]>>((acc, api) => {
|
|
183
|
+
if (!acc[api.tag]) {
|
|
184
|
+
acc[api.tag] = [];
|
|
185
|
+
}
|
|
186
|
+
acc[api.tag].push(api);
|
|
187
|
+
return acc;
|
|
188
|
+
}, {});
|
|
189
|
+
return groupedByRole;
|
|
190
|
+
}
|
|
191
191
|
}
|