From 04a080f28cb58cc4e06d418f7b67dba4ac8a7bd6 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 2 Sep 2023 20:32:46 +0200 Subject: [PATCH] refactor(dynamite): cleanup valueToEscapedValue api Signed-off-by: Nikolas Rimikis --- .../dynamite/dynamite/lib/src/builder/resolve_object.dart | 2 +- .../dynamite/dynamite/lib/src/builder/resolve_type.dart | 2 +- .../lib/src/helpers/{typeresult.dart => type_result.dart} | 6 +++--- packages/dynamite/dynamite/lib/src/openapi_builder.dart | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) rename packages/dynamite/dynamite/lib/src/helpers/{typeresult.dart => type_result.dart} (65%) diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart index aadbf61d..1b58eb85 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart @@ -3,7 +3,7 @@ import 'package:dynamite/src/builder/resolve_type.dart'; import 'package:dynamite/src/builder/state.dart'; import 'package:dynamite/src/helpers/dart_helpers.dart'; import 'package:dynamite/src/helpers/dynamite.dart'; -import 'package:dynamite/src/helpers/typeresult.dart'; +import 'package:dynamite/src/helpers/type_result.dart'; import 'package:dynamite/src/models/open_api.dart'; import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/type_result/type_result.dart'; diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_type.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_type.dart index dfab4e77..0f17b165 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_type.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_type.dart @@ -2,7 +2,7 @@ import 'package:code_builder/code_builder.dart'; import 'package:dynamite/src/builder/resolve_object.dart'; import 'package:dynamite/src/builder/state.dart'; import 'package:dynamite/src/helpers/dart_helpers.dart'; -import 'package:dynamite/src/helpers/typeresult.dart'; +import 'package:dynamite/src/helpers/type_result.dart'; import 'package:dynamite/src/models/open_api.dart'; import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/type_result/type_result.dart'; diff --git a/packages/dynamite/dynamite/lib/src/helpers/typeresult.dart b/packages/dynamite/dynamite/lib/src/helpers/type_result.dart similarity index 65% rename from packages/dynamite/dynamite/lib/src/helpers/typeresult.dart rename to packages/dynamite/dynamite/lib/src/helpers/type_result.dart index e107ab79..ca1727e0 100644 --- a/packages/dynamite/dynamite/lib/src/helpers/typeresult.dart +++ b/packages/dynamite/dynamite/lib/src/helpers/type_result.dart @@ -1,7 +1,7 @@ import 'package:dynamite/src/helpers/dart_helpers.dart'; import 'package:dynamite/src/type_result/type_result.dart'; -String valueToEscapedValue(final TypeResult result, final dynamic value) { +String valueToEscapedValue(final TypeResult result, final String value) { if (result is TypeResultBase && result.name == 'String') { return "'$value'"; } @@ -9,7 +9,7 @@ String valueToEscapedValue(final TypeResult result, final dynamic value) { return 'const $value'; } if (result is TypeResultEnum) { - return '${result.name}.${toDartName(value.toString())}'; + return '${result.name}.${toDartName(value)}'; } - return value.toString(); + return value; } diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index d5a568b2..fe84455f 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -10,7 +10,7 @@ import 'package:dynamite/src/builder/serializer.dart'; import 'package:dynamite/src/builder/state.dart'; import 'package:dynamite/src/helpers/dart_helpers.dart'; import 'package:dynamite/src/helpers/dynamite.dart'; -import 'package:dynamite/src/helpers/typeresult.dart'; +import 'package:dynamite/src/helpers/type_result.dart'; import 'package:dynamite/src/models/open_api.dart'; import 'package:dynamite/src/models/path_item.dart'; import 'package:dynamite/src/models/schema.dart'; @@ -424,7 +424,7 @@ class OpenAPIBuilder implements Builder { } final defaultValueCode = parameter.schema?.default_ != null - ? valueToEscapedValue(result, parameter.schema!.default_) + ? valueToEscapedValue(result, parameter.schema!.default_.toString()) : null; b.optionalParameters.add(