Skip to content

Commit

Permalink
#130: implemented PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Sep 8, 2023
1 parent acbfe70 commit a78c87b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ DateTimeConverter:

## Inline types (since 6.0.0)

In some cases, writing the full specification for simple fields is very verbose. Since 6.0.0 it is possible to write simple fields inline, without nesting below the field name:
In some cases, writing the full specification for simple fields is very verbose. Since 6.0.0 it is possible to write simple fields inline, without nesting below the field name, since 7.0.0 nested lists and list in maps is also supported:

```yaml
UserModel:
Expand All @@ -345,6 +345,7 @@ UserModel:
created_at: DateTime
roles: List<string>
customProperties: Map<String, Property>?
customPropertiesList: Map<String, List<Property>>?
```
since 7.0.0 inline types are supported now even when adding extra configuration:

Expand Down Expand Up @@ -373,7 +374,7 @@ BookCase:
include_if_null: false
```

Currently all basic types are supported, simple Lists and Maps (no nested types, no nullable generic parameters) as well as references to other objects.
Currently all basic types are supported, simple Lists and Maps (no nullable generic parameters) as well as references to other objects.
Items post-fixed with `?` will be marked optional.

## Enum support (as of v7.0.0 enums now support properties)
Expand Down
32 changes: 32 additions & 0 deletions test/writer/object_model_writer/list_in_map/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ProjectWrapper:
path: user/person/
type: object
properties:
projectByInt: Map<int, List<Project>>
projectByString: Map<String, List<Project>>
projectByEnum: Map<ProjectEnum, List<Project>>
StringsByString: Map<String, List<String>>
intsByString: Map<String, List<int>>
intsByDateTime: Map<DateTime, List<int>>
intsBydynamic: Map<dynamic, List<int>>

Project:
path: user/project/
type: object
generate_for_generics: true
static_create: true
properties:
name:
type: String
default_value: "'test'"
cost:
type: double?
default_value: 0.2

ProjectEnum:
path: user/project
type: enum
values:
smallProject:
mediumProject:
bigProject:
40 changes: 40 additions & 0 deletions test/writer/object_model_writer/list_in_map/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

import 'package:json_annotation/json_annotation.dart';
import 'package:model_generator_example/model/user/project/project.dart';
import 'package:model_generator_example/model/user/project/project_enum.dart';

part 'project_wrapper.g.dart';

@JsonSerializable(explicitToJson: true)
class ProjectWrapper {
@JsonKey(name: 'projectByInt', required: true, includeIfNull: false)
final Map<int, List<Project>> projectByInt;
@JsonKey(name: 'projectByString', required: true, includeIfNull: false)
final Map<String, List<Project>> projectByString;
@JsonKey(name: 'projectByEnum', required: true, includeIfNull: false)
final Map<ProjectEnum, List<Project>> projectByEnum;
@JsonKey(name: 'StringsByString', required: true, includeIfNull: false)
final Map<String, List<String>> stringsByString;
@JsonKey(name: 'intsByString', required: true, includeIfNull: false)
final Map<String, List<int>> intsByString;
@JsonKey(name: 'intsByDateTime', required: true, includeIfNull: false)
final Map<DateTime, List<int>> intsByDateTime;
@JsonKey(name: 'intsBydynamic', required: true, includeIfNull: false)
final Map<dynamic, List<int>> intsBydynamic;

const ProjectWrapper({
required this.projectByInt,
required this.projectByString,
required this.projectByEnum,
required this.stringsByString,
required this.intsByString,
required this.intsByDateTime,
required this.intsBydynamic,
});

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

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

}
4 changes: 4 additions & 0 deletions test/writer/object_model_writer/list_in_map/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

0 comments on commit a78c87b

Please sign in to comment.