@devlearning/swagger-generator 1.0.20 → 1.0.21
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/autogen/identity/api/identity_api.dart +99 -0
- package/autogen/identity/models/auth_activate_command.dart +14 -0
- package/autogen/identity/models/auth_app_authenticate_command.dart +16 -0
- package/autogen/identity/models/auth_generate_reset_password_code_command.dart +15 -0
- package/autogen/identity/models/auth_refresh_token_command.dart +15 -0
- package/autogen/identity/models/auth_reset_password_command.dart +16 -0
- package/autogen/identity/models/auth_user_authenticate_command.dart +15 -0
- package/autogen/identity/models/auth_user_dto.dart +18 -0
- package/autogen/identity/models/auth_verify_reset_password_code_command.dart +14 -0
- package/autogen/identity/models/authentication_token.dart +17 -0
- package/autogen/mvc/models/problem_details.dart +17 -0
- package/autogen/service_defaults/models/application_exception.dart +14 -0
- package/autogen/service_defaults/models/result.dart +17 -0
- package/autogen/user_profile/api/user_profile_api.dart +60 -0
- package/autogen/user_profile/models/test_save_command.dart +13 -0
- package/autogen/user_profile/models/user_general_info_save_command.dart +13 -0
- package/dist/generators-writers/dart/api-dart-writer.js +8 -5
- package/dist/generators-writers/dart/model-dart-writer.js +1 -36
- package/dist/generators-writers/dart/normalizator.js +35 -6
- package/package.json +1 -1
- package/src/generators-writers/dart/api-dart-writer.ts +18 -9
- package/src/generators-writers/dart/model-dart-writer.ts +1 -39
- package/src/generators-writers/dart/normalizator.ts +38 -9
- package/src/generators-writers/dart/templates/api.mustache +11 -6
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import 'package:coqudo_app/core/di/injector.dart';
|
|
2
|
+
import 'package:dio/dio.dart';
|
|
3
|
+
import 'package:coqudo_app/autogen/identity/models/auth_app_authenticate_command.dart';
|
|
4
|
+
import 'package:coqudo_app/autogen/identity/models/authentication_token.dart';
|
|
5
|
+
import 'package:coqudo_app/autogen/identity/models/auth_user_authenticate_command.dart';
|
|
6
|
+
import 'package:coqudo_app/autogen/identity/models/auth_refresh_token_command.dart';
|
|
7
|
+
import 'package:coqudo_app/autogen/identity/models/auth_generate_reset_password_code_command.dart';
|
|
8
|
+
import 'package:coqudo_app/autogen/service_defaults/models/result.dart';
|
|
9
|
+
import 'package:coqudo_app/autogen/identity/models/auth_reset_password_command.dart';
|
|
10
|
+
import 'package:coqudo_app/autogen/identity/models/auth_verify_reset_password_code_command.dart';
|
|
11
|
+
import 'package:coqudo_app/autogen/identity/models/auth_activate_command.dart';
|
|
12
|
+
import 'package:coqudo_app/autogen/identity/models/auth_user_dto.dart';
|
|
13
|
+
|
|
14
|
+
class IdentityApi {
|
|
15
|
+
final Dio _dio;
|
|
16
|
+
|
|
17
|
+
IdentityApi() : _dio = getIt<Dio>();
|
|
18
|
+
|
|
19
|
+
Future<AuthenticationToken> authAppToken(AuthAppAuthenticateCommand request
|
|
20
|
+
Identity.AuthAppAuthenticateCommand request,
|
|
21
|
+
) async {
|
|
22
|
+
final response = await _dio.post(
|
|
23
|
+
'/identity/auth/app/token',
|
|
24
|
+
data: request.toJson(),
|
|
25
|
+
);
|
|
26
|
+
return AuthenticationToken.fromJson(response.data);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
Future<AuthenticationToken> authUserToken(AuthUserAuthenticateCommand request
|
|
30
|
+
Identity.AuthUserAuthenticateCommand request,
|
|
31
|
+
) async {
|
|
32
|
+
final response = await _dio.post(
|
|
33
|
+
'/identity/auth/user/token',
|
|
34
|
+
data: request.toJson(),
|
|
35
|
+
);
|
|
36
|
+
return AuthenticationToken.fromJson(response.data);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Future<AuthenticationToken> authRefreshToken(AuthRefreshTokenCommand request
|
|
40
|
+
Identity.AuthRefreshTokenCommand request,
|
|
41
|
+
) async {
|
|
42
|
+
final response = await _dio.post(
|
|
43
|
+
'/identity/auth/refresh-token',
|
|
44
|
+
data: request.toJson(),
|
|
45
|
+
);
|
|
46
|
+
return AuthenticationToken.fromJson(response.data);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Future<Result> authGenerateResetPasswordCode(AuthGenerateResetPasswordCodeCommand request
|
|
50
|
+
Identity.AuthGenerateResetPasswordCodeCommand request,
|
|
51
|
+
) async {
|
|
52
|
+
final response = await _dio.post(
|
|
53
|
+
'/identity/auth/generate-reset-password-code',
|
|
54
|
+
data: request.toJson(),
|
|
55
|
+
);
|
|
56
|
+
return Result.fromJson(response.data);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Future<Result> authResetPassword(AuthResetPasswordCommand request
|
|
60
|
+
Identity.AuthResetPasswordCommand request,
|
|
61
|
+
) async {
|
|
62
|
+
final response = await _dio.post(
|
|
63
|
+
'/identity/auth/reset-password',
|
|
64
|
+
data: request.toJson(),
|
|
65
|
+
);
|
|
66
|
+
return Result.fromJson(response.data);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Future<Result> authVerifyResetPasswordCode(AuthVerifyResetPasswordCodeCommand request
|
|
70
|
+
Identity.AuthVerifyResetPasswordCodeCommand request,
|
|
71
|
+
) async {
|
|
72
|
+
final response = await _dio.post(
|
|
73
|
+
'/identity/auth/verify-reset-password-code',
|
|
74
|
+
data: request.toJson(),
|
|
75
|
+
);
|
|
76
|
+
return Result.fromJson(response.data);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Future<Result> authActivate(AuthActivateCommand request
|
|
80
|
+
Identity.AuthActivateCommand request,
|
|
81
|
+
) async {
|
|
82
|
+
final response = await _dio.post(
|
|
83
|
+
'/identity/auth/activate',
|
|
84
|
+
data: request.toJson(),
|
|
85
|
+
);
|
|
86
|
+
return Result.fromJson(response.data);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Future<AuthUserDto> authUserRead(
|
|
90
|
+
) async {
|
|
91
|
+
final response = await _dio.get(
|
|
92
|
+
'/identity/auth-user/read',
|
|
93
|
+
queryParameters: {
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
return AuthUserDto.fromJson(response.data);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_activate_command.freezed.dart';
|
|
4
|
+
part 'auth_activate_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthActivateCommand with _$AuthActivateCommand {
|
|
8
|
+
const factory AuthActivateCommand({
|
|
9
|
+
String? username,
|
|
10
|
+
String? activationCode,
|
|
11
|
+
}) = _AuthActivateCommand;
|
|
12
|
+
|
|
13
|
+
factory AuthActivateCommand.fromJson(Map<String, dynamic> json) => _$AuthActivateCommandFromJson(json);
|
|
14
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_app_authenticate_command.freezed.dart';
|
|
4
|
+
part 'auth_app_authenticate_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthAppAuthenticateCommand with _$AuthAppAuthenticateCommand {
|
|
8
|
+
const factory AuthAppAuthenticateCommand({
|
|
9
|
+
String? appId,
|
|
10
|
+
String? secret,
|
|
11
|
+
String? audience,
|
|
12
|
+
String? ipAddress,
|
|
13
|
+
}) = _AuthAppAuthenticateCommand;
|
|
14
|
+
|
|
15
|
+
factory AuthAppAuthenticateCommand.fromJson(Map<String, dynamic> json) => _$AuthAppAuthenticateCommandFromJson(json);
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_generate_reset_password_code_command.freezed.dart';
|
|
4
|
+
part 'auth_generate_reset_password_code_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthGenerateResetPasswordCodeCommand with _$AuthGenerateResetPasswordCodeCommand {
|
|
8
|
+
const factory AuthGenerateResetPasswordCodeCommand({
|
|
9
|
+
String? usernameOrEmail,
|
|
10
|
+
String? host,
|
|
11
|
+
String? urlResetPassword,
|
|
12
|
+
}) = _AuthGenerateResetPasswordCodeCommand;
|
|
13
|
+
|
|
14
|
+
factory AuthGenerateResetPasswordCodeCommand.fromJson(Map<String, dynamic> json) => _$AuthGenerateResetPasswordCodeCommandFromJson(json);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_refresh_token_command.freezed.dart';
|
|
4
|
+
part 'auth_refresh_token_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthRefreshTokenCommand with _$AuthRefreshTokenCommand {
|
|
8
|
+
const factory AuthRefreshTokenCommand({
|
|
9
|
+
String? uniqueName,
|
|
10
|
+
String? refreshToken,
|
|
11
|
+
String? ipAddress,
|
|
12
|
+
}) = _AuthRefreshTokenCommand;
|
|
13
|
+
|
|
14
|
+
factory AuthRefreshTokenCommand.fromJson(Map<String, dynamic> json) => _$AuthRefreshTokenCommandFromJson(json);
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_reset_password_command.freezed.dart';
|
|
4
|
+
part 'auth_reset_password_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthResetPasswordCommand with _$AuthResetPasswordCommand {
|
|
8
|
+
const factory AuthResetPasswordCommand({
|
|
9
|
+
String? usernameOrEmail,
|
|
10
|
+
String? verificationCode,
|
|
11
|
+
String? password,
|
|
12
|
+
String? confirmPassword,
|
|
13
|
+
}) = _AuthResetPasswordCommand;
|
|
14
|
+
|
|
15
|
+
factory AuthResetPasswordCommand.fromJson(Map<String, dynamic> json) => _$AuthResetPasswordCommandFromJson(json);
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_user_authenticate_command.freezed.dart';
|
|
4
|
+
part 'auth_user_authenticate_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthUserAuthenticateCommand with _$AuthUserAuthenticateCommand {
|
|
8
|
+
const factory AuthUserAuthenticateCommand({
|
|
9
|
+
String? username,
|
|
10
|
+
String? password,
|
|
11
|
+
String? ipAddress,
|
|
12
|
+
}) = _AuthUserAuthenticateCommand;
|
|
13
|
+
|
|
14
|
+
factory AuthUserAuthenticateCommand.fromJson(Map<String, dynamic> json) => _$AuthUserAuthenticateCommandFromJson(json);
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_user_dto.freezed.dart';
|
|
4
|
+
part 'auth_user_dto.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthUserDto with _$AuthUserDto {
|
|
8
|
+
const factory AuthUserDto({
|
|
9
|
+
required String idAuthUser,
|
|
10
|
+
required String uniqueId,
|
|
11
|
+
String? username,
|
|
12
|
+
String? email,
|
|
13
|
+
DateTime? activationDate,
|
|
14
|
+
DateTime? lockedDate,
|
|
15
|
+
}) = _AuthUserDto;
|
|
16
|
+
|
|
17
|
+
factory AuthUserDto.fromJson(Map<String, dynamic> json) => _$AuthUserDtoFromJson(json);
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'auth_verify_reset_password_code_command.freezed.dart';
|
|
4
|
+
part 'auth_verify_reset_password_code_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthVerifyResetPasswordCodeCommand with _$AuthVerifyResetPasswordCodeCommand {
|
|
8
|
+
const factory AuthVerifyResetPasswordCodeCommand({
|
|
9
|
+
String? usernameOrEmail,
|
|
10
|
+
String? verificationCode,
|
|
11
|
+
}) = _AuthVerifyResetPasswordCodeCommand;
|
|
12
|
+
|
|
13
|
+
factory AuthVerifyResetPasswordCodeCommand.fromJson(Map<String, dynamic> json) => _$AuthVerifyResetPasswordCodeCommandFromJson(json);
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'authentication_token.freezed.dart';
|
|
4
|
+
part 'authentication_token.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class AuthenticationToken with _$AuthenticationToken {
|
|
8
|
+
const factory AuthenticationToken({
|
|
9
|
+
String? uniqueName,
|
|
10
|
+
String? accessToken,
|
|
11
|
+
int? expiresIn,
|
|
12
|
+
String? refreshToken,
|
|
13
|
+
int? refreshTokenExpiresIn,
|
|
14
|
+
}) = _AuthenticationToken;
|
|
15
|
+
|
|
16
|
+
factory AuthenticationToken.fromJson(Map<String, dynamic> json) => _$AuthenticationTokenFromJson(json);
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'problem_details.freezed.dart';
|
|
4
|
+
part 'problem_details.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class ProblemDetails with _$ProblemDetails {
|
|
8
|
+
const factory ProblemDetails({
|
|
9
|
+
String? type,
|
|
10
|
+
String? title,
|
|
11
|
+
int? status,
|
|
12
|
+
String? detail,
|
|
13
|
+
String? instance,
|
|
14
|
+
}) = _ProblemDetails;
|
|
15
|
+
|
|
16
|
+
factory ProblemDetails.fromJson(Map<String, dynamic> json) => _$ProblemDetailsFromJson(json);
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'application_exception.freezed.dart';
|
|
4
|
+
part 'application_exception.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class ApplicationException with _$ApplicationException {
|
|
8
|
+
const factory ApplicationException({
|
|
9
|
+
String? message,
|
|
10
|
+
String? stackTrace,
|
|
11
|
+
}) = _ApplicationException;
|
|
12
|
+
|
|
13
|
+
factory ApplicationException.fromJson(Map<String, dynamic> json) => _$ApplicationExceptionFromJson(json);
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
import 'package:coqudo_app/autogen/service_defaults/models/application_exception.dart';
|
|
3
|
+
|
|
4
|
+
part 'result.freezed.dart';
|
|
5
|
+
part 'result.g.dart';
|
|
6
|
+
|
|
7
|
+
@freezed
|
|
8
|
+
abstract class Result with _$Result {
|
|
9
|
+
const factory Result({
|
|
10
|
+
required bool isSuccess,
|
|
11
|
+
String? message,
|
|
12
|
+
String? stackTrace,
|
|
13
|
+
ApplicationException? exception,
|
|
14
|
+
}) = _Result;
|
|
15
|
+
|
|
16
|
+
factory Result.fromJson(Map<String, dynamic> json) => _$ResultFromJson(json);
|
|
17
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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/test_save_command.dart';
|
|
5
|
+
import 'package:coqudo_app/autogen/user_profile/models/user_general_info_save_command.dart';
|
|
6
|
+
|
|
7
|
+
class UserProfileApi {
|
|
8
|
+
final Dio _dio;
|
|
9
|
+
|
|
10
|
+
UserProfileApi() : _dio = getIt<Dio>();
|
|
11
|
+
|
|
12
|
+
Future<Result> userGeneralInfoTestRead(
|
|
13
|
+
String name,
|
|
14
|
+
DateTime? date,
|
|
15
|
+
int? integer,
|
|
16
|
+
) async {
|
|
17
|
+
final response = await _dio.get(
|
|
18
|
+
'/user-profile/UserGeneralInfo/test/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> userGeneralInfoTestList(
|
|
29
|
+
String name,
|
|
30
|
+
) async {
|
|
31
|
+
final response = await _dio.get(
|
|
32
|
+
'/user-profile/UserGeneralInfo/test/list',
|
|
33
|
+
queryParameters: {
|
|
34
|
+
'name': name,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
return Result.fromJson(response.data);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Future<Result> userGeneralInfoTestSave(TestSaveCommand request
|
|
41
|
+
UserProfile.TestSaveCommand request,
|
|
42
|
+
) async {
|
|
43
|
+
final response = await _dio.post(
|
|
44
|
+
'/user-profile/UserGeneralInfo/test/save',
|
|
45
|
+
data: request.toJson(),
|
|
46
|
+
);
|
|
47
|
+
return Result.fromJson(response.data);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Future<Result> userGeneralInfoSave(UserGeneralInfoSaveCommand request
|
|
51
|
+
UserProfile.UserGeneralInfoSaveCommand request,
|
|
52
|
+
) async {
|
|
53
|
+
final response = await _dio.post(
|
|
54
|
+
'/user-profile/UserGeneralInfo/save',
|
|
55
|
+
data: request.toJson(),
|
|
56
|
+
);
|
|
57
|
+
return Result.fromJson(response.data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
2
|
+
|
|
3
|
+
part 'test_save_command.freezed.dart';
|
|
4
|
+
part 'test_save_command.g.dart';
|
|
5
|
+
|
|
6
|
+
@freezed
|
|
7
|
+
abstract class TestSaveCommand with _$TestSaveCommand {
|
|
8
|
+
const factory TestSaveCommand({
|
|
9
|
+
String? name,
|
|
10
|
+
}) = _TestSaveCommand;
|
|
11
|
+
|
|
12
|
+
factory TestSaveCommand.fromJson(Map<String, dynamic> json) => _$TestSaveCommandFromJson(json);
|
|
13
|
+
}
|
|
@@ -0,0 +1,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 UserGeneralInfoSaveCommand with _$UserGeneralInfoSaveCommand {
|
|
8
|
+
const factory UserGeneralInfoSaveCommand({
|
|
9
|
+
String? name,
|
|
10
|
+
}) = _UserGeneralInfoSaveCommand;
|
|
11
|
+
|
|
12
|
+
factory UserGeneralInfoSaveCommand.fromJson(Map<String, dynamic> json) => _$UserGeneralInfoSaveCommandFromJson(json);
|
|
13
|
+
}
|
|
@@ -49,10 +49,6 @@ export class ApiDartWriter {
|
|
|
49
49
|
methodName = methodName.slice(tag.length);
|
|
50
50
|
methodName = Utils.toFirstLetterLowercase(methodName);
|
|
51
51
|
}
|
|
52
|
-
// console.debug(`\tAPI - ${apiName} - ${apiMethod}`);
|
|
53
|
-
if (methodName == "userGeneralInfoTestRead") {
|
|
54
|
-
debugger;
|
|
55
|
-
}
|
|
56
52
|
const endpoint = {
|
|
57
53
|
methodName: methodName,
|
|
58
54
|
httpMethod: api.method.toLowerCase(),
|
|
@@ -60,8 +56,15 @@ export class ApiDartWriter {
|
|
|
60
56
|
responseType: responseType,
|
|
61
57
|
haveRequest: api.haveRequest,
|
|
62
58
|
requestType: requestType,
|
|
63
|
-
isGet: api.method.toLowerCase() === 'get'
|
|
64
59
|
};
|
|
60
|
+
if (api.parameters && api.parameters.length > 0) {
|
|
61
|
+
endpoint.queryParams = api.parameters
|
|
62
|
+
.map(p => ({
|
|
63
|
+
name: p.name,
|
|
64
|
+
type: p.typeName ? Normalizator.mapTsTypeToDart(p.typeName) : 'String',
|
|
65
|
+
nullable: p.nullable
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
65
68
|
if (api.haveRequest && api.parameters[0]?.typeName) {
|
|
66
69
|
if (imports.findIndex(x => x.type.typeName == api.parameters[0]?.typeName) == -1) {
|
|
67
70
|
models.forEach(model => {
|
|
@@ -29,7 +29,7 @@ export class ModelDartWriter {
|
|
|
29
29
|
};
|
|
30
30
|
var imports = [];
|
|
31
31
|
model.properties.forEach(property => {
|
|
32
|
-
var fieldTypeName =
|
|
32
|
+
var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
|
|
33
33
|
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
34
34
|
if (property.isTypeReference) {
|
|
35
35
|
if (imports.findIndex(x => x.type.typeName == property.typeName) == -1) {
|
|
@@ -93,39 +93,4 @@ export class ModelDartWriter {
|
|
|
93
93
|
// });
|
|
94
94
|
// this._writeFile(modelString);
|
|
95
95
|
}
|
|
96
|
-
_mapTsTypeToDart(type) {
|
|
97
|
-
const normalized = type.trim().toLowerCase();
|
|
98
|
-
if (normalized.endsWith("[]")) {
|
|
99
|
-
const inner = normalized.slice(0, -2).trim();
|
|
100
|
-
return `List<${this._mapTsTypeToDart(inner)}>`;
|
|
101
|
-
}
|
|
102
|
-
switch (normalized) {
|
|
103
|
-
case "string":
|
|
104
|
-
case "uuid":
|
|
105
|
-
case "date":
|
|
106
|
-
return "String";
|
|
107
|
-
case "dateTime":
|
|
108
|
-
return "DateTime";
|
|
109
|
-
case "number":
|
|
110
|
-
case "float":
|
|
111
|
-
case "double":
|
|
112
|
-
return "double";
|
|
113
|
-
case "integer":
|
|
114
|
-
case "int":
|
|
115
|
-
case "long":
|
|
116
|
-
return "int";
|
|
117
|
-
case "boolean":
|
|
118
|
-
case "bool":
|
|
119
|
-
return "bool";
|
|
120
|
-
case "any":
|
|
121
|
-
case "object":
|
|
122
|
-
return "dynamic";
|
|
123
|
-
case "null":
|
|
124
|
-
case "undefined":
|
|
125
|
-
return "Null";
|
|
126
|
-
default:
|
|
127
|
-
// per tipi personalizzati (es. modelli) restituisci con PascalCase
|
|
128
|
-
return Utils.toPascalCase(type);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
96
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { Utils } from "../utils.js";
|
|
2
2
|
export class Normalizator {
|
|
3
|
-
// public static normalizeModelName(modelName: string): string {
|
|
4
|
-
// let normalizeModelName = modelName.split('.').pop()!;
|
|
5
|
-
// return Utils.toDartClassName(filename) ?? filename;
|
|
6
|
-
// }
|
|
7
|
-
// subPath = model.name.split('.').slice(0, -1).join('');
|
|
8
|
-
// subPath = `${Utils.toDartFileName(subPath)}/models`;
|
|
9
3
|
static getNormalizedInfo(model) {
|
|
10
4
|
let subPath = '';
|
|
11
5
|
let filename = '';
|
|
@@ -32,4 +26,39 @@ export class Normalizator {
|
|
|
32
26
|
let formattedTypeName = typeName.split('.').pop();
|
|
33
27
|
return Utils.toDartClassName(formattedTypeName) ?? typeName;
|
|
34
28
|
}
|
|
29
|
+
static mapTsTypeToDart(type) {
|
|
30
|
+
const normalized = type.trim().toLowerCase();
|
|
31
|
+
if (normalized.endsWith("[]")) {
|
|
32
|
+
const inner = normalized.slice(0, -2).trim();
|
|
33
|
+
return `List<${Normalizator.mapTsTypeToDart(inner)}>`;
|
|
34
|
+
}
|
|
35
|
+
switch (normalized) {
|
|
36
|
+
case "string":
|
|
37
|
+
case "uuid":
|
|
38
|
+
case "date":
|
|
39
|
+
return "String";
|
|
40
|
+
case "dateTime":
|
|
41
|
+
return "DateTime";
|
|
42
|
+
case "number":
|
|
43
|
+
case "float":
|
|
44
|
+
case "double":
|
|
45
|
+
return "double";
|
|
46
|
+
case "integer":
|
|
47
|
+
case "int":
|
|
48
|
+
case "long":
|
|
49
|
+
return "int";
|
|
50
|
+
case "boolean":
|
|
51
|
+
case "bool":
|
|
52
|
+
return "bool";
|
|
53
|
+
case "any":
|
|
54
|
+
case "object":
|
|
55
|
+
return "dynamic";
|
|
56
|
+
case "null":
|
|
57
|
+
case "undefined":
|
|
58
|
+
return "Null";
|
|
59
|
+
default:
|
|
60
|
+
// per tipi personalizzati (es. modelli) restituisci con PascalCase
|
|
61
|
+
return Utils.toPascalCase(type);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
35
64
|
}
|
package/package.json
CHANGED
|
@@ -25,9 +25,15 @@ interface EndpointDefinitionDart {
|
|
|
25
25
|
httpMethod: HttpMethodDart;
|
|
26
26
|
path: string;
|
|
27
27
|
responseType: string;
|
|
28
|
-
haveRequest
|
|
28
|
+
haveRequest: boolean;
|
|
29
29
|
requestType?: string; // solo se haveRequest è true
|
|
30
|
-
|
|
30
|
+
queryParams?: Parameter[],
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface Parameter {
|
|
34
|
+
name: string;
|
|
35
|
+
type: string; // "string", "int", ecc
|
|
36
|
+
nullable: boolean;
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
type HttpMethodDart = 'get' | 'post' | 'put' | 'delete' | 'patch';
|
|
@@ -46,7 +52,7 @@ export class ApiDartWriter {
|
|
|
46
52
|
const templatePath = path.join(__dirname, 'templates', 'api.mustache');
|
|
47
53
|
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
48
54
|
let importDirectory = this._commandLineArgs.outputDirectory;
|
|
49
|
-
if(importDirectory.startsWith('lib/')) {
|
|
55
|
+
if (importDirectory.startsWith('lib/')) {
|
|
50
56
|
importDirectory = importDirectory.slice('lib/'.length);
|
|
51
57
|
}
|
|
52
58
|
|
|
@@ -90,11 +96,6 @@ export class ApiDartWriter {
|
|
|
90
96
|
methodName = Utils.toFirstLetterLowercase(methodName);
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
// console.debug(`\tAPI - ${apiName} - ${apiMethod}`);
|
|
94
|
-
if (methodName == "userGeneralInfoTestRead") {
|
|
95
|
-
debugger
|
|
96
|
-
}
|
|
97
|
-
|
|
98
99
|
const endpoint = <EndpointDefinitionDart>{
|
|
99
100
|
methodName: methodName,
|
|
100
101
|
httpMethod: api.method.toLowerCase() as HttpMethodDart,
|
|
@@ -102,9 +103,17 @@ export class ApiDartWriter {
|
|
|
102
103
|
responseType: responseType,
|
|
103
104
|
haveRequest: api.haveRequest,
|
|
104
105
|
requestType: requestType,
|
|
105
|
-
isGet: api.method.toLowerCase() === 'get'
|
|
106
106
|
};
|
|
107
107
|
|
|
108
|
+
if (api.parameters && api.parameters.length > 0) {
|
|
109
|
+
endpoint.queryParams = api.parameters
|
|
110
|
+
.map(p => ({
|
|
111
|
+
name: p.name,
|
|
112
|
+
type: p.typeName ? Normalizator.mapTsTypeToDart(p.typeName)! : 'String',
|
|
113
|
+
nullable: p.nullable
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
|
|
108
117
|
if (api.haveRequest && api.parameters[0]?.typeName) {
|
|
109
118
|
if (imports.findIndex(x => x.type.typeName == api.parameters[0]?.typeName) == -1) {
|
|
110
119
|
models.forEach(model => {
|
|
@@ -60,7 +60,7 @@ export class ModelDartWriter {
|
|
|
60
60
|
var imports = <ImportDefinitionDart[]>[];
|
|
61
61
|
|
|
62
62
|
model.properties.forEach(property => {
|
|
63
|
-
var fieldTypeName =
|
|
63
|
+
var fieldTypeName = Normalizator.mapTsTypeToDart(property.typeName);
|
|
64
64
|
|
|
65
65
|
fieldTypeName = Normalizator.getNormalizedTypeName(fieldTypeName);
|
|
66
66
|
|
|
@@ -141,42 +141,4 @@ export class ModelDartWriter {
|
|
|
141
141
|
|
|
142
142
|
// this._writeFile(modelString);
|
|
143
143
|
}
|
|
144
|
-
|
|
145
|
-
private _mapTsTypeToDart(type: string): string {
|
|
146
|
-
const normalized = type.trim().toLowerCase();
|
|
147
|
-
|
|
148
|
-
if (normalized.endsWith("[]")) {
|
|
149
|
-
const inner = normalized.slice(0, -2).trim();
|
|
150
|
-
return `List<${this._mapTsTypeToDart(inner)}>`;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
switch (normalized) {
|
|
154
|
-
case "string":
|
|
155
|
-
case "uuid":
|
|
156
|
-
case "date":
|
|
157
|
-
return "String";
|
|
158
|
-
case "dateTime":
|
|
159
|
-
return "DateTime";
|
|
160
|
-
case "number":
|
|
161
|
-
case "float":
|
|
162
|
-
case "double":
|
|
163
|
-
return "double";
|
|
164
|
-
case "integer":
|
|
165
|
-
case "int":
|
|
166
|
-
case "long":
|
|
167
|
-
return "int";
|
|
168
|
-
case "boolean":
|
|
169
|
-
case "bool":
|
|
170
|
-
return "bool";
|
|
171
|
-
case "any":
|
|
172
|
-
case "object":
|
|
173
|
-
return "dynamic";
|
|
174
|
-
case "null":
|
|
175
|
-
case "undefined":
|
|
176
|
-
return "Null";
|
|
177
|
-
default:
|
|
178
|
-
// per tipi personalizzati (es. modelli) restituisci con PascalCase
|
|
179
|
-
return Utils.toPascalCase(type);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
144
|
}
|
|
@@ -3,15 +3,6 @@ import { Utils } from "../utils.js";
|
|
|
3
3
|
|
|
4
4
|
export class Normalizator {
|
|
5
5
|
|
|
6
|
-
// public static normalizeModelName(modelName: string): string {
|
|
7
|
-
// let normalizeModelName = modelName.split('.').pop()!;
|
|
8
|
-
// return Utils.toDartClassName(filename) ?? filename;
|
|
9
|
-
// }
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// subPath = model.name.split('.').slice(0, -1).join('');
|
|
13
|
-
// subPath = `${Utils.toDartFileName(subPath)}/models`;
|
|
14
|
-
|
|
15
6
|
public static getNormalizedInfo(model: ModelDto) {
|
|
16
7
|
let subPath = '';
|
|
17
8
|
let filename = '';
|
|
@@ -41,4 +32,42 @@ export class Normalizator {
|
|
|
41
32
|
return Utils.toDartClassName(formattedTypeName) ?? typeName;
|
|
42
33
|
}
|
|
43
34
|
|
|
35
|
+
public static mapTsTypeToDart(type: string): string {
|
|
36
|
+
const normalized = type.trim().toLowerCase();
|
|
37
|
+
|
|
38
|
+
if (normalized.endsWith("[]")) {
|
|
39
|
+
const inner = normalized.slice(0, -2).trim();
|
|
40
|
+
return `List<${Normalizator.mapTsTypeToDart(inner)}>`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
switch (normalized) {
|
|
44
|
+
case "string":
|
|
45
|
+
case "uuid":
|
|
46
|
+
case "date":
|
|
47
|
+
return "String";
|
|
48
|
+
case "dateTime":
|
|
49
|
+
return "DateTime";
|
|
50
|
+
case "number":
|
|
51
|
+
case "float":
|
|
52
|
+
case "double":
|
|
53
|
+
return "double";
|
|
54
|
+
case "integer":
|
|
55
|
+
case "int":
|
|
56
|
+
case "long":
|
|
57
|
+
return "int";
|
|
58
|
+
case "boolean":
|
|
59
|
+
case "bool":
|
|
60
|
+
return "bool";
|
|
61
|
+
case "any":
|
|
62
|
+
case "object":
|
|
63
|
+
return "dynamic";
|
|
64
|
+
case "null":
|
|
65
|
+
case "undefined":
|
|
66
|
+
return "Null";
|
|
67
|
+
default:
|
|
68
|
+
// per tipi personalizzati (es. modelli) restituisci con PascalCase
|
|
69
|
+
return Utils.toPascalCase(type);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
44
73
|
}
|
|
@@ -10,16 +10,21 @@ class {{apiClassName}} {
|
|
|
10
10
|
{{apiClassName}}() : _dio = getIt<Dio>();
|
|
11
11
|
|
|
12
12
|
{{#endpoints}}
|
|
13
|
-
Future<{{responseType}}> {{methodName}}({{#haveRequest}}{{requestType}} request{{/haveRequest}}
|
|
13
|
+
Future<{{responseType}}> {{methodName}}({{#haveRequest}}{{requestType}} request{{/haveRequest}}
|
|
14
|
+
{{#queryParams}}
|
|
15
|
+
{{type}}{{#nullable}}?{{/nullable}} {{name}},
|
|
16
|
+
{{/queryParams}}) async {
|
|
14
17
|
final response = await _dio.{{httpMethod}}(
|
|
15
18
|
'{{{path}}}',
|
|
16
19
|
{{#haveRequest}}
|
|
17
|
-
{{#isGet}}
|
|
18
|
-
queryParameters: request.toJson(),
|
|
19
|
-
{{/isGet}}
|
|
20
|
-
{{^isGet}}
|
|
21
20
|
data: request.toJson(),
|
|
22
|
-
{{/
|
|
21
|
+
{{/haveRequest}}
|
|
22
|
+
{{^haveRequest}}
|
|
23
|
+
queryParameters: {
|
|
24
|
+
{{#queryParams}}
|
|
25
|
+
{{#nullable}}if ({{name}} != null) {{/nullable}}'{{name}}': {{name}},
|
|
26
|
+
{{/queryParams}}
|
|
27
|
+
},
|
|
23
28
|
{{/haveRequest}}
|
|
24
29
|
);
|
|
25
30
|
return {{responseType}}.fromJson(response.data);
|