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) {
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(

2
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)';

2
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})';

13
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()';

2
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<String, ${subType.name}>)';

2
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) {

2
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});
}

Loading…
Cancel
Save