Skip to content

Commit

Permalink
feat(dynamite_end_to_end_test): Add string enum with a keyword value
Browse files Browse the repository at this point in the history
Signed-off-by: jld3103 <[email protected]>
  • Loading branch information
provokateurin committed Dec 12, 2023
1 parent 744efe9 commit 8eb397f
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 0 deletions.
57 changes: 57 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// ignore_for_file: camel_case_types
// ignore_for_file: discarded_futures
// ignore_for_file: public_member_api_docs
// ignore_for_file: unreachable_switch_case

import 'package:built_collection/built_collection.dart';
import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:built_value/standard_json_plugin.dart';
import 'package:dynamite_runtime/built_value.dart';
import 'package:dynamite_runtime/http_client.dart';

part 'enum.openapi.g.dart';

class Client extends DynamiteClient {
Client(
super.baseURL, {
super.baseHeaders,
super.userAgent,
super.httpClient,
super.cookieJar,
});

Client.fromClient(final DynamiteClient client)
: super(
client.baseURL,
baseHeaders: client.baseHeaders,
httpClient: client.httpClient,
cookieJar: client.cookieJar,
authentications: client.authentications,
);
}

class EnumString extends EnumClass {
const EnumString._(super.name);

static const EnumString test = _$enumStringTest;

@BuiltValueEnumConst(wireName: 'default')
static const EnumString $default = _$enumStringDefault;

static BuiltSet<EnumString> get values => _$enumStringValues;

static EnumString valueOf(final String name) => _$valueOfEnumString(name);

static Serializer<EnumString> get serializer => _$enumStringSerializer;
}

// coverage:ignore-start
final Serializers _serializers = (Serializers().toBuilder()..add(EnumString.serializer)).build();

final Serializers _jsonSerializers = (_serializers.toBuilder()
..add(DynamiteDoubleSerializer())
..addPlugin(StandardJsonPlugin())
..addPlugin(const ContentStringPlugin()))
.build();
// coverage:ignore-end
52 changes: 52 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"openapi": "3.1.0",
"info": {
"title": "Enum tests",
"version": "0.0.1"
},
"components": {
"schemas": {
"enum-string": {
"type": "string",
"enum": [
"test",
"default"
]
}
}
},
"paths": {},
"tags": []
}
25 changes: 25 additions & 0 deletions packages/dynamite/dynamite_end_to_end_test/test/enum_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:built_value/serializer.dart';
import 'package:dynamite_end_to_end_test/enum.openapi.dart';
import 'package:test/test.dart';

void main() {
final serializers = (Serializers().toBuilder()..add(EnumString.serializer)).build();

group('String', () {
test('serialize', () {
final serialized = serializers.serialize(
EnumString.$default,
specifiedType: const FullType(EnumString),
);
expect(serialized, 'default');
});

test('deserialize', () {
final deserialized = serializers.deserialize(
'default',
specifiedType: const FullType(EnumString),
);
expect(deserialized, EnumString.$default);
});
});
}

0 comments on commit 8eb397f

Please sign in to comment.