Skip to content

Commit

Permalink
fix(dynamite): to long names for someOf typedefs
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolas Rimikis <[email protected]>
  • Loading branch information
Leptopoda committed Dec 23, 2023
1 parent f2d8516 commit 28c8176
Show file tree
Hide file tree
Showing 21 changed files with 438 additions and 442 deletions.
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"**.mocks.dart",
"**/assets",
"**/l10n/!(en.arb)",
"**/*.openapi.dart",
"external",
"packages/dynamite/dynamite_end_to_end_test/test/*.dart",
"packages/dynamite/dynamite_petstore_example/lib",
"packages/file_icons/lib/src/data.dart",
"packages/neon_lints/lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ String toDartName(
}
}

if (_reservedNames.contains(result) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(result)) {
if (_reservedNames.contains(result) || RegExp(r'^[0-9]+$', multiLine: true).hasMatch(result[0])) {
return '\$$result';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ abstract class TypeResultSomeOf extends TypeResult {
);
}

late final String typeName = _typeName;
late final String typeName = '\$${md5.convert(utf8.encode(_typeName))}';

String get _typeName {
final buffer = StringBuffer();
for (final type in optimizedSubTypes) {
buffer.write(type.className.capitalize());
}

return '\$${toDartName(buffer.toString(), uppercaseFirstCharacter: true)}';
return buffer.toString();
}

BuiltList<TypeResult> get _optimizedSubTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:crypto/crypto.dart';
import 'package:dynamite/src/helpers/dart_helpers.dart';
import 'package:meta/meta.dart';

Expand Down
1 change: 1 addition & 0 deletions packages/dynamite/dynamite/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
checked_yaml: ^2.0.0
code_builder: ^4.5.0
collection: ^1.0.0
crypto: ^3.0.3
dart_style: ^2.0.0
intersperse: ^2.0.0
meta: ^1.0.0
Expand Down
1 change: 1 addition & 0 deletions packages/dynamite/dynamite/test/dart_helpers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void main() {
('lowerCamelCase', 'lowerCamelCase', 'LowerCamelCase'),
('snake_case', 'snakeCase', 'SnakeCase'),
('Upper_Snake_Case', 'upperSnakeCase', 'UpperSnakeCase'),
('10NumberWithText', r'$10NumberWithText', r'$10NumberWithText'),
];

for (final value in values) {
Expand Down
69 changes: 36 additions & 33 deletions packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,31 @@ abstract class OneObjectAnyOf0 implements $OneObjectAnyOf0Interface, Built<OneOb
typedef ObjectAnyOf = ({ObjectAnyOf0? objectAnyOf0, ObjectAnyOf1? objectAnyOf1});
typedef MixedAnyOf = ({MixedAnyOf1? mixedAnyOf1, String? string});
typedef AnyOfIntDoubleOther = ({num? $num, String? string});
typedef $ObjectAnyOf0ObjectAnyOf1 = ({ObjectAnyOf0? objectAnyOf0, ObjectAnyOf1? objectAnyOf1});
typedef $0c9017d9a03ba2eb2f15acadeab85bbe = ({ObjectAnyOf0? objectAnyOf0, ObjectAnyOf1? objectAnyOf1});

extension $ObjectAnyOf0ObjectAnyOf1Extension on $ObjectAnyOf0ObjectAnyOf1 {
extension $0c9017d9a03ba2eb2f15acadeab85bbeExtension on $0c9017d9a03ba2eb2f15acadeab85bbe {
List<dynamic> get _values => [objectAnyOf0, objectAnyOf1];
void validateOneOf() => dynamite_utils.validateOneOf(_values);
void validateAnyOf() => dynamite_utils.validateAnyOf(_values);
static Serializer<$ObjectAnyOf0ObjectAnyOf1> get serializer => const _$ObjectAnyOf0ObjectAnyOf1Serializer();
static $ObjectAnyOf0ObjectAnyOf1 fromJson(Object? json) => jsonSerializers.deserializeWith(serializer, json)!;
static Serializer<$0c9017d9a03ba2eb2f15acadeab85bbe> get serializer =>
const _$0c9017d9a03ba2eb2f15acadeab85bbeSerializer();
static $0c9017d9a03ba2eb2f15acadeab85bbe fromJson(Object? json) => jsonSerializers.deserializeWith(serializer, json)!;
Object? toJson() => jsonSerializers.serializeWith(serializer, this);
}

class _$ObjectAnyOf0ObjectAnyOf1Serializer implements PrimitiveSerializer<$ObjectAnyOf0ObjectAnyOf1> {
const _$ObjectAnyOf0ObjectAnyOf1Serializer();
class _$0c9017d9a03ba2eb2f15acadeab85bbeSerializer implements PrimitiveSerializer<$0c9017d9a03ba2eb2f15acadeab85bbe> {
const _$0c9017d9a03ba2eb2f15acadeab85bbeSerializer();

@override
Iterable<Type> get types => const [$ObjectAnyOf0ObjectAnyOf1];
Iterable<Type> get types => const [$0c9017d9a03ba2eb2f15acadeab85bbe];

@override
String get wireName => r'$ObjectAnyOf0ObjectAnyOf1';
String get wireName => r'$0c9017d9a03ba2eb2f15acadeab85bbe';

@override
Object serialize(
Serializers serializers,
$ObjectAnyOf0ObjectAnyOf1 object, {
$0c9017d9a03ba2eb2f15acadeab85bbe object, {
FullType specifiedType = FullType.unspecified,
}) {
dynamic value;
Expand All @@ -134,7 +135,7 @@ class _$ObjectAnyOf0ObjectAnyOf1Serializer implements PrimitiveSerializer<$Objec
}

@override
$ObjectAnyOf0ObjectAnyOf1 deserialize(
$0c9017d9a03ba2eb2f15acadeab85bbe deserialize(
Serializers serializers,
Object data, {
FullType specifiedType = FullType.unspecified,
Expand All @@ -151,30 +152,31 @@ class _$ObjectAnyOf0ObjectAnyOf1Serializer implements PrimitiveSerializer<$Objec
}
}

typedef $MixedAnyOf1String = ({MixedAnyOf1? mixedAnyOf1, String? string});
typedef $fba45e085ee99d64c5141852d4323e3d = ({MixedAnyOf1? mixedAnyOf1, String? string});

extension $MixedAnyOf1StringExtension on $MixedAnyOf1String {
extension $fba45e085ee99d64c5141852d4323e3dExtension on $fba45e085ee99d64c5141852d4323e3d {
List<dynamic> get _values => [mixedAnyOf1, string];
void validateOneOf() => dynamite_utils.validateOneOf(_values);
void validateAnyOf() => dynamite_utils.validateAnyOf(_values);
static Serializer<$MixedAnyOf1String> get serializer => const _$MixedAnyOf1StringSerializer();
static $MixedAnyOf1String fromJson(Object? json) => jsonSerializers.deserializeWith(serializer, json)!;
static Serializer<$fba45e085ee99d64c5141852d4323e3d> get serializer =>
const _$fba45e085ee99d64c5141852d4323e3dSerializer();
static $fba45e085ee99d64c5141852d4323e3d fromJson(Object? json) => jsonSerializers.deserializeWith(serializer, json)!;
Object? toJson() => jsonSerializers.serializeWith(serializer, this);
}

class _$MixedAnyOf1StringSerializer implements PrimitiveSerializer<$MixedAnyOf1String> {
const _$MixedAnyOf1StringSerializer();
class _$fba45e085ee99d64c5141852d4323e3dSerializer implements PrimitiveSerializer<$fba45e085ee99d64c5141852d4323e3d> {
const _$fba45e085ee99d64c5141852d4323e3dSerializer();

@override
Iterable<Type> get types => const [$MixedAnyOf1String];
Iterable<Type> get types => const [$fba45e085ee99d64c5141852d4323e3d];

@override
String get wireName => r'$MixedAnyOf1String';
String get wireName => r'$fba45e085ee99d64c5141852d4323e3d';

@override
Object serialize(
Serializers serializers,
$MixedAnyOf1String object, {
$fba45e085ee99d64c5141852d4323e3d object, {
FullType specifiedType = FullType.unspecified,
}) {
dynamic value;
Expand All @@ -191,7 +193,7 @@ class _$MixedAnyOf1StringSerializer implements PrimitiveSerializer<$MixedAnyOf1S
}

@override
$MixedAnyOf1String deserialize(
$fba45e085ee99d64c5141852d4323e3d deserialize(
Serializers serializers,
Object data, {
FullType specifiedType = FullType.unspecified,
Expand All @@ -208,30 +210,31 @@ class _$MixedAnyOf1StringSerializer implements PrimitiveSerializer<$MixedAnyOf1S
}
}

typedef $NumString = ({num? $num, String? string});
typedef $b6d67dc2a96424d2f407f8e51557f3de = ({num? $num, String? string});

extension $NumStringExtension on $NumString {
extension $b6d67dc2a96424d2f407f8e51557f3deExtension on $b6d67dc2a96424d2f407f8e51557f3de {
List<dynamic> get _values => [$num, string];
void validateOneOf() => dynamite_utils.validateOneOf(_values);
void validateAnyOf() => dynamite_utils.validateAnyOf(_values);
static Serializer<$NumString> get serializer => const _$NumStringSerializer();
static $NumString fromJson(Object? json) => jsonSerializers.deserializeWith(serializer, json)!;
static Serializer<$b6d67dc2a96424d2f407f8e51557f3de> get serializer =>
const _$b6d67dc2a96424d2f407f8e51557f3deSerializer();
static $b6d67dc2a96424d2f407f8e51557f3de fromJson(Object? json) => jsonSerializers.deserializeWith(serializer, json)!;
Object? toJson() => jsonSerializers.serializeWith(serializer, this);
}

class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
const _$NumStringSerializer();
class _$b6d67dc2a96424d2f407f8e51557f3deSerializer implements PrimitiveSerializer<$b6d67dc2a96424d2f407f8e51557f3de> {
const _$b6d67dc2a96424d2f407f8e51557f3deSerializer();

@override
Iterable<Type> get types => const [$NumString];
Iterable<Type> get types => const [$b6d67dc2a96424d2f407f8e51557f3de];

@override
String get wireName => r'$NumString';
String get wireName => r'$b6d67dc2a96424d2f407f8e51557f3de';

@override
Object serialize(
Serializers serializers,
$NumString object, {
$b6d67dc2a96424d2f407f8e51557f3de object, {
FullType specifiedType = FullType.unspecified,
}) {
dynamic value;
Expand All @@ -248,7 +251,7 @@ class _$NumStringSerializer implements PrimitiveSerializer<$NumString> {
}

@override
$NumString deserialize(
$b6d67dc2a96424d2f407f8e51557f3de deserialize(
Serializers serializers,
Object data, {
FullType specifiedType = FullType.unspecified,
Expand All @@ -272,13 +275,13 @@ final Serializers serializers = (Serializers().toBuilder()
..add(ObjectAnyOf0.serializer)
..addBuilderFactory(const FullType(ObjectAnyOf1), ObjectAnyOf1Builder.new)
..add(ObjectAnyOf1.serializer)
..add($ObjectAnyOf0ObjectAnyOf1Extension.serializer)
..add($0c9017d9a03ba2eb2f15acadeab85bbeExtension.serializer)
..addBuilderFactory(const FullType(MixedAnyOf1), MixedAnyOf1Builder.new)
..add(MixedAnyOf1.serializer)
..add($MixedAnyOf1StringExtension.serializer)
..add($fba45e085ee99d64c5141852d4323e3dExtension.serializer)
..addBuilderFactory(const FullType(OneObjectAnyOf0), OneObjectAnyOf0Builder.new)
..add(OneObjectAnyOf0.serializer)
..add($NumStringExtension.serializer))
..add($b6d67dc2a96424d2f407f8e51557f3deExtension.serializer))
.build();
@visibleForTesting
final Serializers jsonSerializers = (serializers.toBuilder()
Expand Down
Loading

0 comments on commit 28c8176

Please sign in to comment.