-
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 request body test
Signed-off-by: jld3103 <[email protected]>
- Loading branch information
1 parent
43857ae
commit 8d07c57
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
packages/dynamite/dynamite_end_to_end_test/lib/request_body.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,94 @@ | ||
// 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 'dart:typed_data'; | ||
|
||
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'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:universal_io/io.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, | ||
); | ||
|
||
/// Returns a [Future] containing a [DynamiteResponse] with the status code, deserialized body and headers. | ||
/// Throws a [DynamiteApiException] if the API call does not return an expected status code. | ||
/// | ||
/// Status codes: | ||
/// * default | ||
/// | ||
/// See: | ||
/// * [$getRaw] for an experimental operation that returns a [DynamiteRawResponse] that can be serialized. | ||
Future<DynamiteResponse<void, void>> $get({final Uint8List? uint8List}) async { | ||
final rawResponse = $getRaw( | ||
uint8List: uint8List, | ||
); | ||
|
||
return rawResponse.future; | ||
} | ||
|
||
/// This method and the response it returns is experimental. The API might change without a major version bump. | ||
/// | ||
/// Returns a [Future] containing a [DynamiteRawResponse] with the raw [HttpClientResponse] and serialization helpers. | ||
/// Throws a [DynamiteApiException] if the API call does not return an expected status code. | ||
/// | ||
/// Status codes: | ||
/// * default | ||
/// | ||
/// See: | ||
/// * [$get] for an operation that returns a [DynamiteResponse] with a stable API. | ||
@experimental | ||
DynamiteRawResponse<void, void> $getRaw({final Uint8List? uint8List}) { | ||
final queryParameters = <String, dynamic>{}; | ||
final headers = <String, String>{}; | ||
Uint8List? body; | ||
|
||
headers['Content-Type'] = 'application/octet-stream'; | ||
if (uint8List != null) { | ||
body = uint8List; | ||
} | ||
const path = '/'; | ||
final uri = Uri(path: path, queryParameters: queryParameters.isNotEmpty ? queryParameters : null); | ||
|
||
return DynamiteRawResponse<void, void>( | ||
response: executeRequest( | ||
'get', | ||
uri, | ||
headers, | ||
body, | ||
null, | ||
), | ||
bodyType: null, | ||
headersType: null, | ||
serializers: _jsonSerializers, | ||
); | ||
} | ||
} | ||
|
||
// coverage:ignore-start | ||
final Serializers _serializers = Serializers().toBuilder().build(); | ||
|
||
final Serializers _jsonSerializers = (_serializers.toBuilder() | ||
..add(DynamiteDoubleSerializer()) | ||
..addPlugin(StandardJsonPlugin()) | ||
..addPlugin(const ContentStringPlugin())) | ||
.build(); | ||
// coverage:ignore-end |
28 changes: 28 additions & 0 deletions
28
packages/dynamite/dynamite_end_to_end_test/lib/request_body.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,28 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "request body test", | ||
"version": "0.0.1" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"requestBody": { | ||
"content": { | ||
"application/octet-stream": { | ||
"schema": { | ||
"type": "string", | ||
"format": "binary" | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"default": { | ||
"description": "" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |