diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index a2743b75..ed26cdce 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -600,7 +600,11 @@ class OpenAPIBuilder implements Builder { if (nullable) { code.write('if (${_toDartName(parameter.name)} != null) {'); } - final value = result.encode(result.serialize(_toDartName(parameter.name))); + final isPlainList = result is TypeResultList && !result.fromJsonString; + final value = result.encode( + result.serialize(_toDartName(parameter.name)), + onlyChildren: isPlainList && parameter.in_ == 'query', + ); switch (parameter.in_) { case 'path': code.write( @@ -609,7 +613,7 @@ class OpenAPIBuilder implements Builder { break; case 'query': code.write( - "queryParameters['${parameter.name}${result is TypeResultList ? '[]' : ''}'] = $value;", + "queryParameters['${parameter.name}${isPlainList ? '[]' : ''}'] = $value;", ); break; case 'header': @@ -1417,6 +1421,7 @@ TypeResult resolveType( result = TypeResultList( 'List<${subResult.name}>', subResult, + fromJsonString: fromJsonString, ); } else { result = TypeResultList( diff --git a/packages/dynamite/lib/src/type_result/base.dart b/packages/dynamite/lib/src/type_result/base.dart index 101f5630..a6616043 100644 --- a/packages/dynamite/lib/src/type_result/base.dart +++ b/packages/dynamite/lib/src/type_result/base.dart @@ -7,7 +7,7 @@ class TypeResultBase extends TypeResult { String serialize(final String object) => object; @override - String encode(final String object) => '$object.toString()'; + String encode(final String object, {final bool onlyChildren = false}) => '$object.toString()'; @override String deserialize(final String object) => '($object as $name)'; diff --git a/packages/dynamite/lib/src/type_result/enum.dart b/packages/dynamite/lib/src/type_result/enum.dart index af9a9b94..b5b85880 100644 --- a/packages/dynamite/lib/src/type_result/enum.dart +++ b/packages/dynamite/lib/src/type_result/enum.dart @@ -12,7 +12,7 @@ class TypeResultEnum extends TypeResult { String serialize(final String object) => '$object.value'; @override - String encode(final String object) => subType.encode(object); + String encode(final String object, {final bool onlyChildren = false}) => subType.encode(object); @override String deserialize(final String object) => '$name.fromValue($object as ${subType.name})'; diff --git a/packages/dynamite/lib/src/type_result/list.dart b/packages/dynamite/lib/src/type_result/list.dart index a48efb1f..d59b4155 100644 --- a/packages/dynamite/lib/src/type_result/list.dart +++ b/packages/dynamite/lib/src/type_result/list.dart @@ -3,16 +3,23 @@ part of '../../dynamite.dart'; class TypeResultList extends TypeResult { TypeResultList( super.name, - this.subType, - ); + this.subType, { + this.fromJsonString = false, + }); final TypeResult subType; + final bool fromJsonString; @override String serialize(final String object) => '$object.map((final e) => ${subType.serialize('e')}).toList()'; @override - String encode(final String object) => 'json.encode($object)'; + String encode(final String object, {final bool onlyChildren = false}) { + if (onlyChildren) { + return '$object.map((final e) => ${subType.encode('e')}).toList()'; + } + return 'json.encode($object)'; + } @override String deserialize(final String object) => '($object as List).map((final e) => ${subType.deserialize('e')}).toList()'; diff --git a/packages/dynamite/lib/src/type_result/map.dart b/packages/dynamite/lib/src/type_result/map.dart index 884e8d27..b0f24027 100644 --- a/packages/dynamite/lib/src/type_result/map.dart +++ b/packages/dynamite/lib/src/type_result/map.dart @@ -12,7 +12,7 @@ class TypeResultMap extends TypeResult { String serialize(final String object) => object; @override - String encode(final String object) => 'json.encode($object)'; + String encode(final String object, {final bool onlyChildren = false}) => 'json.encode($object)'; @override String deserialize(final String object) => '($object as Map)'; diff --git a/packages/dynamite/lib/src/type_result/object.dart b/packages/dynamite/lib/src/type_result/object.dart index 7509849d..0b556af3 100644 --- a/packages/dynamite/lib/src/type_result/object.dart +++ b/packages/dynamite/lib/src/type_result/object.dart @@ -17,7 +17,7 @@ class TypeResultObject extends TypeResult { } @override - String encode(final String object) => 'json.encode($object)'; + String encode(final String object, {final bool onlyChildren = false}) => 'json.encode($object)'; @override String deserialize(final String object) { diff --git a/packages/dynamite/lib/src/type_result/type_result.dart b/packages/dynamite/lib/src/type_result/type_result.dart index 25c79bed..1ceb5992 100644 --- a/packages/dynamite/lib/src/type_result/type_result.dart +++ b/packages/dynamite/lib/src/type_result/type_result.dart @@ -11,5 +11,5 @@ abstract class TypeResult { String decode(final String object); - String encode(final String object); + String encode(final String object, {final bool onlyChildren = false}); }