Skip to content

Commit

Permalink
support multi parameter types for headers (#546)
Browse files Browse the repository at this point in the history
* support multi parameter types for headers

when use headers annotation, generator code cann't transform double、int、bool type to genetated code. So fix like this

* fix: fix issue

---------

Co-authored-by: Trevor Wang <trevor.wang@qq.com>
  • Loading branch information
tanghuai and trevorwang authored Mar 8, 2023
1 parent 32b728a commit 3a806c3
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1871,10 +1871,26 @@ ${bodyName.displayName} == null
.map((e) => e.peek(_valueVar))
.map(
(value) => value?.mapValue.map(
(k, v) => MapEntry(
k?.toStringValue() ?? 'null',
literal(v?.toStringValue()),
),
(k, v) {
dynamic val;
if (v == null) {
val = null;
} else if (v.type?.isDartCoreBool == true) {
val = v.toBoolValue();
} else if (v.type?.isDartCoreString == true) {
val = v.toStringValue();
} else if (v.type?.isDartCoreDouble == true) {
val = v.toDoubleValue();
} else if (v.type?.isDartCoreInt == true) {
val = v.toIntValue();
} else {
val = v.toStringValue();
}
return MapEntry(
k?.toStringValue() ?? 'null',
literal(val),
);
},
),
)
.fold<Map<String, Expression>>({}, (p, e) => p..addAll(e ?? {}));
Expand Down

0 comments on commit 3a806c3

Please sign in to comment.