You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+3
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,10 @@
1
1
# Changelog
2
2
## [7.0.0] - 2023-08-14
3
3
-*BREAKING CHANGE*: Every type is now defined inline, this means that 'required' is no longer supported, if a field isn't nullable it is automatically required. This also means that the 'array' type is no longer supported and is instead just defined like 'List<T>'.
4
+
-*BREAKING CHANGE*: The way enums are defined has changed, see readme for more information. You can now add properties to enums, optional and default values are supported.
5
+
-*BREAKING CHANGE*: Enums are now by default not uppercase anymore, you can still enable this my adding 'uppercase_enums: true' to your pubspec or enum configuration
4
6
- Logs of build runner now get shown in real time.
7
+
- You are now allowed to have no properties configured for a class.
Copy file name to clipboardExpand all lines: README.md
+141-27
Original file line number
Diff line number
Diff line change
@@ -333,7 +333,7 @@ DateTimeConverter:
333
333
334
334
## Inline types (since 6.0.0)
335
335
336
-
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:
336
+
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:
since 7.0.0 inline types are supported now even when adding extra configuration:
350
351
@@ -373,67 +374,161 @@ BookCase:
373
374
include_if_null: false
374
375
```
375
376
376
-
Currently all basic types are supported, simple Lists and Maps (no nested types, no nullable generic parameters) as well as references to other objects.
377
+
Currently all basic types are supported, simple Lists and Maps (no nullable generic parameters) as well as references to other objects.
377
378
Items post-fixed with `?` will be marked optional.
378
379
379
-
## Enum support
380
+
## Enum support (as of v7.0.0 enums now support properties)
380
381
381
-
Add enums with custom values (can be mapped to String,double,int)
382
+
Add simple enums, the name of the enum value (MALE, FEMALE, X, Y) will be used when parsing from json
382
383
383
384
```yaml
384
385
Gender:
385
386
path: webservice/user
386
387
type: enum
387
-
properties:
388
+
values:
388
389
MALE:
389
-
value: _mAl3
390
390
FEMALE:
391
-
value: femAle
392
391
X:
393
-
value: X
394
392
Y:
395
393
```
396
394
397
-
### Generate mapping
395
+
By default enums will be generated with a property called jsonValue. this is the value of the enum used when parsing from json. This will only be used when there isn't already a custom jsonValue defined using 'is_json_value: true' in the properties of the enum. To turn this behavior of you can use 'use_default_json_value: false'.
396
+
397
+
```yaml
398
+
Gender:
399
+
path: webservice/user
400
+
use_default_json_value: false
401
+
type: enum
402
+
values:
403
+
MALE:
404
+
FEMALE:
405
+
X:
406
+
Y:
407
+
```
398
408
399
-
For enums, it is also possible to have a map generated that maps from the enum value to its string representation and reverse. To enable this, use `generate_map: true`
409
+
Add enums with custom properties (currently supported types are int, double, bool and String)
400
410
401
411
```yaml
402
412
Gender:
403
413
path: webservice/user
404
414
type: enum
405
-
generate_map: true
406
415
properties:
416
+
abbreviation: String
417
+
values:
407
418
MALE:
408
-
value: _mAl3
419
+
properties:
420
+
abbreviation: m
409
421
FEMALE:
410
-
value: femAle
422
+
properties:
423
+
abbreviation: f
411
424
X:
412
-
value: X
425
+
properties:
426
+
abbreviation: x
413
427
Y:
428
+
properties:
429
+
abbreviation: y
414
430
```
415
431
416
-
### Generate mapping extensions
432
+
Define custom json key using is_json_value, the value of this property will then be used to parse from json
433
+
434
+
```yaml
435
+
Gender:
436
+
path: webservice/user
437
+
type: enum
438
+
properties:
439
+
key:
440
+
type: String
441
+
is_json_value: true
442
+
abbreviation: String
443
+
values:
444
+
MALE:
445
+
properties:
446
+
key: male
447
+
abbreviation: m
448
+
FEMALE:
449
+
properties:
450
+
key: female
451
+
abbreviation: f
452
+
X:
453
+
properties:
454
+
key: x
455
+
abbreviation: x
456
+
Y:
457
+
properties:
458
+
key: y
459
+
abbreviation: y
460
+
```
417
461
418
-
When generating maps, it is also possible to specify that special extension functions should be added that return either the string value or that takes a string value and tries to
419
-
convert it to the enum value. To enable this, use `generate_map: true` **AND** `generate_extensions: true`
462
+
Optional and default values are supported. If value isn't defined for a property then it will use the defaultValue. If a property is optional and no value is given it is null.
420
463
421
464
```yaml
422
465
Gender:
423
466
path: webservice/user
424
467
type: enum
425
-
generate_map: true
426
-
generate_extensions: true
427
468
properties:
469
+
key:
470
+
type: String
471
+
is_json_value: true
472
+
abbreviation:
473
+
type: String
474
+
default_value: m
475
+
lastName: String?
476
+
values:
428
477
MALE:
429
-
value: _mAl3
478
+
properties:
479
+
key: male
430
480
FEMALE:
431
-
value: femAle
481
+
properties:
482
+
key: female
483
+
abbreviation: f
432
484
X:
433
-
value: X
485
+
properties:
486
+
key: x
434
487
Y:
488
+
properties:
489
+
key: y
490
+
lastName: lastName
435
491
```
436
492
493
+
### Generate mapping extensions
494
+
495
+
It is possible to generate an extension for the enum that can turn the enum into it's corresponding jsonValue and the reverse.
496
+
497
+
```yaml
498
+
Person:
499
+
path: test/enum/
500
+
type: enum
501
+
generate_extension: true
502
+
properties:
503
+
jsonValue:
504
+
is_json_value: true
505
+
type: int
506
+
firstName: String
507
+
lastName: String
508
+
values:
509
+
MAN:
510
+
properties:
511
+
jsonKey: 1
512
+
firstName: firstName1
513
+
lastName: lastName1
514
+
WOMAN:
515
+
properties:
516
+
jsonKey: 2
517
+
firstName: firstName2
518
+
lastName: lastName2
519
+
520
+
```
521
+
The above configuration will generate an enum with this extension.
### Generate mapping is no longer supported as of V7.0.0, use properties instead
437
532
### Use unknownEnumValue
438
533
439
534
```yaml
@@ -445,22 +540,22 @@ UnknownEnumTestObject:
445
540
type: Gender
446
541
```
447
542
448
-
### Automatic case conversion
543
+
### Automatic case conversion(v7.0.0)
449
544
450
-
By default all fields will be converted into uppercase. You can control this behavior globally for all enums or per-enum by setting the `uppercase_enums` property to `true` (
451
-
default) or `false`
545
+
As of v7.0.0 by default all fields will be converted into lowercase camelcase instead of uppercase like before. You can control this behavior globally for all enums or per-enum by setting the `uppercase_enums` property to `false` (
546
+
default) or `true`. This only affects the name of the enum when using it in dart code. the jsonValue will still be the name you type in the config.
452
547
453
548
```yaml
454
549
model_generator:
455
-
uppercase_enums: false
550
+
uppercase_enums: true
456
551
```
457
552
458
553
or
459
554
460
555
```yaml
461
556
UnknownEnumTestObject:
462
557
path: webservice
463
-
uppercase_enums: false
558
+
uppercase_enums: true
464
559
properties:
465
560
path:
466
561
```
@@ -546,6 +641,8 @@ DateTimeConverter:
546
641
547
642
You can specify `description` on models, enum, fields and on enum entries. This description will be used verbatim to generate a code comment for that class/enum/field
548
643
644
+
Example for a class:
645
+
549
646
```yaml
550
647
UserModel:
551
648
path: webservice/user
@@ -557,6 +654,23 @@ UserModel:
557
654
changedAt: DateTime
558
655
```
559
656
657
+
Example for a enum:
658
+
659
+
```yaml
660
+
Person:
661
+
path: test/enum/
662
+
type: enum
663
+
description: This is a enum of a person
664
+
values:
665
+
MAN:
666
+
description: enum of a man
667
+
WOMAN:
668
+
description: enum of a woman
669
+
OTHER:
670
+
description: enum of a other
671
+
```
672
+
673
+
560
674
## Static creator support
561
675
562
676
You can specify `static_create` on objects or globally in the `pubspec.yaml` file. If this is specified, a static creator method called `create` will be generated referencing the
0 commit comments