@devlearning/swagger-generator 1.0.24 → 1.0.26
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 +22 -22
- package/README.md +209 -209
- package/autogen/identity/api/identity_api.dart +100 -100
- package/autogen/identity/models/auth_activate_command.dart +14 -14
- package/autogen/identity/models/auth_app_authenticate_command.dart +16 -16
- package/autogen/identity/models/auth_generate_reset_password_code_command.dart +15 -15
- package/autogen/identity/models/auth_refresh_token_command.dart +15 -15
- package/autogen/identity/models/auth_reset_password_command.dart +16 -16
- package/autogen/identity/models/auth_user_authenticate_command.dart +15 -15
- package/autogen/identity/models/auth_user_dto.dart +18 -18
- package/autogen/identity/models/auth_verify_reset_password_code_command.dart +14 -14
- package/autogen/identity/models/authentication_token.dart +17 -17
- package/autogen/mvc/models/problem_details.dart +17 -17
- package/autogen/product/api/product_api.dart +70 -0
- package/autogen/product/models/geoposition.dart +14 -0
- package/autogen/product/models/product_category_dto.dart +15 -0
- package/autogen/product/models/product_category_list_query_response.dart +14 -0
- package/autogen/product/models/product_category_save_command.dart +15 -0
- package/autogen/product/models/product_list_nearby_query.dart +20 -0
- package/autogen/product/models/product_list_nearby_query_filter.dart +15 -0
- package/autogen/product/models/product_list_nearby_query_order_by.dart +10 -0
- package/autogen/product/models/product_save_command.dart +13 -0
- package/autogen/service_defaults/models/application_exception.dart +14 -14
- package/autogen/service_defaults/models/result.dart +17 -17
- package/autogen/service_defaults/models/sort_direction.dart +10 -0
- package/autogen/user_profile/api/user_profile_api.dart +51 -62
- package/autogen/user_profile/models/user_general_info_save_command.dart +17 -13
- package/dist/api.constants.js +22 -22
- package/dist/generator.js +9 -4
- 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/model-dart-writer.js +63 -60
- package/dist/generators-writers/dart/templates/api.mustache +36 -36
- package/dist/generators-writers/dart/templates/enum.mustache +14 -0
- package/dist/generators-writers/dart/templates/model.mustache +18 -18
- 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/package.json +45 -45
- package/src/api.constants.ts +26 -26
- package/src/generator-old.ts +449 -449
- package/src/generator.ts +582 -577
- 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 -143
- 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 -0
- package/src/generators-writers/dart/templates/model.mustache +18 -18
- 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/user_profile/models/test_save_command.dart +0 -13
- package/dist/templates/api.mustache +0 -29
- package/dist/templates/model.mustache +0 -18
|
@@ -1,62 +1,51 @@
|
|
|
1
|
-
import 'package:coqudo_app/core/di/injector.dart';
|
|
2
|
-
import 'package:dio/dio.dart';
|
|
3
|
-
import 'package:coqudo_app/autogen/service_defaults/models/result.dart';
|
|
4
|
-
import 'package:coqudo_app/autogen/user_profile/models/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
Future<Result> userGeneralInfoSave(
|
|
53
|
-
UserGeneralInfoSaveCommand request
|
|
54
|
-
) async {
|
|
55
|
-
final response = await _dio.post(
|
|
56
|
-
'/user-profile/UserGeneralInfo/save',
|
|
57
|
-
data: request.toJson(),
|
|
58
|
-
);
|
|
59
|
-
return Result.fromJson(response.data);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}
|
|
1
|
+
import 'package:coqudo_app/core/di/injector.dart';
|
|
2
|
+
import 'package:dio/dio.dart';
|
|
3
|
+
import 'package:coqudo_app/autogen/service_defaults/models/result.dart';
|
|
4
|
+
import 'package:coqudo_app/autogen/user_profile/models/user_general_info_save_command.dart';
|
|
5
|
+
|
|
6
|
+
class UserProfileApi {
|
|
7
|
+
final Dio _dio;
|
|
8
|
+
|
|
9
|
+
UserProfileApi() : _dio = getIt<Dio>();
|
|
10
|
+
|
|
11
|
+
Future<Result> userGeneralInfoRead(
|
|
12
|
+
|
|
13
|
+
String name,
|
|
14
|
+
DateTime? date,
|
|
15
|
+
int? integer,
|
|
16
|
+
) async {
|
|
17
|
+
final response = await _dio.get(
|
|
18
|
+
'/user-profile/UserGeneralInfo/read',
|
|
19
|
+
queryParameters: {
|
|
20
|
+
'name': name,
|
|
21
|
+
if (date != null) 'date': date,
|
|
22
|
+
if (integer != null) 'integer': integer,
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
return Result.fromJson(response.data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Future<Result> userGeneralInfoList(
|
|
29
|
+
|
|
30
|
+
String name,
|
|
31
|
+
) async {
|
|
32
|
+
final response = await _dio.get(
|
|
33
|
+
'/user-profile/UserGeneralInfo/list',
|
|
34
|
+
queryParameters: {
|
|
35
|
+
'name': name,
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
return Result.fromJson(response.data);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Future<Result> userGeneralInfoSave(
|
|
42
|
+
UserGeneralInfoSaveCommand request
|
|
43
|
+
) async {
|
|
44
|
+
final response = await _dio.post(
|
|
45
|
+
'/user-profile/UserGeneralInfo/save',
|
|
46
|
+
data: request.toJson(),
|
|
47
|
+
);
|
|
48
|
+
return Result.fromJson(response.data);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
-
|
|
3
|
-
part 'user_general_info_save_command.freezed.dart';
|
|
4
|
-
part 'user_general_info_save_command.g.dart';
|
|
5
|
-
|
|
6
|
-
@freezed
|
|
7
|
-
abstract class
|
|
8
|
-
const factory
|
|
9
|
-
String?
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'user_general_info_save_command.freezed.dart';
|
|
4
|
+
part 'user_general_info_save_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class with _$ {
|
|
8
|
+
const factory ({
|
|
9
|
+
String? displayName,
|
|
10
|
+
String? profilePictureUrl,
|
|
11
|
+
String? email,
|
|
12
|
+
String? phoneNumber,
|
|
13
|
+
required int avgRating,
|
|
14
|
+
}) = _;
|
|
15
|
+
|
|
16
|
+
factory .fromJson(Map<String, dynamic> json) => _$FromJson(json);
|
|
17
|
+
}
|
package/dist/api.constants.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
-
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
-
import * as Models from './model.autogenerated';
|
|
4
|
-
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
-
|
|
6
|
-
export const httpOptions = {
|
|
7
|
-
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const httpOptionsMultipart = {};
|
|
11
|
-
|
|
12
|
-
export abstract class ApiAutogeneratedService {
|
|
13
|
-
constructor(
|
|
14
|
-
public _http: HttpClient,
|
|
15
|
-
public _baseUrl: string,
|
|
16
|
-
) { }
|
|
17
|
-
|
|
18
|
-
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
-
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
-
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
-
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
-
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
1
|
+
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
+
import * as Models from './model.autogenerated';
|
|
4
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
+
|
|
6
|
+
export const httpOptions = {
|
|
7
|
+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const httpOptionsMultipart = {};
|
|
11
|
+
|
|
12
|
+
export abstract class ApiAutogeneratedService {
|
|
13
|
+
constructor(
|
|
14
|
+
public _http: HttpClient,
|
|
15
|
+
public _baseUrl: string,
|
|
16
|
+
) { }
|
|
17
|
+
|
|
18
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
23
23
|
`;
|
|
24
24
|
export const API_POST = `}`;
|
package/dist/generator.js
CHANGED
|
@@ -417,10 +417,15 @@ export class Generator {
|
|
|
417
417
|
return [];
|
|
418
418
|
let values = [];
|
|
419
419
|
for (let index = 0; index < swaggerCopmponent.enum.length; index++) {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
420
|
+
try {
|
|
421
|
+
values.push({
|
|
422
|
+
name: swaggerCopmponent.enum[index].split('-')[0].trim(),
|
|
423
|
+
value: swaggerCopmponent.enum[index].split('-')[1].trim(),
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
catch (error) {
|
|
427
|
+
debugger;
|
|
428
|
+
}
|
|
424
429
|
}
|
|
425
430
|
return values;
|
|
426
431
|
}
|
|
@@ -23,14 +23,14 @@ export class ApiAngularWriter {
|
|
|
23
23
|
let haveRequest = api.haveRequest;
|
|
24
24
|
let method = api.method.toLowerCase();
|
|
25
25
|
let httpOptions = api.isMultiPart ? 'httpOptionsMultiPart' : 'httpOptions';
|
|
26
|
-
let apiString = `
|
|
27
|
-
public ${apiNameNormalized}(${parametersString}): Observable<${returnTypeString}> {
|
|
28
|
-
${queryParametersPreparation}${requestPreparation}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${api.url}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
29
|
-
.pipe(
|
|
30
|
-
map(x => this._handleResponse(x)),
|
|
31
|
-
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
32
|
-
);
|
|
33
|
-
}
|
|
26
|
+
let apiString = `
|
|
27
|
+
public ${apiNameNormalized}(${parametersString}): Observable<${returnTypeString}> {
|
|
28
|
+
${queryParametersPreparation}${requestPreparation}return this._http.${method}<${returnTypeString}>(\`\${this._baseUrl}${api.url}${queryParameters}\`${haveRequest ? ', wrappedRequest' : ''}, ${httpOptions})
|
|
29
|
+
.pipe(
|
|
30
|
+
map(x => this._handleResponse(x)),
|
|
31
|
+
catchError((err, obs) => this._handleError(err, <Observable<any>>obs))
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
34
|
`;
|
|
35
35
|
return apiString;
|
|
36
36
|
}
|
|
@@ -61,21 +61,21 @@ export class ApiAngularWriter {
|
|
|
61
61
|
_queryParametersPreparationStatement(parameter) {
|
|
62
62
|
if (parameter.nullable) {
|
|
63
63
|
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
64
|
-
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined && ${parameter.name}.isValid() ? encodeURIComponent(this._momentToString(${parameter.name})) : '';
|
|
64
|
+
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined && ${parameter.name}.isValid() ? encodeURIComponent(this._momentToString(${parameter.name})) : '';
|
|
65
65
|
`;
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
|
-
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined ? encodeURIComponent('' + ${parameter.name}) : '';
|
|
68
|
+
return `let ${parameter.name}Param: string = ${parameter.name} != null && ${parameter.name} != undefined ? encodeURIComponent('' + ${parameter.name}) : '';
|
|
69
69
|
`;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
73
|
if (Utils.isDate(parameter.swaggerParameter?.schema)) {
|
|
74
|
-
return `let ${parameter.name}Param: string = encodeURIComponent(this._momentToString(${parameter.name}));
|
|
74
|
+
return `let ${parameter.name}Param: string = encodeURIComponent(this._momentToString(${parameter.name}));
|
|
75
75
|
`;
|
|
76
76
|
}
|
|
77
77
|
else {
|
|
78
|
-
return `let ${parameter.name}Param: string = encodeURIComponent('' + ${parameter.name});
|
|
78
|
+
return `let ${parameter.name}Param: string = encodeURIComponent('' + ${parameter.name});
|
|
79
79
|
`;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -103,12 +103,12 @@ export class ApiAngularWriter {
|
|
|
103
103
|
if (!api.haveRequest) {
|
|
104
104
|
return '';
|
|
105
105
|
}
|
|
106
|
-
return `let wrappedRequest = this._handleRequest(request);
|
|
106
|
+
return `let wrappedRequest = this._handleRequest(request);
|
|
107
107
|
`;
|
|
108
108
|
}
|
|
109
109
|
_writeFile(apis) {
|
|
110
|
-
fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts", `${API_PRE}
|
|
111
|
-
${apis}
|
|
110
|
+
fs.writeFileSync(this._outputDirectory + "/api.autogenerated.ts", `${API_PRE}
|
|
111
|
+
${apis}
|
|
112
112
|
${API_POST}`, { flag: 'w' });
|
|
113
113
|
}
|
|
114
114
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
-
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
-
import * as Models from './model.autogenerated';
|
|
4
|
-
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
-
|
|
6
|
-
export const httpOptions = {
|
|
7
|
-
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const httpOptionsMultipart = {};
|
|
11
|
-
|
|
12
|
-
export abstract class ApiAutogeneratedService {
|
|
13
|
-
constructor(
|
|
14
|
-
public _http: HttpClient,
|
|
15
|
-
public _baseUrl: string,
|
|
16
|
-
) { }
|
|
17
|
-
|
|
18
|
-
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
-
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
-
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
-
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
-
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
1
|
+
export const API_PRE = `import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Observable, catchError, map } from 'rxjs';
|
|
3
|
+
import * as Models from './model.autogenerated';
|
|
4
|
+
import { HttpHeaders } from "@angular/common/http";
|
|
5
|
+
|
|
6
|
+
export const httpOptions = {
|
|
7
|
+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const httpOptionsMultipart = {};
|
|
11
|
+
|
|
12
|
+
export abstract class ApiAutogeneratedService {
|
|
13
|
+
constructor(
|
|
14
|
+
public _http: HttpClient,
|
|
15
|
+
public _baseUrl: string,
|
|
16
|
+
) { }
|
|
17
|
+
|
|
18
|
+
protected abstract _momentToString(moment: moment.Moment): string;
|
|
19
|
+
protected abstract _handleRequest<T>(request: T): T;
|
|
20
|
+
protected abstract _handleMultipart<T>(request: T): FormData;
|
|
21
|
+
protected abstract _handleResponse<T>(response: T): T;
|
|
22
|
+
protected abstract _handleError(error: any, obs: any): Observable<never>;
|
|
23
23
|
`;
|
|
24
24
|
export const API_POST = `}`;
|
|
25
|
-
export const MODEL_PRE = `import * as moment from 'moment';
|
|
25
|
+
export const MODEL_PRE = `import * as moment from 'moment';
|
|
26
26
|
`;
|
|
27
|
-
export const MODEL_POST = `
|
|
27
|
+
export const MODEL_POST = `
|
|
28
28
|
`;
|
|
@@ -13,10 +13,10 @@ export class ModelAngularWriter {
|
|
|
13
13
|
this._writeFile(modelString);
|
|
14
14
|
}
|
|
15
15
|
_modelString(model) {
|
|
16
|
-
let modelString = `
|
|
17
|
-
export ${model.modelType} ${model.name} {
|
|
18
|
-
${this._properties(model)}${this._enumValues(model)}
|
|
19
|
-
}
|
|
16
|
+
let modelString = `
|
|
17
|
+
export ${model.modelType} ${model.name} {
|
|
18
|
+
${this._properties(model)}${this._enumValues(model)}
|
|
19
|
+
}
|
|
20
20
|
`;
|
|
21
21
|
return modelString;
|
|
22
22
|
}
|
|
@@ -38,8 +38,8 @@ ${this._properties(model)}${this._enumValues(model)}
|
|
|
38
38
|
return enumValuesString.trimEnd();
|
|
39
39
|
}
|
|
40
40
|
_writeFile(models) {
|
|
41
|
-
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts", `${MODEL_PRE}
|
|
42
|
-
${models}
|
|
41
|
+
fs.writeFileSync(this._outputDirectory + "/model.autogenerated.ts", `${MODEL_PRE}
|
|
42
|
+
${models}
|
|
43
43
|
${MODEL_POST}`, { flag: 'w' });
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -10,6 +10,10 @@ export class ModelDartWriter {
|
|
|
10
10
|
this._commandLineArgs = commandLineArgs;
|
|
11
11
|
}
|
|
12
12
|
write(models) {
|
|
13
|
+
this.writeEnums(models.filter(m => m.modelType === 'enum'));
|
|
14
|
+
this.writeClasses(models);
|
|
15
|
+
}
|
|
16
|
+
writeClasses(models) {
|
|
13
17
|
const __filename = fileURLToPath(import.meta.url);
|
|
14
18
|
const __dirname = path.dirname(__filename);
|
|
15
19
|
const templatePath = path.join(__dirname, 'templates', 'model.mustache');
|
|
@@ -18,79 +22,78 @@ export class ModelDartWriter {
|
|
|
18
22
|
if (importDirectory.startsWith('lib/')) {
|
|
19
23
|
importDirectory = importDirectory.slice('lib/'.length);
|
|
20
24
|
}
|
|
25
|
+
models.forEach(model => {
|
|
26
|
+
if (model.modelType === 'class' || model.modelType === 'interface') {
|
|
27
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
28
|
+
const dartModel = {
|
|
29
|
+
filename: normalizedInfo.filename,
|
|
30
|
+
path: this._commandLineArgs.outputDirectory,
|
|
31
|
+
className: normalizedInfo.modelName,
|
|
32
|
+
fields: [],
|
|
33
|
+
imports: [],
|
|
34
|
+
};
|
|
35
|
+
var imports = [];
|
|
36
|
+
model.properties.forEach(property => {
|
|
37
|
+
var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
|
|
38
|
+
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
39
|
+
dartModel.fields.push({
|
|
40
|
+
name: property.name,
|
|
41
|
+
type: fieldTypeName,
|
|
42
|
+
typeName: property.typeName,
|
|
43
|
+
nullable: property.nullable ? '?' : '',
|
|
44
|
+
required: property.nullable ? '' : 'required ',
|
|
45
|
+
});
|
|
46
|
+
if (property.isTypeReference) {
|
|
47
|
+
if (imports.findIndex(x => x.type.typeName == property.typeName) == -1) {
|
|
48
|
+
models.forEach(currModel => {
|
|
49
|
+
if (currModel.typeName === property.typeName) {
|
|
50
|
+
const normalizedInfo = Normalizator.getNormalizedInfo(currModel);
|
|
51
|
+
imports.push({
|
|
52
|
+
type: property,
|
|
53
|
+
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
dartModel.imports = imports.map(i => i.import);
|
|
61
|
+
let destinationPath = `${this._commandLineArgs.outputDirectory}/${normalizedInfo.subPath}`;
|
|
62
|
+
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
63
|
+
let result = Mustache.default.render(template, dartModel);
|
|
64
|
+
writeFileSync(`${destinationPath}/${normalizedInfo.filename}.dart`, result, 'utf-8');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
writeEnums(models) {
|
|
69
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
70
|
+
const __dirname = path.dirname(__filename);
|
|
71
|
+
const templatePath = path.join(__dirname, 'templates', 'enum.mustache');
|
|
72
|
+
const template = readFileSync(templatePath, 'utf-8');
|
|
73
|
+
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
74
|
+
if (importDirectory.startsWith('lib/')) {
|
|
75
|
+
importDirectory = importDirectory.slice('lib/'.length);
|
|
76
|
+
}
|
|
21
77
|
models.forEach(model => {
|
|
22
78
|
const normalizedInfo = Normalizator.getNormalizedInfo(model);
|
|
23
79
|
const dartModel = {
|
|
24
|
-
|
|
80
|
+
enumName: normalizedInfo.modelName,
|
|
25
81
|
path: this._commandLineArgs.outputDirectory,
|
|
26
|
-
modelName: normalizedInfo.modelName,
|
|
27
82
|
fields: [],
|
|
28
|
-
imports: [],
|
|
29
83
|
};
|
|
30
|
-
|
|
31
|
-
model.properties.forEach(property => {
|
|
32
|
-
var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
|
|
33
|
-
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
34
|
-
if (property.isTypeReference) {
|
|
35
|
-
if (imports.findIndex(x => x.type.typeName == property.typeName) == -1) {
|
|
36
|
-
models.forEach(currModel => {
|
|
37
|
-
if (currModel.typeName === property.typeName) {
|
|
38
|
-
const normalizedInfo = Normalizator.getNormalizedInfo(currModel);
|
|
39
|
-
imports.push({
|
|
40
|
-
type: property,
|
|
41
|
-
import: `import 'package:${this._commandLineArgs.package}/${importDirectory}/${normalizedInfo.subPath}/${normalizedInfo.filename}.dart';`
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
84
|
+
model.enumValues.forEach(enumItem => {
|
|
47
85
|
dartModel.fields.push({
|
|
48
|
-
name:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
nullable: property.nullable ? '?' : '',
|
|
52
|
-
required: property.nullable ? '' : 'required ',
|
|
86
|
+
name: enumItem.name,
|
|
87
|
+
value: enumItem.value,
|
|
88
|
+
isLast: false,
|
|
53
89
|
});
|
|
54
90
|
});
|
|
55
|
-
|
|
91
|
+
const lastIndex = dartModel.fields.length - 1;
|
|
92
|
+
dartModel.fields[lastIndex].isLast = true;
|
|
56
93
|
let destinationPath = `${this._commandLineArgs.outputDirectory}/${normalizedInfo.subPath}`;
|
|
57
94
|
Utils.ensureDirectorySync(`${destinationPath}`);
|
|
58
95
|
let result = Mustache.default.render(template, dartModel);
|
|
59
96
|
writeFileSync(`${destinationPath}/${normalizedInfo.filename}.dart`, result, 'utf-8');
|
|
60
97
|
});
|
|
61
|
-
// var exportDataModels = <ExportModelItemDefinitionDart[]>[];
|
|
62
|
-
// models.forEach(model => {
|
|
63
|
-
// exportDataModels.push({
|
|
64
|
-
// filename: `${model.filename}.dart`
|
|
65
|
-
// });
|
|
66
|
-
// });
|
|
67
|
-
// var exportData = <ExportModelDefinitionDart>{
|
|
68
|
-
// models: exportDataModels
|
|
69
|
-
// };
|
|
70
|
-
// const exportTemplate = readFileSync('src/generators-writers/dart/templates/model.export.mustache', 'utf-8');
|
|
71
|
-
// const exportContent = Mustache.default.render(exportTemplate, exportData);
|
|
72
|
-
// writeFileSync(`${this._commandLineArgs.outputDirectory}/_export_models.dart`, exportContent, 'utf-8');
|
|
73
|
-
// const model = [
|
|
74
|
-
// {
|
|
75
|
-
// filename: 'login_request',
|
|
76
|
-
// modelName: 'LoginRequest',
|
|
77
|
-
// fields: [
|
|
78
|
-
// { name: 'email', type: 'String' },
|
|
79
|
-
// { name: 'password', type: 'String' }
|
|
80
|
-
// ]
|
|
81
|
-
// },
|
|
82
|
-
// {
|
|
83
|
-
// filename: 'login_response',
|
|
84
|
-
// modelName: 'LoginResponse',
|
|
85
|
-
// fields: [
|
|
86
|
-
// { name: 'token', type: 'String' }
|
|
87
|
-
// ]
|
|
88
|
-
// }
|
|
89
|
-
// ];
|
|
90
|
-
// let modelString = '';
|
|
91
|
-
// models.forEach(model => {
|
|
92
|
-
// modelString += this._modelString(model);
|
|
93
|
-
// });
|
|
94
|
-
// this._writeFile(modelString);
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import 'package:{{package}}/core/di/injector.dart';
|
|
2
|
-
import 'package:dio/dio.dart';
|
|
3
|
-
{{#imports}}
|
|
4
|
-
{{{.}}}
|
|
5
|
-
{{/imports}}
|
|
6
|
-
|
|
7
|
-
class {{apiClassName}} {
|
|
8
|
-
final Dio _dio;
|
|
9
|
-
|
|
10
|
-
{{apiClassName}}() : _dio = getIt<Dio>();
|
|
11
|
-
|
|
12
|
-
{{#endpoints}}
|
|
13
|
-
Future<{{responseType}}> {{methodName}}(
|
|
14
|
-
{{#haveRequest}}{{requestType}} request{{/haveRequest}}
|
|
15
|
-
{{#queryParams}}
|
|
16
|
-
{{type}}{{#nullable}}?{{/nullable}} {{name}},
|
|
17
|
-
{{/queryParams}}
|
|
18
|
-
) async {
|
|
19
|
-
final response = await _dio.{{httpMethod}}(
|
|
20
|
-
'{{{path}}}',
|
|
21
|
-
{{#haveRequest}}
|
|
22
|
-
data: request.toJson(),
|
|
23
|
-
{{/haveRequest}}
|
|
24
|
-
{{^haveRequest}}
|
|
25
|
-
queryParameters: {
|
|
26
|
-
{{#queryParams}}
|
|
27
|
-
{{#nullable}}if ({{name}} != null) {{/nullable}}'{{name}}': {{name}},
|
|
28
|
-
{{/queryParams}}
|
|
29
|
-
},
|
|
30
|
-
{{/haveRequest}}
|
|
31
|
-
);
|
|
32
|
-
return {{responseType}}.fromJson(response.data);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
{{/endpoints}}
|
|
36
|
-
}
|
|
1
|
+
import 'package:{{package}}/core/di/injector.dart';
|
|
2
|
+
import 'package:dio/dio.dart';
|
|
3
|
+
{{#imports}}
|
|
4
|
+
{{{.}}}
|
|
5
|
+
{{/imports}}
|
|
6
|
+
|
|
7
|
+
class {{apiClassName}} {
|
|
8
|
+
final Dio _dio;
|
|
9
|
+
|
|
10
|
+
{{apiClassName}}() : _dio = getIt<Dio>();
|
|
11
|
+
|
|
12
|
+
{{#endpoints}}
|
|
13
|
+
Future<{{responseType}}> {{methodName}}(
|
|
14
|
+
{{#haveRequest}}{{requestType}} request{{/haveRequest}}
|
|
15
|
+
{{#queryParams}}
|
|
16
|
+
{{type}}{{#nullable}}?{{/nullable}} {{name}},
|
|
17
|
+
{{/queryParams}}
|
|
18
|
+
) async {
|
|
19
|
+
final response = await _dio.{{httpMethod}}(
|
|
20
|
+
'{{{path}}}',
|
|
21
|
+
{{#haveRequest}}
|
|
22
|
+
data: request.toJson(),
|
|
23
|
+
{{/haveRequest}}
|
|
24
|
+
{{^haveRequest}}
|
|
25
|
+
queryParameters: {
|
|
26
|
+
{{#queryParams}}
|
|
27
|
+
{{#nullable}}if ({{name}} != null) {{/nullable}}'{{name}}': {{name}},
|
|
28
|
+
{{/queryParams}}
|
|
29
|
+
},
|
|
30
|
+
{{/haveRequest}}
|
|
31
|
+
);
|
|
32
|
+
return {{responseType}}.fromJson(response.data);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
{{/endpoints}}
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
{{#imports}}
|
|
3
|
+
{{{.}}}
|
|
4
|
+
{{/imports}}
|
|
5
|
+
|
|
6
|
+
@JsonEnum(fieldRename: FieldRename.pascal)
|
|
7
|
+
enum {{enumName}} {
|
|
8
|
+
{{#fields}}
|
|
9
|
+
{{name}}({{value}}){{#isLast}};{{/isLast}}{{^isLast}},{{/isLast}}
|
|
10
|
+
{{/fields}}
|
|
11
|
+
|
|
12
|
+
final int value;
|
|
13
|
+
const {{enumName}}(this.value);
|
|
14
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
-
{{#imports}}
|
|
3
|
-
{{{.}}}
|
|
4
|
-
{{/imports}}
|
|
5
|
-
|
|
6
|
-
part '{{filename}}.freezed.dart';
|
|
7
|
-
part '{{filename}}.g.dart';
|
|
8
|
-
|
|
9
|
-
@freezed
|
|
10
|
-
abstract class {{
|
|
11
|
-
const factory {{
|
|
12
|
-
{{#fields}}
|
|
13
|
-
{{required}}{{type}}{{nullable}} {{name}},
|
|
14
|
-
{{/fields}}
|
|
15
|
-
}) = _{{
|
|
16
|
-
|
|
17
|
-
factory {{
|
|
18
|
-
}
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
{{#imports}}
|
|
3
|
+
{{{.}}}
|
|
4
|
+
{{/imports}}
|
|
5
|
+
|
|
6
|
+
part '{{filename}}.freezed.dart';
|
|
7
|
+
part '{{filename}}.g.dart';
|
|
8
|
+
|
|
9
|
+
@freezed
|
|
10
|
+
abstract class {{className}} with _${{className}} {
|
|
11
|
+
const factory {{className}}({
|
|
12
|
+
{{#fields}}
|
|
13
|
+
{{required}}{{type}}{{nullable}} {{name}},
|
|
14
|
+
{{/fields}}
|
|
15
|
+
}) = _{{className}};
|
|
16
|
+
|
|
17
|
+
factory {{className}}.fromJson(Map<String, dynamic> json) => _${{className}}FromJson(json);
|
|
18
|
+
}
|