Browse Source

dynamite,nextcloud: Fix names colliding with keywords

pull/129/head
jld3103 2 years ago
parent
commit
677627f277
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 14
      packages/dynamite/lib/src/openapi_builder.dart
  2. 54
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  3. 22
      packages/nextcloud/test/user_status_test.dart

14
packages/dynamite/lib/src/openapi_builder.dart

@ -260,8 +260,7 @@ class OpenAPIBuilder implements Builder {
final fields = <String, String>{}; final fields = <String, String>{};
for (final result in results) { for (final result in results) {
final dartName = _toDartName(result.typeName); final dartName = _toDartName(result.typeName);
final fieldName = dartName == result.typeName ? '${dartName}_' : dartName; fields[result.typeName] = _toFieldName(dartName, result.typeName);
fields[result.typeName] = fieldName;
} }
b b
@ -1179,11 +1178,12 @@ String _toDartName(
result.write(char); result.write(char);
} }
if (_dartKeywords.contains(result.toString())) { final out = result.toString();
return '${result.toString()}_'; if (_dartKeywords.contains(out) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(out)) {
return '\$$out';
} }
return result.toString(); return out;
} }
final _dartKeywords = [ final _dartKeywords = [
@ -1250,7 +1250,9 @@ final _dartKeywords = [
bool _isNonAlphaNumericString(final String input) => !RegExp(r'^[a-zA-Z0-9]$').hasMatch(input); bool _isNonAlphaNumericString(final String input) => !RegExp(r'^[a-zA-Z0-9]$').hasMatch(input);
String _makeNullable(final String type, final bool nullable) => nullable ? '$type?' : type; String _makeNullable(final String type, final bool nullable) => nullable && type != 'dynamic' ? '$type?' : type;
String _toFieldName(final String dartName, final String type) => dartName == type ? '\$$dartName' : dartName;
class TypeResolveResult { class TypeResolveResult {
TypeResolveResult( TypeResolveResult(

54
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -1324,30 +1324,30 @@ class CoreServerCapabilities {
class CoreNavigationApps_Ocs_Data_Order { class CoreNavigationApps_Ocs_Data_Order {
CoreNavigationApps_Ocs_Data_Order( CoreNavigationApps_Ocs_Data_Order(
this._data, { this._data, {
this.int_, this.$int,
this.string, this.string,
}); });
factory CoreNavigationApps_Ocs_Data_Order.fromJson(dynamic data) { factory CoreNavigationApps_Ocs_Data_Order.fromJson(dynamic data) {
int? int_; int? $int;
try { try {
int_ = data as int; $int = data as int;
} catch (_) {} } catch (_) {}
String? string; String? string;
try { try {
string = data as String; string = data as String;
} catch (_) {} } catch (_) {}
assert([int_, string].where((final x) => x != null).length == 1, 'Need oneOf'); assert([$int, string].where((final x) => x != null).length == 1, 'Need oneOf');
return CoreNavigationApps_Ocs_Data_Order( return CoreNavigationApps_Ocs_Data_Order(
data, data,
int_: int_, $int: $int,
string: string, string: string,
); );
} }
final dynamic _data; final dynamic _data;
final int? int_; final int? $int;
final String? string; final String? string;
@ -3239,7 +3239,7 @@ class UserStatusClearAt_Time {
UserStatusClearAt_Time( UserStatusClearAt_Time(
this._data, { this._data, {
this.userStatusClearAtTime0, this.userStatusClearAtTime0,
this.int_, this.$int,
}); });
factory UserStatusClearAt_Time.fromJson(dynamic data) { factory UserStatusClearAt_Time.fromJson(dynamic data) {
@ -3247,15 +3247,15 @@ class UserStatusClearAt_Time {
try { try {
userStatusClearAtTime0 = UserStatusClearAt_Time0.fromValue(data as String); userStatusClearAtTime0 = UserStatusClearAt_Time0.fromValue(data as String);
} catch (_) {} } catch (_) {}
int? int_; int? $int;
try { try {
int_ = data as int; $int = data as int;
} catch (_) {} } catch (_) {}
assert([userStatusClearAtTime0, int_].where((final x) => x != null).length == 1, 'Need oneOf'); assert([userStatusClearAtTime0, $int].where((final x) => x != null).length == 1, 'Need oneOf');
return UserStatusClearAt_Time( return UserStatusClearAt_Time(
data, data,
userStatusClearAtTime0: userStatusClearAtTime0, userStatusClearAtTime0: userStatusClearAtTime0,
int_: int_, $int: $int,
); );
} }
@ -3264,7 +3264,7 @@ class UserStatusClearAt_Time {
final UserStatusClearAt_Time0? userStatusClearAtTime0; final UserStatusClearAt_Time0? userStatusClearAtTime0;
/// Time offset in seconds /// Time offset in seconds
final int? int_; final int? $int;
// coverage:ignore-start // coverage:ignore-start
dynamic toJson() => _data; dynamic toJson() => _data;
@ -3293,7 +3293,7 @@ class UserStatusPublicUserStatus_ClearAt {
UserStatusPublicUserStatus_ClearAt( UserStatusPublicUserStatus_ClearAt(
this._data, { this._data, {
this.userStatusClearAt, this.userStatusClearAt,
this.int_, this.$int,
}); });
factory UserStatusPublicUserStatus_ClearAt.fromJson(dynamic data) { factory UserStatusPublicUserStatus_ClearAt.fromJson(dynamic data) {
@ -3301,14 +3301,14 @@ class UserStatusPublicUserStatus_ClearAt {
try { try {
userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>); userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>);
} catch (_) {} } catch (_) {}
int? int_; int? $int;
try { try {
int_ = data as int; $int = data as int;
} catch (_) {} } catch (_) {}
return UserStatusPublicUserStatus_ClearAt( return UserStatusPublicUserStatus_ClearAt(
data, data,
userStatusClearAt: userStatusClearAt, userStatusClearAt: userStatusClearAt,
int_: int_, $int: $int,
); );
} }
@ -3317,7 +3317,7 @@ class UserStatusPublicUserStatus_ClearAt {
final UserStatusClearAt? userStatusClearAt; final UserStatusClearAt? userStatusClearAt;
/// Time as unix timestamp /// Time as unix timestamp
final int? int_; final int? $int;
// coverage:ignore-start // coverage:ignore-start
dynamic toJson() => _data; dynamic toJson() => _data;
@ -3473,7 +3473,7 @@ class UserStatus_ClearAt {
UserStatus_ClearAt( UserStatus_ClearAt(
this._data, { this._data, {
this.userStatusClearAt, this.userStatusClearAt,
this.int_, this.$int,
}); });
factory UserStatus_ClearAt.fromJson(dynamic data) { factory UserStatus_ClearAt.fromJson(dynamic data) {
@ -3481,14 +3481,14 @@ class UserStatus_ClearAt {
try { try {
userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>); userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>);
} catch (_) {} } catch (_) {}
int? int_; int? $int;
try { try {
int_ = data as int; $int = data as int;
} catch (_) {} } catch (_) {}
return UserStatus_ClearAt( return UserStatus_ClearAt(
data, data,
userStatusClearAt: userStatusClearAt, userStatusClearAt: userStatusClearAt,
int_: int_, $int: $int,
); );
} }
@ -3497,7 +3497,7 @@ class UserStatus_ClearAt {
final UserStatusClearAt? userStatusClearAt; final UserStatusClearAt? userStatusClearAt;
/// Time as unix timestamp /// Time as unix timestamp
final int? int_; final int? $int;
// coverage:ignore-start // coverage:ignore-start
dynamic toJson() => _data; dynamic toJson() => _data;
@ -3602,7 +3602,7 @@ class UserStatusPredefinedStatus_ClearAt {
UserStatusPredefinedStatus_ClearAt( UserStatusPredefinedStatus_ClearAt(
this._data, { this._data, {
this.userStatusClearAt, this.userStatusClearAt,
this.int_, this.$int,
}); });
factory UserStatusPredefinedStatus_ClearAt.fromJson(dynamic data) { factory UserStatusPredefinedStatus_ClearAt.fromJson(dynamic data) {
@ -3610,14 +3610,14 @@ class UserStatusPredefinedStatus_ClearAt {
try { try {
userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>); userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>);
} catch (_) {} } catch (_) {}
int? int_; int? $int;
try { try {
int_ = data as int; $int = data as int;
} catch (_) {} } catch (_) {}
return UserStatusPredefinedStatus_ClearAt( return UserStatusPredefinedStatus_ClearAt(
data, data,
userStatusClearAt: userStatusClearAt, userStatusClearAt: userStatusClearAt,
int_: int_, $int: $int,
); );
} }
@ -3626,7 +3626,7 @@ class UserStatusPredefinedStatus_ClearAt {
final UserStatusClearAt? userStatusClearAt; final UserStatusClearAt? userStatusClearAt;
/// Time as unix timestamp /// Time as unix timestamp
final int? int_; final int? $int;
// coverage:ignore-start // coverage:ignore-start
dynamic toJson() => _data; dynamic toJson() => _data;

22
packages/nextcloud/test/user_status_test.dart

@ -28,11 +28,11 @@ Future main() async {
final meeting = response.ocs.data.singleWhere((final s) => s.id == 'meeting').clearAt.userStatusClearAt!; final meeting = response.ocs.data.singleWhere((final s) => s.id == 'meeting').clearAt.userStatusClearAt!;
expect(meeting.type, UserStatusClearAt_Type.period); expect(meeting.type, UserStatusClearAt_Type.period);
expect(meeting.time.int_, 3600); expect(meeting.time.$int, 3600);
final commuting = response.ocs.data.singleWhere((final s) => s.id == 'commuting').clearAt.userStatusClearAt!; final commuting = response.ocs.data.singleWhere((final s) => s.id == 'commuting').clearAt.userStatusClearAt!;
expect(commuting.type, UserStatusClearAt_Type.period); expect(commuting.type, UserStatusClearAt_Type.period);
expect(commuting.time.int_, 1800); expect(commuting.time.$int, 1800);
final remoteWork = response.ocs.data.singleWhere((final s) => s.id == 'remote-work').clearAt.userStatusClearAt!; final remoteWork = response.ocs.data.singleWhere((final s) => s.id == 'remote-work').clearAt.userStatusClearAt!;
expect(remoteWork.type, UserStatusClearAt_Type.endOf); expect(remoteWork.type, UserStatusClearAt_Type.endOf);
@ -44,7 +44,7 @@ Future main() async {
final vacationing = response.ocs.data.singleWhere((final s) => s.id == 'vacationing').clearAt; final vacationing = response.ocs.data.singleWhere((final s) => s.id == 'vacationing').clearAt;
expect(vacationing.userStatusClearAt, null); expect(vacationing.userStatusClearAt, null);
expect(vacationing.int_, null); expect(vacationing.$int, null);
}); });
test('Set status', () async { test('Set status', () async {
@ -56,7 +56,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageIsPredefined, false); expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, null); expect(response.ocs.data.userStatus!.icon, null);
expect(response.ocs.data.userStatus!.clearAt.userStatusClearAt, null); expect(response.ocs.data.userStatus!.clearAt.userStatusClearAt, null);
expect(response.ocs.data.userStatus!.clearAt.int_, null); expect(response.ocs.data.userStatus!.clearAt.$int, null);
expect(response.ocs.data.userStatus!.status, UserStatusType.online); expect(response.ocs.data.userStatus!.status, UserStatusType.online);
expect(response.ocs.data.userStatus!.statusIsUserDefined, true); expect(response.ocs.data.userStatus!.statusIsUserDefined, true);
}); });
@ -73,7 +73,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageIsPredefined, false); expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, null); expect(response.ocs.data.userStatus!.icon, null);
expect(response.ocs.data.userStatus!.clearAt.userStatusClearAt, null); expect(response.ocs.data.userStatus!.clearAt.userStatusClearAt, null);
expect(response.ocs.data.userStatus!.clearAt.int_, null); expect(response.ocs.data.userStatus!.clearAt.$int, null);
expect(response.ocs.data.userStatus!.status, UserStatusType.online); expect(response.ocs.data.userStatus!.status, UserStatusType.online);
expect(response.ocs.data.userStatus!.statusIsUserDefined, true); expect(response.ocs.data.userStatus!.statusIsUserDefined, true);
}); });
@ -90,7 +90,7 @@ Future main() async {
expect(response.ocs.data[0].message, null); expect(response.ocs.data[0].message, null);
expect(response.ocs.data[0].icon, null); expect(response.ocs.data[0].icon, null);
expect(response.ocs.data[0].clearAt.userStatusClearAt, null); expect(response.ocs.data[0].clearAt.userStatusClearAt, null);
expect(response.ocs.data[0].clearAt.int_, null); expect(response.ocs.data[0].clearAt.$int, null);
expect(response.ocs.data[0].status, UserStatusType.online); expect(response.ocs.data[0].status, UserStatusType.online);
}); });
@ -103,7 +103,7 @@ Future main() async {
expect(response.ocs.data.userStatusPublicUserStatus!.message, null); expect(response.ocs.data.userStatusPublicUserStatus!.message, null);
expect(response.ocs.data.userStatusPublicUserStatus!.icon, null); expect(response.ocs.data.userStatusPublicUserStatus!.icon, null);
expect(response.ocs.data.userStatusPublicUserStatus!.clearAt.userStatusClearAt, null); expect(response.ocs.data.userStatusPublicUserStatus!.clearAt.userStatusClearAt, null);
expect(response.ocs.data.userStatusPublicUserStatus!.clearAt.int_, null); expect(response.ocs.data.userStatusPublicUserStatus!.clearAt.$int, null);
expect(response.ocs.data.userStatusPublicUserStatus!.status, UserStatusType.online); expect(response.ocs.data.userStatusPublicUserStatus!.status, UserStatusType.online);
}); });
@ -118,7 +118,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageId, 'meeting'); expect(response.ocs.data.userStatus!.messageId, 'meeting');
expect(response.ocs.data.userStatus!.messageIsPredefined, true); expect(response.ocs.data.userStatus!.messageIsPredefined, true);
expect(response.ocs.data.userStatus!.icon, null); expect(response.ocs.data.userStatus!.icon, null);
expect(response.ocs.data.userStatus!.clearAt.int_, clearAt); expect(response.ocs.data.userStatus!.clearAt.$int, clearAt);
expect(response.ocs.data.userStatus!.status, UserStatusType.offline); expect(response.ocs.data.userStatus!.status, UserStatusType.offline);
expect(response.ocs.data.userStatus!.statusIsUserDefined, false); expect(response.ocs.data.userStatus!.statusIsUserDefined, false);
}); });
@ -135,7 +135,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageId, null); expect(response.ocs.data.userStatus!.messageId, null);
expect(response.ocs.data.userStatus!.messageIsPredefined, false); expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, '😀'); expect(response.ocs.data.userStatus!.icon, '😀');
expect(response.ocs.data.userStatus!.clearAt.int_, clearAt); expect(response.ocs.data.userStatus!.clearAt.$int, clearAt);
expect(response.ocs.data.userStatus!.status, UserStatusType.offline); expect(response.ocs.data.userStatus!.status, UserStatusType.offline);
expect(response.ocs.data.userStatus!.statusIsUserDefined, false); expect(response.ocs.data.userStatus!.statusIsUserDefined, false);
}); });
@ -156,7 +156,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageIsPredefined, false); expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, null); expect(response.ocs.data.userStatus!.icon, null);
expect(response.ocs.data.userStatus!.clearAt.userStatusClearAt, null); expect(response.ocs.data.userStatus!.clearAt.userStatusClearAt, null);
expect(response.ocs.data.userStatus!.clearAt.int_, null); expect(response.ocs.data.userStatus!.clearAt.$int, null);
expect(response.ocs.data.userStatus!.status, UserStatusType.offline); expect(response.ocs.data.userStatus!.status, UserStatusType.offline);
expect(response.ocs.data.userStatus!.statusIsUserDefined, false); expect(response.ocs.data.userStatus!.statusIsUserDefined, false);
}); });
@ -169,7 +169,7 @@ Future main() async {
expect(response.messageIsPredefined, false); expect(response.messageIsPredefined, false);
expect(response.icon, null); expect(response.icon, null);
expect(response.clearAt.userStatusClearAt, null); expect(response.clearAt.userStatusClearAt, null);
expect(response.clearAt.int_, null); expect(response.clearAt.$int, null);
expect(response.status, UserStatusType.online); expect(response.status, UserStatusType.online);
expect(response.statusIsUserDefined, false); expect(response.statusIsUserDefined, false);
}); });

Loading…
Cancel
Save