From 7150e32253c3aa9f6d0d433d977665afa00daff5 Mon Sep 17 00:00:00 2001 From: Uladzimir_Paliukhovich Date: Fri, 17 Nov 2023 15:11:07 +0300 Subject: [PATCH] Development (#679) * Fixed some issues * formatted code * updated SDK * Updated SDK and version * Fixed generation of lists of classes * Fixed generation $Items classes * Updated pubspec and changelog * Fixed #524 * Fixed #598 Generation of query enum parameters * Fixed conflicts * Fixed some issues in swaggers * Updated changelog and pubspec * Fix #583, #637, #619 and update readme (#638) * fix #583 and update readme * fix #637 * fix #619 * Fixed generation of some fields * Removed test * Fixed classes named List * Fixed generation of query parameters with ref default type * Fixed generation of DateTime parameters * Fixed generation of responses in some cases * Some fixes * Updated changelog and pubspec * Implemented not nullable fields * Fixed tests * fixed generation of some swaggers * Added ability to return String values * Returned main.dart content * Updated pubspec and changelog * Fixed generation of required and not required fields * Added check for object ref in body * Fixed some things * Fixed tests * Fixed tests * Fixed some things * Updated changelog and pubspec * Removed not needed lines in tests * Fixed generation of nullable responses * Added generation of DateTime * Updated pubspec and changelog * Fixed tests * Fixed #669 Generation models from content schema allof * Fixed #665 generation putIfAbsent for response from content schema * Fixed generation of nullable and required properties * Fixed tests * Fixed some stuff related to nullable properties * Updated changelog and pubspec * Formatted code * Formatted code * Fixed tests * Fixed generation of some enums inside classes * Implemented support of exploded parameters * Pushed constants file --------- Co-authored-by: Uladzimir Paliukhovich Co-authored-by: Romain --- lib/src/code_generators/constants.dart | 2 + lib/src/code_generators/enum_model.dart | 6 +++ .../swagger_requests_generator.dart | 47 +++++++++++++++---- .../requests/swagger_request_parameter.dart | 4 ++ .../swagger_request_parameter.g2.dart | 2 + 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/lib/src/code_generators/constants.dart b/lib/src/code_generators/constants.dart index 3b76d788..8b0a672b 100644 --- a/lib/src/code_generators/constants.dart +++ b/lib/src/code_generators/constants.dart @@ -88,6 +88,8 @@ const kCookie = 'cookie'; const kArray = 'array'; const kEnum = 'enum'; const kBody = 'body'; +const kQuery = 'query'; +const kExplodedQuery ='ExplodedQuery'; const kPartFile = 'partFile'; const kPart = 'part'; diff --git a/lib/src/code_generators/enum_model.dart b/lib/src/code_generators/enum_model.dart index 9107c8c6..4ff61b92 100644 --- a/lib/src/code_generators/enum_model.dart +++ b/lib/src/code_generators/enum_model.dart @@ -134,6 +134,12 @@ enums.$name? ${name.camelCase}NullableFromJson( return enums.$name.values.firstWhereOrNull((e) => e.value == ${name.camelCase}) ?? defaultValue; } +String ${name.camelCase}ExplodedListToJson( + List? ${name.camelCase}) { + + return ${name.camelCase}?.map((e) => e.value!).join(',') ?? ''; +} + List<$type> ${name.camelCase}ListToJson( List? ${name.camelCase}) { diff --git a/lib/src/code_generators/swagger_requests_generator.dart b/lib/src/code_generators/swagger_requests_generator.dart index 1c309acc..7c962d07 100644 --- a/lib/src/code_generators/swagger_requests_generator.dart +++ b/lib/src/code_generators/swagger_requests_generator.dart @@ -359,20 +359,22 @@ class SwaggerRequestsGenerator extends SwaggerGeneratorBase { Method _getPrivateMethod(Method method) { final parameters = method.optionalParameters.map((p) { + Parameter result = p; + if (p.type!.symbol!.startsWith('enums.')) { if (p.annotations .any((p0) => p0.code.toString().contains('symbol=Body'))) { - return p.copyWith(type: Reference('dynamic')); + result = result.copyWith(type: Reference('dynamic')); } else { - return p.copyWith(type: Reference('String?')); + result = result.copyWith(type: Reference('String?')); } } if (p.annotations.first.code.toString().contains('symbol=Header')) { if (p.type?.symbol?.startsWith('List<') == true) { - return p.copyWith(type: Reference('Iterable?')); + result = result.copyWith(type: Reference('Iterable?')); } - return p.copyWith(type: Reference('String?')); + result = result.copyWith(type: Reference('String?')); } if (p.type!.symbol!.startsWith('List')) { @@ -381,14 +383,21 @@ class SwaggerRequestsGenerator extends SwaggerGeneratorBase { if (listType.startsWith('enums.')) { if (p.annotations .any((p0) => p0.code.toString().contains('symbol=Body'))) { - return p.copyWith(type: Reference('dynamic')); + result = result.copyWith(type: Reference('dynamic')); } else { - return p.copyWith(type: Reference('List?')); + result = result.copyWith(type: Reference('List?')); } } } - return p; + if (p.annotations.first.code + .toString() + .contains('symbol=ExplodedQuery')) { + result = result.copyWith( + annotations: [refer('Query()')], type: Reference('String?')); + } + + return result; }); return Method( @@ -425,6 +434,11 @@ class SwaggerRequestsGenerator extends SwaggerGeneratorBase { List allModels, ) { final parametersListString = parameters.map((p) { + final isExposed = p.annotations.firstOrNull?.code + .toString() + .contains('symbol=ExplodedQuery') ?? + false; + if (p.type!.symbol!.startsWith('enums.')) { return '${p.name} : ${p.name}?.value?.toString()'; } @@ -442,7 +456,12 @@ class SwaggerRequestsGenerator extends SwaggerGeneratorBase { if (p.type!.symbol!.startsWith('List? ?? [], + explode: json['explode'] as bool? ?? false, ); Map _$SwaggerRequestParameterToJson( SwaggerRequestParameter instance) => { 'in': instance.inParameter, + 'explode': instance.explode, 'name': instance.name, 'description': instance.description, 'required': instance.isRequired,