-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dynamite_end_to_end_test): Add string enum with a keyword value
Signed-off-by: jld3103 <[email protected]>
- Loading branch information
1 parent
744efe9
commit 8eb397f
Showing
4 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
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.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
packages/dynamite/dynamite_end_to_end_test/test/enum_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
} |