From ccfc4753885cb42fb20f134ae75874c316597af6 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Wed, 7 Jun 2023 19:09:56 +0200 Subject: [PATCH 1/4] dynamite: move TypeResult into it's own lib --- packages/dynamite/dynamite/lib/dynamite.dart | 8 +------- packages/dynamite/dynamite/lib/src/type_result/base.dart | 2 +- packages/dynamite/dynamite/lib/src/type_result/enum.dart | 2 +- packages/dynamite/dynamite/lib/src/type_result/list.dart | 2 +- packages/dynamite/dynamite/lib/src/type_result/map.dart | 2 +- .../dynamite/dynamite/lib/src/type_result/object.dart | 2 +- .../dynamite/lib/src/type_result/type_result.dart | 9 ++++++++- packages/dynamite/dynamite/test/type_result_test.dart | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/dynamite/dynamite/lib/dynamite.dart b/packages/dynamite/dynamite/lib/dynamite.dart index c5397acb..ae668694 100644 --- a/packages/dynamite/dynamite/lib/dynamite.dart +++ b/packages/dynamite/dynamite/lib/dynamite.dart @@ -9,13 +9,7 @@ import 'package:dynamite/src/models/open_api.dart'; import 'package:dynamite/src/models/parameter.dart' as spec_parameter; import 'package:dynamite/src/models/path_item.dart'; import 'package:dynamite/src/models/schema.dart'; -import 'package:intersperse/intersperse.dart'; +import 'package:dynamite/src/type_result/type_result.dart'; import 'package:path/path.dart' as p; part 'src/openapi_builder.dart'; -part 'src/type_result/base.dart'; -part 'src/type_result/enum.dart'; -part 'src/type_result/list.dart'; -part 'src/type_result/map.dart'; -part 'src/type_result/object.dart'; -part 'src/type_result/type_result.dart'; diff --git a/packages/dynamite/dynamite/lib/src/type_result/base.dart b/packages/dynamite/dynamite/lib/src/type_result/base.dart index a9e93996..c8b5db5f 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/base.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/base.dart @@ -1,4 +1,4 @@ -part of '../../dynamite.dart'; +part of 'type_result.dart'; class TypeResultBase extends TypeResult { TypeResultBase( diff --git a/packages/dynamite/dynamite/lib/src/type_result/enum.dart b/packages/dynamite/dynamite/lib/src/type_result/enum.dart index 54e59a70..34901958 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/enum.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/enum.dart @@ -1,4 +1,4 @@ -part of '../../dynamite.dart'; +part of 'type_result.dart'; class TypeResultEnum extends TypeResult { TypeResultEnum( diff --git a/packages/dynamite/dynamite/lib/src/type_result/list.dart b/packages/dynamite/dynamite/lib/src/type_result/list.dart index db00cff9..472ccc83 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/list.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/list.dart @@ -1,4 +1,4 @@ -part of '../../dynamite.dart'; +part of 'type_result.dart'; class TypeResultList extends TypeResult { TypeResultList( diff --git a/packages/dynamite/dynamite/lib/src/type_result/map.dart b/packages/dynamite/dynamite/lib/src/type_result/map.dart index 6e0efdcc..c4d576cb 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/map.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/map.dart @@ -1,4 +1,4 @@ -part of '../../dynamite.dart'; +part of 'type_result.dart'; class TypeResultMap extends TypeResult { TypeResultMap( diff --git a/packages/dynamite/dynamite/lib/src/type_result/object.dart b/packages/dynamite/dynamite/lib/src/type_result/object.dart index c93c049c..47841de5 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/object.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/object.dart @@ -1,4 +1,4 @@ -part of '../../dynamite.dart'; +part of 'type_result.dart'; const _contentString = 'ContentString'; diff --git a/packages/dynamite/dynamite/lib/src/type_result/type_result.dart b/packages/dynamite/dynamite/lib/src/type_result/type_result.dart index 950fb70e..ed0d1d2e 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/type_result.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/type_result.dart @@ -1,4 +1,11 @@ -part of '../../dynamite.dart'; +import 'package:intersperse/intersperse.dart'; +import 'package:meta/meta.dart'; + +part 'base.dart'; +part 'enum.dart'; +part 'list.dart'; +part 'map.dart'; +part 'object.dart'; abstract class TypeResult { TypeResult( diff --git a/packages/dynamite/dynamite/test/type_result_test.dart b/packages/dynamite/dynamite/test/type_result_test.dart index 34ec95f4..903475f3 100644 --- a/packages/dynamite/dynamite/test/type_result_test.dart +++ b/packages/dynamite/dynamite/test/type_result_test.dart @@ -1,4 +1,4 @@ -import 'package:dynamite/dynamite.dart'; +import 'package:dynamite/src/type_result/type_result.dart'; import 'package:test/test.dart'; void main() { From cff12fd6cc90a92c621685f7e0347ebc17d99094 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Wed, 7 Jun 2023 19:13:00 +0200 Subject: [PATCH 2/4] dynamite: make TypeResult immutable and add equality operator --- .../dynamite/dynamite/lib/src/type_result/base.dart | 1 + .../dynamite/dynamite/lib/src/type_result/enum.dart | 12 ++++++++++++ .../dynamite/dynamite/lib/src/type_result/list.dart | 12 ++++++++++++ .../dynamite/dynamite/lib/src/type_result/map.dart | 12 ++++++++++++ .../dynamite/lib/src/type_result/object.dart | 1 + .../dynamite/lib/src/type_result/type_result.dart | 8 ++++++++ packages/dynamite/dynamite/pubspec.yaml | 1 + 7 files changed, 47 insertions(+) diff --git a/packages/dynamite/dynamite/lib/src/type_result/base.dart b/packages/dynamite/dynamite/lib/src/type_result/base.dart index c8b5db5f..08a006ba 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/base.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/base.dart @@ -1,5 +1,6 @@ part of 'type_result.dart'; +@immutable class TypeResultBase extends TypeResult { TypeResultBase( super.name, { diff --git a/packages/dynamite/dynamite/lib/src/type_result/enum.dart b/packages/dynamite/dynamite/lib/src/type_result/enum.dart index 34901958..7ef627a0 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/enum.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/enum.dart @@ -1,5 +1,6 @@ part of 'type_result.dart'; +@immutable class TypeResultEnum extends TypeResult { TypeResultEnum( super.name, @@ -27,4 +28,15 @@ class TypeResultEnum extends TypeResult { @override String decode(final String object) => subType.decode(object); + + @override + bool operator ==(final Object other) => + other is TypeResultEnum && + other.className == className && + other.generics == generics && + other.nullable == nullable && + other.subType == subType; + + @override + int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode + subType.hashCode; } diff --git a/packages/dynamite/dynamite/lib/src/type_result/list.dart b/packages/dynamite/dynamite/lib/src/type_result/list.dart index 472ccc83..2034436e 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/list.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/list.dart @@ -1,5 +1,6 @@ part of 'type_result.dart'; +@immutable class TypeResultList extends TypeResult { TypeResultList( super.name, @@ -27,4 +28,15 @@ class TypeResultList extends TypeResult { @override TypeResultList get dartType => TypeResultList('List', subType, nullable: nullable); + + @override + bool operator ==(final Object other) => + other is TypeResultList && + other.className == className && + other.generics == generics && + other.nullable == nullable && + other.subType == subType; + + @override + int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode + subType.hashCode; } diff --git a/packages/dynamite/dynamite/lib/src/type_result/map.dart b/packages/dynamite/dynamite/lib/src/type_result/map.dart index c4d576cb..0050354d 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/map.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/map.dart @@ -1,5 +1,6 @@ part of 'type_result.dart'; +@immutable class TypeResultMap extends TypeResult { TypeResultMap( super.name, @@ -14,4 +15,15 @@ class TypeResultMap extends TypeResult { @override TypeResultMap get dartType => TypeResultMap('Map', subType, nullable: nullable); + + @override + bool operator ==(final Object other) => + other is TypeResultMap && + other.className == className && + other.generics == generics && + other.nullable == nullable && + other.subType == subType; + + @override + int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode + subType.hashCode; } diff --git a/packages/dynamite/dynamite/lib/src/type_result/object.dart b/packages/dynamite/dynamite/lib/src/type_result/object.dart index 47841de5..b6f94bc3 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/object.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/object.dart @@ -2,6 +2,7 @@ part of 'type_result.dart'; const _contentString = 'ContentString'; +@immutable class TypeResultObject extends TypeResult { TypeResultObject( super.className, { diff --git a/packages/dynamite/dynamite/lib/src/type_result/type_result.dart b/packages/dynamite/dynamite/lib/src/type_result/type_result.dart index ed0d1d2e..e295f758 100644 --- a/packages/dynamite/dynamite/lib/src/type_result/type_result.dart +++ b/packages/dynamite/dynamite/lib/src/type_result/type_result.dart @@ -7,6 +7,7 @@ part 'list.dart'; part 'map.dart'; part 'object.dart'; +@immutable abstract class TypeResult { TypeResult( this.className, { @@ -91,4 +92,11 @@ abstract class TypeResult { /// Native dart type equivalent // ignore: avoid_returning_this TypeResult get dartType => this; + + @override + bool operator ==(final Object other) => + other is TypeResult && other.className == className && other.generics == generics && other.nullable == nullable; + + @override + int get hashCode => className.hashCode + generics.hashCode + nullable.hashCode; } diff --git a/packages/dynamite/dynamite/pubspec.yaml b/packages/dynamite/dynamite/pubspec.yaml index f8781950..0a134f6b 100644 --- a/packages/dynamite/dynamite/pubspec.yaml +++ b/packages/dynamite/dynamite/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: dart_style: ^2.3.1 intersperse: ^2.0.0 json_annotation: ^4.8.1 + meta: ^1.9.1 path: ^1.8.3 dev_dependencies: From b7b7fef3c34678caedfb0b3a39bd53be10c81efd Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Wed, 7 Jun 2023 19:13:56 +0200 Subject: [PATCH 3/4] dynamite: make registered state a Set to avoid duplicates --- packages/dynamite/dynamite/lib/src/openapi_builder.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index e0d79198..bd3b550d 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -1228,10 +1228,10 @@ class State { State(this.prefix); final String prefix; - final resolvedTypes = []; - final registeredJsonObjects = []; + final resolvedTypes = {}; + final registeredJsonObjects = {}; final output = []; - final resolvedTypeCombinations = []; + final resolvedTypeCombinations = {}; } TypeResult resolveObject( From 1128f1cdd167fe45527e2a6bdb0fe1b246c49869 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Wed, 7 Jun 2023 19:15:34 +0200 Subject: [PATCH 4/4] nextcloud: rebuild to avoid duplicate builderFacvtories --- packages/nextcloud/lib/src/nextcloud.openapi.dart | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index 83bb5cd1..6635d88a 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -5182,20 +5182,14 @@ final Serializers serializers = (_$serializers.toBuilder() ..addBuilderFactory(const FullType(NextcloudCoreAutocompleteResult), NextcloudCoreAutocompleteResult.new) ..addBuilderFactory(const FullType(NextcloudNewsSupportedAPIVersions), NextcloudNewsSupportedAPIVersions.new) ..addBuilderFactory(const FullType(NextcloudNewsListFolders), NextcloudNewsListFolders.new) - ..addBuilderFactory(const FullType(NextcloudNewsListFolders), NextcloudNewsListFolders.new) - ..addBuilderFactory(const FullType(NextcloudNewsListFeeds), NextcloudNewsListFeeds.new) ..addBuilderFactory(const FullType(NextcloudNewsListFeeds), NextcloudNewsListFeeds.new) ..addBuilderFactory(const FullType(NextcloudNewsListArticles), NextcloudNewsListArticles.new) - ..addBuilderFactory(const FullType(NextcloudNewsListArticles), NextcloudNewsListArticles.new) ..addBuilderFactory(const FullType(NextcloudNotesNote), NextcloudNotesNote.new) ..addBuilderFactory( const FullType(BuiltList, [FullType(NextcloudNotesNote)]), ListBuilder.new, ) ..addBuilderFactory(const FullType(NextcloudNotesNote), NextcloudNotesNote.new) - ..addBuilderFactory(const FullType(NextcloudNotesNote), NextcloudNotesNote.new) - ..addBuilderFactory(const FullType(NextcloudNotesNote), NextcloudNotesNote.new) - ..addBuilderFactory(const FullType(NextcloudNotesSettings), NextcloudNotesSettings.new) ..addBuilderFactory(const FullType(NextcloudNotesSettings), NextcloudNotesSettings.new) ..addBuilderFactory( const FullType(NextcloudNotificationsListNotifications), @@ -5210,8 +5204,6 @@ final Serializers serializers = (_$serializers.toBuilder() const FullType(NextcloudNotificationsPushServerRegistration), NextcloudNotificationsPushServerRegistration.new, ) - ..addBuilderFactory(const FullType(NextcloudEmptyOCS), NextcloudEmptyOCS.new) - ..addBuilderFactory(const FullType(NextcloudProvisioningApiUser), NextcloudProvisioningApiUser.new) ..addBuilderFactory(const FullType(NextcloudProvisioningApiUser), NextcloudProvisioningApiUser.new) ..addBuilderFactory( const FullType(NextcloudUnifiedPushProviderCheckResponse200ApplicationJson), @@ -5263,9 +5255,6 @@ final Serializers serializers = (_$serializers.toBuilder() ) ..addBuilderFactory(const FullType(NextcloudUserStatusGetPublicStatus), NextcloudUserStatusGetPublicStatus.new) ..addBuilderFactory(const FullType(NextcloudUserStatusGetStatus), NextcloudUserStatusGetStatus.new) - ..addBuilderFactory(const FullType(NextcloudUserStatusGetStatus), NextcloudUserStatusGetStatus.new) - ..addBuilderFactory(const FullType(NextcloudUserStatusGetStatus), NextcloudUserStatusGetStatus.new) - ..addBuilderFactory(const FullType(NextcloudUserStatusGetStatus), NextcloudUserStatusGetStatus.new) ..addBuilderFactory( const FullType(NextcloudUserStatusPredefinedStatuses), NextcloudUserStatusPredefinedStatuses.new,