Skip to content

Commit

Permalink
Fix: model json serializable generation (#1055)
Browse files Browse the repository at this point in the history
<!--
  Thanks for contributing!

Provide a description of your changes below and a general summary in the
title

Please look at the following checklist to ensure that your PR can be
accepted quickly:
-->

## Description
This is related to the following issue reported on the Flutter
repository flutter/flutter#122899

When running `build_runner` to generate the generated code of the models
from the api, it was causing issues with some of the api tests.

- Changed return type of `NewsBlockConverter()` from List<Map<String,
dynamic>> `List<dynamic>`. This was causing tests to fail.
- Added `explicitToJson` statements to some models that had complex
attributes inside, like another model. This was also causing tests to
fail.
- Since generated files are pushed to the repo, updated the .g files
with the new generated ones.


<!--- Describe your changes in detail -->



## Type of Change

<!--- Put an `x` in all the boxes that apply: -->

- [ ] ✨ New feature (non-breaking change which adds functionality)
- [x] 🛠️ Bug fix (non-breaking change which fixes an issue)
- [ ] ❌ Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] 🧹 Code refactor
- [ ] ✅ Build configuration change
- [ ] 📝 Documentation
- [ ] 🗑️ Chore
  • Loading branch information
valentinallavayol committed Nov 16, 2023
1 parent 15b1503 commit 553992b
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 335 deletions.
43 changes: 11 additions & 32 deletions flutter_news_example/api/lib/src/data/models/article.g.dart

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

34 changes: 7 additions & 27 deletions flutter_news_example/api/lib/src/data/models/feed.g.dart

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.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ part 'subscription.g.dart';
/// A news subscription object which contains
/// metadata about a subscription tier.
/// {@endtemplate}
@JsonSerializable()
@JsonSerializable(explicitToJson: true)
class Subscription extends Equatable {
/// {@macro subscription}
const Subscription({
Expand Down
39 changes: 10 additions & 29 deletions flutter_news_example/api/lib/src/data/models/subscription.g.dart

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

2 changes: 1 addition & 1 deletion flutter_news_example/api/lib/src/data/models/user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ part 'user.g.dart';
/// {@template user}
/// A user object which contains user metadata.
/// {@endtemplate}
@JsonSerializable()
@JsonSerializable(explicitToJson: true)
class User extends Equatable {
/// {@macro user}
const User({required this.id, required this.subscription});
Expand Down
19 changes: 5 additions & 14 deletions flutter_news_example/api/lib/src/data/models/user.g.dart

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.

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

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ part 'current_user_response.g.dart';
/// {@template current_user_response}
/// A response object which contains the current user.
/// {@endtemplate}
@JsonSerializable()
@JsonSerializable(explicitToJson: true)
class CurrentUserResponse extends Equatable {
/// {@macro current_user_response}
const CurrentUserResponse({required this.user});
Expand Down
Loading

0 comments on commit 553992b

Please sign in to comment.