Skip to content

Address #102 #103

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 3 commits into from
Jun 6, 2020
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
23 changes: 14 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.2.2] - 2020-06-05
### Fixed
- Client throws NoSuchMethodError on unexpected primary data ([issue](https://github.com/f3ath/json-api-dart/issues/102)).

## [4.2.1] - 2020-06-04
### Fixed
- The server library was not exporting `Controller`.
- `ResourceData.toJson()` was not calling the underlying `ResourceObject.toJson()`.

## [4.2.0] - 2020-06-03
### Added
- Filtering support for collections ([#97](https://github.com/f3ath/json-api-dart/pull/97))
- Filtering support for collections ([pr](https://github.com/f3ath/json-api-dart/pull/97))

### Changed
- The client will not attempt to decode the body of the HTTP response with error status if the correct Content-Type
is missing. Before in such cases a `FormatException` would be thrown ([#98](https://github.com/f3ath/json-api-dart/pull/98))
is missing. Before in such cases a `FormatException` would be thrown ([pr](https://github.com/f3ath/json-api-dart/pull/98))

## [4.1.0] - 2020-05-28
### Changed
Expand All @@ -29,11 +33,11 @@ is missing. Before in such cases a `FormatException` would be thrown ([#98](http

## [3.2.2] - 2020-01-07
### Fixed
- Can not decode related resource which is null ([#77](https://github.com/f3ath/json-api-dart/issues/77))
- Can not decode related resource which is null ([issue](https://github.com/f3ath/json-api-dart/issues/77))

## [3.2.1] - 2020-01-01
### Fixed
- Incorrect URL in the example in the Client documentation ([#74](https://github.com/f3ath/json-api-dart/issues/74))
- Incorrect URL in the example in the Client documentation ([issue](https://github.com/f3ath/json-api-dart/issues/74))

## [3.2.0] - 2019-12-30
### Added
Expand All @@ -59,7 +63,7 @@ is missing. Before in such cases a `FormatException` would be thrown ([#98](http

## [3.0.0] - 2019-12-17
### Added
- Support for custom non-standard links ([#61](https://github.com/f3ath/json-api-dart/issues/61))
- Support for custom non-standard links ([issue](https://github.com/f3ath/json-api-dart/issues/61))
- Client supports `jsonapi` key in outgoing requests.
- `Document.contentType` constant.
- `IdentifierObject.fromIdentifier` factory method
Expand All @@ -84,15 +88,15 @@ Most of the changes are **BC-BREAKING**.

## [2.1.0] - 2019-12-04
### Added
- `onHttpCall` hook to enable raw http request/response logging ([#60](https://github.com/f3ath/json-api-dart/issues/60)).
- `onHttpCall` hook to enable raw http request/response logging ([issue](https://github.com/f3ath/json-api-dart/issues/60)).

## [2.0.3] - 2019-09-29
### Fixed
- Documentation links got broken due to pub.dev update.

## [2.0.2] - 2019-08-01
### Fixed
- Meta members have incorrect type ([#54](https://github.com/f3ath/json-api-dart/issues/54)).
- Meta members have incorrect type ([issue](https://github.com/f3ath/json-api-dart/issues/54)).

## [2.0.1] - 2019-07-12
### Fixed
Expand Down Expand Up @@ -133,7 +137,7 @@ Most of the changes are **BC-BREAKING**.
- More BC-breaking changes in the Server

### Fixed
- Location headers were incorrectly generated by Server
- Location headers generated incorrectly

### Added
- Related collection pagination
Expand Down Expand Up @@ -169,7 +173,8 @@ Most of the changes are **BC-BREAKING**.
### Added
- Client: fetch resources, collections, related resources and relationships

[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.2.1...HEAD
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/4.2.2...HEAD
[4.2.2]: https://github.com/f3ath/json-api-dart/compare/4.2.1...4.2.2
[4.2.1]: https://github.com/f3ath/json-api-dart/compare/4.2.0...4.2.1
[4.2.0]: https://github.com/f3ath/json-api-dart/compare/4.1.0...4.2.0
[4.1.0]: https://github.com/f3ath/json-api-dart/compare/4.0.0...4.1.0
Expand Down
2 changes: 1 addition & 1 deletion lib/src/document/document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Document<Data extends PrimaryData> implements JsonEncodable {
return Document.error(errors.map(ErrorObject.fromJson),
meta: json['meta'], api: api);
}
} else if (json.containsKey('data')) {
} else if (primaryData != null) {
return Document(primaryData(json), meta: json['meta'], api: api);
} else if (json['meta'] != null) {
return Document.empty(json['meta'], api: api);
Expand Down
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: 4.2.1
version: 4.2.2
homepage: https://github.com/f3ath/json-api-dart
description: Framework-agnostic implementations of JSON:API Client (Flutter, Web and VM) and Server (VM). Supports JSON:API v1.0 (http://jsonapi.org)
environment:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:json_api/client.dart';
import 'package:json_api/http.dart';
import 'package:json_api/routing.dart';
Expand All @@ -8,7 +10,7 @@ import '../../helper/test_http_handler.dart';
void main() {
final handler = TestHttpHandler();
final client = RoutingClient(JsonApiClient(handler), StandardRouting());
test('Error status code with incorrect content-type is not decoded',
test('Error status code with incorrect content-type, body is not decoded',
() async {
handler.nextResponse = HttpResponse(500, body: 'Something went wrong');

Expand All @@ -20,4 +22,21 @@ void main() {
expect(r.asyncData, isNull);
expect(r.statusCode, 500);
});

test('Do not attempt to decode primary data if decoder is null', () async {
handler.nextResponse = HttpResponse(200,
body: jsonEncode({
'meta': {'foo': 'bar'},
'data': {'id': '123', 'type': 'books'}
}));

final r = await client.deleteResource('books', '123');
expect(r.isAsync, false);
expect(r.isSuccessful, true);
expect(r.isFailed, false);
expect(r.data, isNull);
expect(r.document.meta['foo'], 'bar');
expect(r.asyncData, isNull);
expect(r.statusCode, 200);
});
}
2 changes: 1 addition & 1 deletion test/unit/document/document_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:test/test.dart';

void main() {
test('Unrecognized structure', () {
expect(() => Document.fromJson({}, ResourceData.fromJson),
expect(() => Document.fromJson({}, ResourceCollectionData.fromJson),
throwsA(TypeMatcher<DocumentException>()));
});
}