Skip to content

Release 5.0.4 #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.0.4] - 2021-05-20
### Fixed
- Missing meta properties in responses

## [5.0.3] - 2021-05-19
### Fixed
- Missing "meta" arguments in RoutingClient
Expand Down Expand Up @@ -200,6 +204,7 @@ the Document model.
### Added
- Client: fetch resources, collections, related resources and relationships

[5.0.4]: https://github.com/f3ath/json-api-dart/compare/5.0.3...5.0.4
[5.0.3]: https://github.com/f3ath/json-api-dart/compare/5.0.2...5.0.3
[5.0.2]: https://github.com/f3ath/json-api-dart/compare/5.0.1...5.0.2
[5.0.1]: https://github.com/f3ath/json-api-dart/compare/5.0.0...5.0.1
Expand Down
4 changes: 4 additions & 0 deletions lib/src/client/response/resource_created.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class ResourceCreated {

/// Created resource.
final Resource resource;

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

/// Top-level links
final links = <String, Link>{};

/// Included resources
Expand Down
6 changes: 4 additions & 2 deletions lib/src/client/response/resource_fetched.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class ResourceFetched {

final HttpResponse http;
final Resource resource;
final included = ResourceCollection();

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

/// Top-level links object
/// Top-level links
final links = <String, Link>{};

/// Included resources
final included = ResourceCollection();
}
17 changes: 16 additions & 1 deletion lib/src/client/response/resource_updated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import 'package:json_api/document.dart';
import 'package:json_api/http.dart';

class ResourceUpdated {
ResourceUpdated(this.http, Map? json) : resource = _resource(json);
ResourceUpdated(this.http, Map? json) : resource = _resource(json) {
if (json != null) {
included.addAll(InboundDocument(json).included());
meta.addAll(InboundDocument(json).meta());
links.addAll(InboundDocument(json).links());
}
}

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

/// The created resource. Null for "204 No Content" responses.
late final Resource? resource;

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

/// Top-level links
final links = <String, Link>{};

/// Included resources
final included = ResourceCollection();
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_api
version: 5.0.3
version: 5.0.4
homepage: https://github.com/f3ath/json-api-dart
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
environment:
Expand Down
14 changes: 14 additions & 0 deletions test/unit/client/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ void main() {
});
expect(http.request.headers,
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});

expect(response.meta, {'hello': 'world'});
});

group('Fetch Related Collection', () {
Expand Down Expand Up @@ -123,6 +125,8 @@ void main() {
});
expect(http.request.headers,
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});

expect(response.meta, {'hello': 'world'});
});
});

Expand Down Expand Up @@ -155,6 +159,8 @@ void main() {
{'include': 'author', 'fields[author]': 'name', 'foo': 'bar'});
expect(http.request.headers,
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});

expect(response.meta, {'hello': 'world'});
});
});

Expand Down Expand Up @@ -190,6 +196,8 @@ void main() {
{'include': 'author', 'fields[author]': 'name', 'foo': 'bar'});
expect(http.request.headers,
{'Accept': 'application/vnd.api+json', 'foo': 'bar'});

expect(response.meta, {'hello': 'world'});
});

test('Missing resource', () async {
Expand Down Expand Up @@ -295,6 +303,8 @@ void main() {
},
'meta': {'hello': 'world'}
});

expect(response.meta, {'hello': 'world'});
});
});

Expand Down Expand Up @@ -376,6 +386,8 @@ void main() {
},
'meta': {'hello': 'world'}
});

expect(response.meta, {'hello': 'world'});
});
});

Expand Down Expand Up @@ -458,6 +470,8 @@ void main() {
},
'meta': {'hello': 'world'}
});

expect(response.meta, {'hello': 'world'});
});
});

Expand Down
7 changes: 7 additions & 0 deletions test/unit/client/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final collectionFull = HttpResponse(200,
'next': 'http://example.com/articles?page[offset]=2',
'last': 'http://example.com/articles?page[offset]=10'
},
'meta': {'hello': 'world'},
'data': [
{
'type': 'articles',
Expand Down Expand Up @@ -85,6 +86,7 @@ final collectionFull = HttpResponse(200,
final primaryResource = HttpResponse(200,
body: jsonEncode({
'links': {'self': 'http://example.com/articles/1'},
'meta': {'hello': 'world'},
'data': {
'type': 'articles',
'id': '1',
Expand Down Expand Up @@ -134,6 +136,7 @@ final primaryResource = HttpResponse(200,
final relatedResourceNull = HttpResponse(200,
body: jsonEncode({
'links': {'self': 'http://example.com/articles/1/author'},
'meta': {'hello': 'world'},
'data': null
}))
..headers.addAll({'Content-Type': mediaType});
Expand All @@ -143,6 +146,7 @@ final one = HttpResponse(200,
'self': '/articles/1/relationships/author',
'related': '/articles/1/author'
},
'meta': {'hello': 'world'},
'data': {'type': 'people', 'id': '12'},
'included': [
{
Expand Down Expand Up @@ -187,6 +191,7 @@ final oneEmpty = HttpResponse(200,
'self': '/articles/1/relationships/author',
'related': '/articles/1/author'
},
'meta': {'hello': 'world'},
'data': null,
'included': [
{
Expand Down Expand Up @@ -231,6 +236,7 @@ final many = HttpResponse(200,
'self': '/articles/1/relationships/tags',
'related': '/articles/1/tags'
},
'meta': {'hello': 'world'},
'data': [
{'type': 'tags', 'id': '12'}
]
Expand All @@ -241,6 +247,7 @@ final noContent = HttpResponse(204);

final error422 = HttpResponse(422,
body: jsonEncode({
'meta': {'hello': 'world'},
'errors': [
{
'status': '422',
Expand Down