Skip to content

Commit

Permalink
Support for application/json requests with primitive body types.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpoul committed Aug 27, 2024
1 parent 3eda589 commit a268bf9
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 59 deletions.
3 changes: 2 additions & 1 deletion packages/openapi_base/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.0.0-rc.1
## 2.0.0

* Use UTF-8 encoding by default for json responses.
* Support for dynamic request bodys (instead of just `Map<String, dynamic>`).

## 1.3.2

Expand Down
2 changes: 2 additions & 0 deletions packages/openapi_base/lib/src/openapi_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ abstract class OpenApiRequest {

Future<Map<String, dynamic>> readJsonBody();

Future<dynamic> readJsonBodyDynamic();

Future<Map<String, List<String>>> readUrlEncodedBody();

Future<Map<String, String>> readUrlEncodedBodyFlat() async =>
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi_base/lib/src/openapi_client_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ abstract class OpenApiClientRequestBody {
class OpenApiClientRequestBodyJson extends OpenApiClientRequestBody {
OpenApiClientRequestBodyJson(this.jsonMap);

final Map<String, dynamic> jsonMap;
final /*Map<String, dynamic>*/ dynamic jsonMap;

@override
String encodeToString() => json.encode(jsonMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ class ShelfRequest extends OpenApiRequest {
as Map<String, dynamic>?)!;
}

@override
Future<dynamic> readJsonBodyDynamic() async {
return json.decode(await _request.readAsString());
}

@override
Future<Map<String, List<String>>> readUrlEncodedBody() async {
final query = await _request.readAsString();
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi_base/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: openapi_base
description: Open API base implementation for client/server to be used with openapi_code_builder.
version: 2.0.0-rc.1
version: 2.0.0
homepage: https://github.com/hpoul/openapi_dart/tree/master/packages/openapi_base

environment:
Expand Down
4 changes: 4 additions & 0 deletions packages/openapi_code_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.3

* Support for `application/json` requests with primitive body types.

## 1.3.2+1

* Upgrade `openapi_base` dependency.
Expand Down
5 changes: 5 additions & 0 deletions packages/openapi_code_builder/example/bin/example_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ class TestApiImpl extends TestApi {
return UuidExampleMessageIdGetResponse.response200(
UuidExampleMessageIdGetResponseBody200(id: messageId));
}

@override
Future<HelloIntegerPutResponse> helloIntegerPut(int body) async {
return HelloIntegerPutResponse.response200();
}
}

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

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

102 changes: 102 additions & 0 deletions packages/openapi_code_builder/example/lib/src/api/testapi.openapi.dart

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

Loading

0 comments on commit a268bf9

Please sign in to comment.