Skip to content
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

#134 Removed the ignore #137

Merged
merged 3 commits into from
Jun 5, 2023
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
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
## [6.3.0] - 2023-06-05
- Fixed the deprecated `ignore` field. Added
```
includeFromJson: false
includeToJson: false
```

## [6.2.1] - 2023-03-07
- Updated the enum model generator to correctly generate the (reverse)Mapping based on the item_type
- Updated the enum model generator to correctly generate the (reverse)Mapping based on the item_type

## [6.2.0] - 2023-02-23
- Better enum support. Right now, String, int, double can be used to map a value to an enum.
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,13 @@ UserModel:
include_if_null: false #If this field is null, this field will not be added to your json object (used for PATCH models)
type: String
ignoreField:
ignore: false #this field will not be final, and not be used in the json parsing
ignore: false #This field is ignored in the to & from json methods
type: String
ignoreFieldOnlyInFrom:
includeFromJson: false #This field is ignored in the from json method
type: String
ignoreFieldOnlyInTo:
includeToJson: false #This field is ignored in the to json method
type: String
mutableField:
non_final: true #Field will not be marked final
Expand Down
6 changes: 5 additions & 1 deletion example/lib/model/user/testing.dart

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

5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ environment:
dependencies:
flutter:
sdk: flutter
json_serializable: ^6.6.1
json_annotation: ^4.8.1
provider: ^6.0.5

dev_dependencies:
build_runner: ^2.3.3
build_runner: ^2.4.4
flutter_test:
sdk: flutter
json_serializable: ^6.7.0
model_generator:
path: ../

Expand Down
8 changes: 8 additions & 0 deletions lib/config/yml_generator_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ class YmlGeneratorConfig {
property.containsKey('required') && property['required'] == true;
final ignored =
property.containsKey('ignore') && property['ignore'] == true;
final includeFromJson = !property.containsKey('includeFromJson') ||
property['includeFromJson'] == true;
final includeToJson = !property.containsKey('includeToJson') ||
property['includeToJson'] == true;
final nonFinal = ignored ||
property.containsKey('non_final') && property['non_final'] == true;
final includeIfNull = property.containsKey('include_if_null') &&
Expand Down Expand Up @@ -241,6 +245,8 @@ class YmlGeneratorConfig {
type: itemType,
isRequired: required,
ignore: ignored,
includeFromJson: includeFromJson,
includeToJson: includeToJson,
jsonKey: jsonKey,
nonFinal: nonFinal,
description: description,
Expand Down Expand Up @@ -269,6 +275,8 @@ class YmlGeneratorConfig {
type: type,
isRequired: !optional,
ignore: false,
includeToJson: true,
includeFromJson: true,
includeIfNull: true,
nonFinal: false,
ignoreEquality: false,
Expand Down
4 changes: 4 additions & 0 deletions lib/model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Field {
final ItemType type;
final bool isRequired;
final bool ignore;
final bool includeFromJson;
final bool includeToJson;
final bool includeIfNull;
final bool nonFinal;
final String? unknownEnumValue;
Expand All @@ -25,6 +27,8 @@ class Field {
required this.type,
required this.isRequired,
required this.ignore,
required this.includeFromJson,
required this.includeToJson,
required this.includeIfNull,
required this.nonFinal,
required this.ignoreEquality,
Expand Down
9 changes: 8 additions & 1 deletion lib/writer/object_model_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ class ObjectModelWriter {
}

if (key.ignore) {
sb.write(', ignore: true');
sb.write(', includeFromJson: false, includeToJson: false');
} else {
if (!key.includeFromJson) {
sb.write(', includeFromJson: false');
}
if (!key.includeToJson) {
sb.write(', includeToJson: false');
}
}

if (key.unknownEnumValue != null) {
Expand Down
20 changes: 10 additions & 10 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: model_generator
description: Dart tool to automaticly generate models from a yml file to speed up your development flow.
version: 6.2.1
description: Dart tool to automatically generate models from a yml file to speed up your development flow.
version: 6.3.0
homepage: https://github.com/icapps/flutter-model-generator

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
args: ^2.3.0
meta: ^1.3.0
path: ^1.8.0
pub_semver: ^2.1.0
yaml: ^3.1.0
args: ^2.4.1
meta: ^1.9.1
path: ^1.8.3
pub_semver: ^2.1.4
yaml: ^3.1.2

dev_dependencies:
test: 1.21.6
lints: ^2.0.0
test: ^1.24.3
lints: ^2.1.1
8 changes: 8 additions & 0 deletions test/model/field_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void main() {
type: StringType(),
isRequired: true,
ignore: true,
includeFromJson: true,
includeToJson: true,
includeIfNull: true,
nonFinal: true,
ignoreEquality: false,
Expand All @@ -32,6 +34,8 @@ void main() {
type: StringType(),
isRequired: true,
ignore: true,
includeFromJson: true,
includeToJson: true,
includeIfNull: true,
ignoreEquality: true,
nonFinal: true,
Expand All @@ -56,6 +60,8 @@ void main() {
type: StringType(),
isRequired: true,
ignore: true,
includeFromJson: true,
includeToJson: true,
includeIfNull: true,
ignoreEquality: true,
nonFinal: true,
Expand All @@ -78,6 +84,8 @@ void main() {
type: StringType(),
isRequired: true,
ignore: true,
includeFromJson: true,
includeToJson: true,
includeIfNull: true,
ignoreEquality: true,
nonFinal: true,
Expand Down
2 changes: 1 addition & 1 deletion test/writer/object_model_writer/ignore/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ part 'person.g.dart';

@JsonSerializable(explicitToJson: true)
class Person {
@JsonKey(name: 'firstName', ignore: true)
@JsonKey(name: 'firstName', includeFromJson: false, includeToJson: false)
final String? firstName;

const Person({
Expand Down
8 changes: 8 additions & 0 deletions test/writer/object_model_writer/includeFromJson/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Person:
path: user/person/
type: object
properties:
firstName:
required: false
includeFromJson: false
type: string
20 changes: 20 additions & 0 deletions test/writer/object_model_writer/includeFromJson/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

import 'package:json_annotation/json_annotation.dart';

part 'person.g.dart';

@JsonSerializable(explicitToJson: true)
class Person {
@JsonKey(name: 'firstName', includeFromJson: false)
final String? firstName;

const Person({
this.firstName,
});

factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

Map<String, dynamic> toJson() => _$PersonToJson(this);

}
4 changes: 4 additions & 0 deletions test/writer/object_model_writer/includeFromJson/pubspec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: model_generator_example

model_generator:
config_path: model_generator/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Person:
path: user/person/
type: object
properties:
firstName:
required: false
includeFromJson: false
includeToJson: false
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

import 'package:json_annotation/json_annotation.dart';

part 'person.g.dart';

@JsonSerializable(explicitToJson: true)
class Person {
@JsonKey(name: 'firstName', includeFromJson: false, includeToJson: false)
final String? firstName;

const Person({
this.firstName,
});

factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

Map<String, dynamic> toJson() => _$PersonToJson(this);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: model_generator_example

model_generator:
config_path: model_generator/config.yaml
8 changes: 8 additions & 0 deletions test/writer/object_model_writer/includeToJson/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Person:
path: user/person/
type: object
properties:
firstName:
required: false
includeToJson: false
type: string
20 changes: 20 additions & 0 deletions test/writer/object_model_writer/includeToJson/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

import 'package:json_annotation/json_annotation.dart';

part 'person.g.dart';

@JsonSerializable(explicitToJson: true)
class Person {
@JsonKey(name: 'firstName', includeToJson: false)
final String? firstName;

const Person({
this.firstName,
});

factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

Map<String, dynamic> toJson() => _$PersonToJson(this);

}
4 changes: 4 additions & 0 deletions test/writer/object_model_writer/includeToJson/pubspec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: model_generator_example

model_generator:
config_path: model_generator/config.yaml
Loading