Skip to content

Commit

Permalink
#130: use jsonValue as default
Browse files Browse the repository at this point in the history
  • Loading branch information
jorre127 committed Sep 7, 2023
1 parent 5210216 commit 4790a0d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/writer/enum_model_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class EnumModelWriter {
var value = enumValue?.value ?? property.defaultValue;

sb.write(' ${property.name}: ');
if (property.type is StringType && value != null) {
if (property.type is StringType && (value != null || property.isJsonvalue)) {
if (value == null && property.isJsonvalue) value = jsonValue;
sb.writeln('\'$value\',');
} else {
sb.writeln('$value,');
Expand Down
14 changes: 14 additions & 0 deletions test/writer/enum_model_writer/use_default_json_value/config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DoubleStatus:
path: status
type: enum
properties:
value:
type: String
is_json_value: true
values:
status_0:
properties:
value: customValue
status_1:
status_2:
status_3:
28 changes: 28 additions & 0 deletions test/writer/enum_model_writer/use_default_json_value/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// GENERATED CODE - DO NOT MODIFY BY HAND

import 'package:json_annotation/json_annotation.dart';

enum DoubleStatus {
@JsonValue('customValue')
STATUS_0(
value: 'customValue',
),
@JsonValue('status_1')
STATUS_1(
value: 'status_1',
),
@JsonValue('status_2')
STATUS_2(
value: 'status_2',
),
@JsonValue('status_3')
STATUS_3(
value: 'status_3',
);

final String value;

const DoubleStatus({
required this.value,
});
}

0 comments on commit 4790a0d

Please sign in to comment.