Skip to content

Commit 461bac9

Browse files
Merge pull request #137 from icapps/refactor/#134-remove-ignore
#134 Removed the ignore
2 parents 95c36ad + 79ba959 commit 461bac9

File tree

20 files changed

+314
-20
lines changed

20 files changed

+314
-20
lines changed

Diff for: CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
2+
## [6.3.0] - 2023-06-05
3+
- Fixed the deprecated `ignore` field. Added
4+
```
5+
includeFromJson: false
6+
includeToJson: false
7+
```
8+
29
## [6.2.1] - 2023-03-07
3-
- Updated the enum model generator to correctly generate the (reverse)Mapping based on the item_type
10+
- Updated the enum model generator to correctly generate the (reverse)Mapping based on the item_type
411

512
## [6.2.0] - 2023-02-23
613
- Better enum support. Right now, String, int, double can be used to map a value to an enum.

Diff for: README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,13 @@ UserModel:
323323
include_if_null: false #If this field is null, this field will not be added to your json object (used for PATCH models)
324324
type: String
325325
ignoreField:
326-
ignore: false #this field will not be final, and not be used in the json parsing
326+
ignore: false #This field is ignored in the to & from json methods
327+
type: String
328+
ignoreFieldOnlyInFrom:
329+
includeFromJson: false #This field is ignored in the from json method
330+
type: String
331+
ignoreFieldOnlyInTo:
332+
includeToJson: false #This field is ignored in the to json method
327333
type: String
328334
mutableField:
329335
non_final: true #Field will not be marked final

Diff for: example/lib/model/user/testing.dart

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: example/pubspec.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ environment:
88
dependencies:
99
flutter:
1010
sdk: flutter
11-
json_serializable: ^6.6.1
11+
json_annotation: ^4.8.1
1212
provider: ^6.0.5
1313

1414
dev_dependencies:
15-
build_runner: ^2.3.3
15+
build_runner: ^2.4.4
1616
flutter_test:
1717
sdk: flutter
18+
json_serializable: ^6.7.0
1819
model_generator:
1920
path: ../
2021

Diff for: lib/config/yml_generator_config.dart

+8
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ class YmlGeneratorConfig {
184184
property.containsKey('required') && property['required'] == true;
185185
final ignored =
186186
property.containsKey('ignore') && property['ignore'] == true;
187+
final includeFromJson = !property.containsKey('includeFromJson') ||
188+
property['includeFromJson'] == true;
189+
final includeToJson = !property.containsKey('includeToJson') ||
190+
property['includeToJson'] == true;
187191
final nonFinal = ignored ||
188192
property.containsKey('non_final') && property['non_final'] == true;
189193
final includeIfNull = property.containsKey('include_if_null') &&
@@ -241,6 +245,8 @@ class YmlGeneratorConfig {
241245
type: itemType,
242246
isRequired: required,
243247
ignore: ignored,
248+
includeFromJson: includeFromJson,
249+
includeToJson: includeToJson,
244250
jsonKey: jsonKey,
245251
nonFinal: nonFinal,
246252
description: description,
@@ -269,6 +275,8 @@ class YmlGeneratorConfig {
269275
type: type,
270276
isRequired: !optional,
271277
ignore: false,
278+
includeToJson: true,
279+
includeFromJson: true,
272280
includeIfNull: true,
273281
nonFinal: false,
274282
ignoreEquality: false,

Diff for: lib/model/field.dart

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Field {
88
final ItemType type;
99
final bool isRequired;
1010
final bool ignore;
11+
final bool includeFromJson;
12+
final bool includeToJson;
1113
final bool includeIfNull;
1214
final bool nonFinal;
1315
final String? unknownEnumValue;
@@ -25,6 +27,8 @@ class Field {
2527
required this.type,
2628
required this.isRequired,
2729
required this.ignore,
30+
required this.includeFromJson,
31+
required this.includeToJson,
2832
required this.includeIfNull,
2933
required this.nonFinal,
3034
required this.ignoreEquality,

Diff for: lib/writer/object_model_writer.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ class ObjectModelWriter {
115115
}
116116

117117
if (key.ignore) {
118-
sb.write(', ignore: true');
118+
sb.write(', includeFromJson: false, includeToJson: false');
119+
} else {
120+
if (!key.includeFromJson) {
121+
sb.write(', includeFromJson: false');
122+
}
123+
if (!key.includeToJson) {
124+
sb.write(', includeToJson: false');
125+
}
119126
}
120127

121128
if (key.unknownEnumValue != null) {

Diff for: pubspec.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
name: model_generator
2-
description: Dart tool to automaticly generate models from a yml file to speed up your development flow.
3-
version: 6.2.1
2+
description: Dart tool to automatically generate models from a yml file to speed up your development flow.
3+
version: 6.3.0
44
homepage: https://github.com/icapps/flutter-model-generator
55

66
environment:
7-
sdk: ">=2.17.0 <3.0.0"
7+
sdk: ">=3.0.0 <4.0.0"
88

99
dependencies:
10-
args: ^2.3.0
11-
meta: ^1.3.0
12-
path: ^1.8.0
13-
pub_semver: ^2.1.0
14-
yaml: ^3.1.0
10+
args: ^2.4.1
11+
meta: ^1.9.1
12+
path: ^1.8.3
13+
pub_semver: ^2.1.4
14+
yaml: ^3.1.2
1515

1616
dev_dependencies:
17-
test: 1.21.6
18-
lints: ^2.0.0
17+
test: ^1.24.3
18+
lints: ^2.1.1

Diff for: test/model/field_test.dart

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ void main() {
1010
type: StringType(),
1111
isRequired: true,
1212
ignore: true,
13+
includeFromJson: true,
14+
includeToJson: true,
1315
includeIfNull: true,
1416
nonFinal: true,
1517
ignoreEquality: false,
@@ -32,6 +34,8 @@ void main() {
3234
type: StringType(),
3335
isRequired: true,
3436
ignore: true,
37+
includeFromJson: true,
38+
includeToJson: true,
3539
includeIfNull: true,
3640
ignoreEquality: true,
3741
nonFinal: true,
@@ -56,6 +60,8 @@ void main() {
5660
type: StringType(),
5761
isRequired: true,
5862
ignore: true,
63+
includeFromJson: true,
64+
includeToJson: true,
5965
includeIfNull: true,
6066
ignoreEquality: true,
6167
nonFinal: true,
@@ -78,6 +84,8 @@ void main() {
7884
type: StringType(),
7985
isRequired: true,
8086
ignore: true,
87+
includeFromJson: true,
88+
includeToJson: true,
8189
includeIfNull: true,
8290
ignoreEquality: true,
8391
nonFinal: true,

Diff for: test/writer/object_model_writer/ignore/output.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ part 'person.g.dart';
66

77
@JsonSerializable(explicitToJson: true)
88
class Person {
9-
@JsonKey(name: 'firstName', ignore: true)
9+
@JsonKey(name: 'firstName', includeFromJson: false, includeToJson: false)
1010
final String? firstName;
1111

1212
const Person({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Person:
2+
path: user/person/
3+
type: object
4+
properties:
5+
firstName:
6+
required: false
7+
includeFromJson: false
8+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// GENERATED CODE - DO NOT MODIFY BY HAND
2+
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'person.g.dart';
6+
7+
@JsonSerializable(explicitToJson: true)
8+
class Person {
9+
@JsonKey(name: 'firstName', includeFromJson: false)
10+
final String? firstName;
11+
12+
const Person({
13+
this.firstName,
14+
});
15+
16+
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
17+
18+
Map<String, dynamic> toJson() => _$PersonToJson(this);
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: model_generator_example
2+
3+
model_generator:
4+
config_path: model_generator/config.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Person:
2+
path: user/person/
3+
type: object
4+
properties:
5+
firstName:
6+
required: false
7+
includeFromJson: false
8+
includeToJson: false
9+
type: string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// GENERATED CODE - DO NOT MODIFY BY HAND
2+
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'person.g.dart';
6+
7+
@JsonSerializable(explicitToJson: true)
8+
class Person {
9+
@JsonKey(name: 'firstName', includeFromJson: false, includeToJson: false)
10+
final String? firstName;
11+
12+
const Person({
13+
this.firstName,
14+
});
15+
16+
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
17+
18+
Map<String, dynamic> toJson() => _$PersonToJson(this);
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: model_generator_example
2+
3+
model_generator:
4+
config_path: model_generator/config.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Person:
2+
path: user/person/
3+
type: object
4+
properties:
5+
firstName:
6+
required: false
7+
includeToJson: false
8+
type: string
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// GENERATED CODE - DO NOT MODIFY BY HAND
2+
3+
import 'package:json_annotation/json_annotation.dart';
4+
5+
part 'person.g.dart';
6+
7+
@JsonSerializable(explicitToJson: true)
8+
class Person {
9+
@JsonKey(name: 'firstName', includeToJson: false)
10+
final String? firstName;
11+
12+
const Person({
13+
this.firstName,
14+
});
15+
16+
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
17+
18+
Map<String, dynamic> toJson() => _$PersonToJson(this);
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: model_generator_example
2+
3+
model_generator:
4+
config_path: model_generator/config.yaml

0 commit comments

Comments
 (0)