Skip to content

Commit 821a386

Browse files
authored
Release 5.0.4 (#122)
1 parent 13816de commit 821a386

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [5.0.4] - 2021-05-20
8+
### Fixed
9+
- Missing meta properties in responses
10+
711
## [5.0.3] - 2021-05-19
812
### Fixed
913
- Missing "meta" arguments in RoutingClient
@@ -200,6 +204,7 @@ the Document model.
200204
### Added
201205
- Client: fetch resources, collections, related resources and relationships
202206

207+
[5.0.4]: https://github.com/f3ath/json-api-dart/compare/5.0.3...5.0.4
203208
[5.0.3]: https://github.com/f3ath/json-api-dart/compare/5.0.2...5.0.3
204209
[5.0.2]: https://github.com/f3ath/json-api-dart/compare/5.0.1...5.0.2
205210
[5.0.1]: https://github.com/f3ath/json-api-dart/compare/5.0.0...5.0.1

lib/src/client/response/resource_created.dart

+4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class ResourceCreated {
1717

1818
/// Created resource.
1919
final Resource resource;
20+
21+
/// Top-level meta data
2022
final meta = <String, Object?>{};
23+
24+
/// Top-level links
2125
final links = <String, Link>{};
2226

2327
/// Included resources

lib/src/client/response/resource_fetched.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class ResourceFetched {
1212

1313
final HttpResponse http;
1414
final Resource resource;
15-
final included = ResourceCollection();
1615

1716
/// Top-level meta data
1817
final meta = <String, Object?>{};
1918

20-
/// Top-level links object
19+
/// Top-level links
2120
final links = <String, Link>{};
21+
22+
/// Included resources
23+
final included = ResourceCollection();
2224
}

lib/src/client/response/resource_updated.dart

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import 'package:json_api/document.dart';
22
import 'package:json_api/http.dart';
33

44
class ResourceUpdated {
5-
ResourceUpdated(this.http, Map? json) : resource = _resource(json);
5+
ResourceUpdated(this.http, Map? json) : resource = _resource(json) {
6+
if (json != null) {
7+
included.addAll(InboundDocument(json).included());
8+
meta.addAll(InboundDocument(json).meta());
9+
links.addAll(InboundDocument(json).links());
10+
}
11+
}
612

713
static Resource? _resource(Map? json) {
814
if (json != null) {
@@ -17,4 +23,13 @@ class ResourceUpdated {
1723

1824
/// The created resource. Null for "204 No Content" responses.
1925
late final Resource? resource;
26+
27+
/// Top-level meta data
28+
final meta = <String, Object?>{};
29+
30+
/// Top-level links
31+
final links = <String, Link>{};
32+
33+
/// Included resources
34+
final included = ResourceCollection();
2035
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_api
2-
version: 5.0.3
2+
version: 5.0.4
33
homepage: https://github.com/f3ath/json-api-dart
44
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
55
environment:

test/unit/client/client_test.dart

+14
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ void main() {
7979
});
8080
expect(http.request.headers,
8181
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});
82+
83+
expect(response.meta, {'hello': 'world'});
8284
});
8385

8486
group('Fetch Related Collection', () {
@@ -123,6 +125,8 @@ void main() {
123125
});
124126
expect(http.request.headers,
125127
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});
128+
129+
expect(response.meta, {'hello': 'world'});
126130
});
127131
});
128132

@@ -155,6 +159,8 @@ void main() {
155159
{'include': 'author', 'fields[author]': 'name', 'foo': 'bar'});
156160
expect(http.request.headers,
157161
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});
162+
163+
expect(response.meta, {'hello': 'world'});
158164
});
159165
});
160166

@@ -190,6 +196,8 @@ void main() {
190196
{'include': 'author', 'fields[author]': 'name', 'foo': 'bar'});
191197
expect(http.request.headers,
192198
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});
199+
200+
expect(response.meta, {'hello': 'world'});
193201
});
194202

195203
test('Missing resource', () async {
@@ -295,6 +303,8 @@ void main() {
295303
},
296304
'meta': {'hello': 'world'}
297305
});
306+
307+
expect(response.meta, {'hello': 'world'});
298308
});
299309
});
300310

@@ -376,6 +386,8 @@ void main() {
376386
},
377387
'meta': {'hello': 'world'}
378388
});
389+
390+
expect(response.meta, {'hello': 'world'});
379391
});
380392
});
381393

@@ -458,6 +470,8 @@ void main() {
458470
},
459471
'meta': {'hello': 'world'}
460472
});
473+
474+
expect(response.meta, {'hello': 'world'});
461475
});
462476
});
463477

test/unit/client/response.dart

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final collectionFull = HttpResponse(200,
1818
'next': 'http://example.com/articles?page[offset]=2',
1919
'last': 'http://example.com/articles?page[offset]=10'
2020
},
21+
'meta': {'hello': 'world'},
2122
'data': [
2223
{
2324
'type': 'articles',
@@ -85,6 +86,7 @@ final collectionFull = HttpResponse(200,
8586
final primaryResource = HttpResponse(200,
8687
body: jsonEncode({
8788
'links': {'self': 'http://example.com/articles/1'},
89+
'meta': {'hello': 'world'},
8890
'data': {
8991
'type': 'articles',
9092
'id': '1',
@@ -134,6 +136,7 @@ final primaryResource = HttpResponse(200,
134136
final relatedResourceNull = HttpResponse(200,
135137
body: jsonEncode({
136138
'links': {'self': 'http://example.com/articles/1/author'},
139+
'meta': {'hello': 'world'},
137140
'data': null
138141
}))
139142
..headers.addAll({'Content-Type': mediaType});
@@ -143,6 +146,7 @@ final one = HttpResponse(200,
143146
'self': '/articles/1/relationships/author',
144147
'related': '/articles/1/author'
145148
},
149+
'meta': {'hello': 'world'},
146150
'data': {'type': 'people', 'id': '12'},
147151
'included': [
148152
{
@@ -187,6 +191,7 @@ final oneEmpty = HttpResponse(200,
187191
'self': '/articles/1/relationships/author',
188192
'related': '/articles/1/author'
189193
},
194+
'meta': {'hello': 'world'},
190195
'data': null,
191196
'included': [
192197
{
@@ -231,6 +236,7 @@ final many = HttpResponse(200,
231236
'self': '/articles/1/relationships/tags',
232237
'related': '/articles/1/tags'
233238
},
239+
'meta': {'hello': 'world'},
234240
'data': [
235241
{'type': 'tags', 'id': '12'}
236242
]
@@ -241,6 +247,7 @@ final noContent = HttpResponse(204);
241247

242248
final error422 = HttpResponse(422,
243249
body: jsonEncode({
250+
'meta': {'hello': 'world'},
244251
'errors': [
245252
{
246253
'status': '422',

0 commit comments

Comments
 (0)