Browse Source

Merge pull request #129 from provokateurin/fix/colliding-keyword-names

dynamite,nextcloud: Fix names colliding with keywords
pull/130/head
Kate 2 years ago committed by GitHub
parent
commit
4ce8500199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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

@ -292,8 +292,7 @@ class OpenAPIBuilder implements Builder {
final fields = <String, String>{};
for (final result in results) {
final dartName = _toDartName(result.typeName);
final fieldName = dartName == result.typeName ? '${dartName}_' : dartName;
fields[result.typeName] = fieldName;
fields[result.typeName] = _toFieldName(dartName, result.typeName);
}
b
@ -1249,11 +1248,12 @@ String _toDartName(
result.write(char);
}
if (_dartKeywords.contains(result.toString())) {
return '${result.toString()}_';
final out = result.toString();
if (_dartKeywords.contains(out) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(out)) {
return '\$$out';
}
return result.toString();
return out;
}
final _dartKeywords = [
@ -1320,7 +1320,9 @@ final _dartKeywords = [
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 {
TypeResolveResult(

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

@ -1352,30 +1352,30 @@ class CoreServerCapabilities {
class CoreNavigationApps_Ocs_Data_Order {
CoreNavigationApps_Ocs_Data_Order(
this._data, {
this.int_,
this.$int,
this.string,
});
factory CoreNavigationApps_Ocs_Data_Order.fromJson(dynamic data) {
int? int_;
int? $int;
try {
int_ = data as int;
$int = data as int;
} catch (_) {}
String? string;
try {
string = data as String;
} 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(
data,
int_: int_,
$int: $int,
string: string,
);
}
final dynamic _data;
final int? int_;
final int? $int;
final String? string;
@ -3267,7 +3267,7 @@ class UserStatusClearAt_Time {
UserStatusClearAt_Time(
this._data, {
this.userStatusClearAtTime0,
this.int_,
this.$int,
});
factory UserStatusClearAt_Time.fromJson(dynamic data) {
@ -3275,15 +3275,15 @@ class UserStatusClearAt_Time {
try {
userStatusClearAtTime0 = UserStatusClearAt_Time0.fromValue(data as String);
} catch (_) {}
int? int_;
int? $int;
try {
int_ = data as int;
$int = data as int;
} 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(
data,
userStatusClearAtTime0: userStatusClearAtTime0,
int_: int_,
$int: $int,
);
}
@ -3292,7 +3292,7 @@ class UserStatusClearAt_Time {
final UserStatusClearAt_Time0? userStatusClearAtTime0;
/// Time offset in seconds
final int? int_;
final int? $int;
// coverage:ignore-start
dynamic toJson() => _data;
@ -3321,7 +3321,7 @@ class UserStatusPublicUserStatus_ClearAt {
UserStatusPublicUserStatus_ClearAt(
this._data, {
this.userStatusClearAt,
this.int_,
this.$int,
});
factory UserStatusPublicUserStatus_ClearAt.fromJson(dynamic data) {
@ -3329,14 +3329,14 @@ class UserStatusPublicUserStatus_ClearAt {
try {
userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>);
} catch (_) {}
int? int_;
int? $int;
try {
int_ = data as int;
$int = data as int;
} catch (_) {}
return UserStatusPublicUserStatus_ClearAt(
data,
userStatusClearAt: userStatusClearAt,
int_: int_,
$int: $int,
);
}
@ -3345,7 +3345,7 @@ class UserStatusPublicUserStatus_ClearAt {
final UserStatusClearAt? userStatusClearAt;
/// Time as unix timestamp
final int? int_;
final int? $int;
// coverage:ignore-start
dynamic toJson() => _data;
@ -3501,7 +3501,7 @@ class UserStatus_ClearAt {
UserStatus_ClearAt(
this._data, {
this.userStatusClearAt,
this.int_,
this.$int,
});
factory UserStatus_ClearAt.fromJson(dynamic data) {
@ -3509,14 +3509,14 @@ class UserStatus_ClearAt {
try {
userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>);
} catch (_) {}
int? int_;
int? $int;
try {
int_ = data as int;
$int = data as int;
} catch (_) {}
return UserStatus_ClearAt(
data,
userStatusClearAt: userStatusClearAt,
int_: int_,
$int: $int,
);
}
@ -3525,7 +3525,7 @@ class UserStatus_ClearAt {
final UserStatusClearAt? userStatusClearAt;
/// Time as unix timestamp
final int? int_;
final int? $int;
// coverage:ignore-start
dynamic toJson() => _data;
@ -3630,7 +3630,7 @@ class UserStatusPredefinedStatus_ClearAt {
UserStatusPredefinedStatus_ClearAt(
this._data, {
this.userStatusClearAt,
this.int_,
this.$int,
});
factory UserStatusPredefinedStatus_ClearAt.fromJson(dynamic data) {
@ -3638,14 +3638,14 @@ class UserStatusPredefinedStatus_ClearAt {
try {
userStatusClearAt = UserStatusClearAt.fromJson(data as Map<String, dynamic>);
} catch (_) {}
int? int_;
int? $int;
try {
int_ = data as int;
$int = data as int;
} catch (_) {}
return UserStatusPredefinedStatus_ClearAt(
data,
userStatusClearAt: userStatusClearAt,
int_: int_,
$int: $int,
);
}
@ -3654,7 +3654,7 @@ class UserStatusPredefinedStatus_ClearAt {
final UserStatusClearAt? userStatusClearAt;
/// Time as unix timestamp
final int? int_;
final int? $int;
// coverage:ignore-start
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!;
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!;
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!;
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;
expect(vacationing.userStatusClearAt, null);
expect(vacationing.int_, null);
expect(vacationing.$int, null);
});
test('Set status', () async {
@ -56,7 +56,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, 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!.statusIsUserDefined, true);
});
@ -73,7 +73,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, 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!.statusIsUserDefined, true);
});
@ -90,7 +90,7 @@ Future main() async {
expect(response.ocs.data[0].message, null);
expect(response.ocs.data[0].icon, 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);
});
@ -103,7 +103,7 @@ Future main() async {
expect(response.ocs.data.userStatusPublicUserStatus!.message, null);
expect(response.ocs.data.userStatusPublicUserStatus!.icon, 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);
});
@ -118,7 +118,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageId, 'meeting');
expect(response.ocs.data.userStatus!.messageIsPredefined, true);
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!.statusIsUserDefined, false);
});
@ -135,7 +135,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageId, null);
expect(response.ocs.data.userStatus!.messageIsPredefined, false);
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!.statusIsUserDefined, false);
});
@ -156,7 +156,7 @@ Future main() async {
expect(response.ocs.data.userStatus!.messageIsPredefined, false);
expect(response.ocs.data.userStatus!.icon, 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!.statusIsUserDefined, false);
});
@ -169,7 +169,7 @@ Future main() async {
expect(response.messageIsPredefined, false);
expect(response.icon, null);
expect(response.clearAt.userStatusClearAt, null);
expect(response.clearAt.int_, null);
expect(response.clearAt.$int, null);
expect(response.status, UserStatusType.online);
expect(response.statusIsUserDefined, false);
});

Loading…
Cancel
Save