Browse Source

Merge pull request #144 from provokateurin/fix/array-query-parameters

dynamite: Fix array query parameters
pull/145/head
Kate 2 years ago committed by GitHub
parent
commit
258175ffbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      packages/dynamite/lib/src/openapi_builder.dart
  2. 2
      packages/dynamite/lib/src/type_result/base.dart
  3. 2
      packages/dynamite/lib/src/type_result/enum.dart
  4. 13
      packages/dynamite/lib/src/type_result/list.dart
  5. 2
      packages/dynamite/lib/src/type_result/map.dart
  6. 2
      packages/dynamite/lib/src/type_result/object.dart
  7. 2
      packages/dynamite/lib/src/type_result/type_result.dart

9
packages/dynamite/lib/src/openapi_builder.dart

@ -600,7 +600,11 @@ class OpenAPIBuilder implements Builder {
if (nullable) { if (nullable) {
code.write('if (${_toDartName(parameter.name)} != null) {'); 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_) { switch (parameter.in_) {
case 'path': case 'path':
code.write( code.write(
@ -609,7 +613,7 @@ class OpenAPIBuilder implements Builder {
break; break;
case 'query': case 'query':
code.write( code.write(
"queryParameters['${parameter.name}${result is TypeResultList ? '[]' : ''}'] = $value;", "queryParameters['${parameter.name}${isPlainList ? '[]' : ''}'] = $value;",
); );
break; break;
case 'header': case 'header':
@ -1417,6 +1421,7 @@ TypeResult resolveType(
result = TypeResultList( result = TypeResultList(
'List<${subResult.name}>', 'List<${subResult.name}>',
subResult, subResult,
fromJsonString: fromJsonString,
); );
} else { } else {
result = TypeResultList( result = TypeResultList(

2
packages/dynamite/lib/src/type_result/base.dart

@ -7,7 +7,7 @@ class TypeResultBase extends TypeResult {
String serialize(final String object) => object; String serialize(final String object) => object;
@override @override
String encode(final String object) => '$object.toString()'; String encode(final String object, {final bool onlyChildren = false}) => '$object.toString()';
@override @override
String deserialize(final String object) => '($object as $name)'; String deserialize(final String object) => '($object as $name)';

2
packages/dynamite/lib/src/type_result/enum.dart

@ -12,7 +12,7 @@ class TypeResultEnum extends TypeResult {
String serialize(final String object) => '$object.value'; String serialize(final String object) => '$object.value';
@override @override
String encode(final String object) => subType.encode(object); String encode(final String object, {final bool onlyChildren = false}) => subType.encode(object);
@override @override
String deserialize(final String object) => '$name.fromValue($object as ${subType.name})'; String deserialize(final String object) => '$name.fromValue($object as ${subType.name})';

13
packages/dynamite/lib/src/type_result/list.dart

@ -3,16 +3,23 @@ part of '../../dynamite.dart';
class TypeResultList extends TypeResult { class TypeResultList extends TypeResult {
TypeResultList( TypeResultList(
super.name, super.name,
this.subType, this.subType, {
); this.fromJsonString = false,
});
final TypeResult subType; final TypeResult subType;
final bool fromJsonString;
@override @override
String serialize(final String object) => '$object.map((final e) => ${subType.serialize('e')}).toList()'; String serialize(final String object) => '$object.map((final e) => ${subType.serialize('e')}).toList()';
@override @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 @override
String deserialize(final String object) => '($object as List).map((final e) => ${subType.deserialize('e')}).toList()'; String deserialize(final String object) => '($object as List).map((final e) => ${subType.deserialize('e')}).toList()';

2
packages/dynamite/lib/src/type_result/map.dart

@ -12,7 +12,7 @@ class TypeResultMap extends TypeResult {
String serialize(final String object) => object; String serialize(final String object) => object;
@override @override
String encode(final String object) => 'json.encode($object)'; String encode(final String object, {final bool onlyChildren = false}) => 'json.encode($object)';
@override @override
String deserialize(final String object) => '($object as Map<String, ${subType.name}>)'; String deserialize(final String object) => '($object as Map<String, ${subType.name}>)';

2
packages/dynamite/lib/src/type_result/object.dart

@ -17,7 +17,7 @@ class TypeResultObject extends TypeResult {
} }
@override @override
String encode(final String object) => 'json.encode($object)'; String encode(final String object, {final bool onlyChildren = false}) => 'json.encode($object)';
@override @override
String deserialize(final String object) { String deserialize(final String object) {

2
packages/dynamite/lib/src/type_result/type_result.dart

@ -11,5 +11,5 @@ abstract class TypeResult {
String decode(final String object); String decode(final String object);
String encode(final String object); String encode(final String object, {final bool onlyChildren = false});
} }

Loading…
Cancel
Save