diff --git a/codegen/gql_code_builder/lib/src/built_class.dart b/codegen/gql_code_builder/lib/src/built_class.dart index 0e7795eb..69a5bfb0 100644 --- a/codegen/gql_code_builder/lib/src/built_class.dart +++ b/codegen/gql_code_builder/lib/src/built_class.dart @@ -1,8 +1,8 @@ import "package:built_collection/built_collection.dart"; import "package:code_builder/code_builder.dart"; -import "package:recase/recase.dart"; import "./common.dart"; +import "./utils/to_camel_case.dart"; /// Generates a class that implements [Built], along with its serializers Class builtClass({ @@ -68,7 +68,7 @@ Class builtClass({ if (getters != null) ...getters, // Serlialization methods buildSerializerGetter(className).rebuild( - (b) => b..body = Code("_\$${className.camelCase}Serializer"), + (b) => b..body = Code("_\$${toCamelCase(className)}Serializer"), ), buildToJsonGetter(className), buildFromJsonGetter(className), diff --git a/codegen/gql_code_builder/lib/src/schema/enum.dart b/codegen/gql_code_builder/lib/src/schema/enum.dart index e17831da..31091015 100644 --- a/codegen/gql_code_builder/lib/src/schema/enum.dart +++ b/codegen/gql_code_builder/lib/src/schema/enum.dart @@ -1,10 +1,10 @@ import "package:built_collection/built_collection.dart"; import "package:code_builder/code_builder.dart"; import "package:gql/ast.dart"; -import "package:gql_code_builder/schema.dart"; -import "package:recase/recase.dart"; -import "package:gql_code_builder/src/common.dart"; +import "../../schema.dart"; +import "../common.dart"; +import "../utils/to_camel_case.dart"; Class buildEnumClass( EnumTypeDefinitionNode node, @@ -97,7 +97,7 @@ ListBuilder _buildMethods( ..type = MethodType.getter ..name = "serializer" ..lambda = true - ..body = Code("_\$${enumName.camelCase}Serializer"), + ..body = Code("_\$${toCamelCase(enumName)}Serializer"), ), Method( (b) => b @@ -113,7 +113,7 @@ ListBuilder _buildMethods( ..type = MethodType.getter ..name = "values" ..lambda = true - ..body = Code("_\$${enumName.camelCase}Values"), + ..body = Code("_\$${toCamelCase(enumName)}Values"), ), Method( (b) => b @@ -128,7 +128,7 @@ ListBuilder _buildMethods( ), ) ..lambda = true - ..body = refer("_\$${enumName.camelCase}ValueOf") + ..body = refer("_\$${toCamelCase(enumName)}ValueOf") .call([refer("name")]).code, ), ], @@ -177,5 +177,5 @@ Field _buildConst( ..type = refer(enumName) ..name = _escapeConstName(node.name.value) ..assignment = Code( - "_\$${enumName.camelCase}${_escapeConstName(node.name.value)}"), + "_\$${toCamelCase(enumName)}${_escapeConstName(node.name.value)}"), ); diff --git a/codegen/gql_code_builder/lib/src/utils/to_camel_case.dart b/codegen/gql_code_builder/lib/src/utils/to_camel_case.dart new file mode 100644 index 00000000..9d27e2c7 --- /dev/null +++ b/codegen/gql_code_builder/lib/src/utils/to_camel_case.dart @@ -0,0 +1,17 @@ +String toCamelCase(String name) { + var result = ""; + var upperCase = false; + var firstCharacter = true; + for (final char in name.split("")) { + if (char == "_") { + upperCase = true; + } else { + result += firstCharacter + ? char.toLowerCase() + : (upperCase ? char.toUpperCase() : char); + upperCase = false; + firstCharacter = false; + } + } + return result; +} diff --git a/codegen/gql_code_builder/pubspec.yaml b/codegen/gql_code_builder/pubspec.yaml index 2ee9913f..19aa8321 100644 --- a/codegen/gql_code_builder/pubspec.yaml +++ b/codegen/gql_code_builder/pubspec.yaml @@ -2,9 +2,9 @@ name: gql_code_builder version: 0.2.0 description: Dart code builders taking *.graphql documents and SDL to build useful classes. repository: https://github.com/gql-dart/gql -environment: +environment: sdk: '>=2.12.0 <3.0.0' -dependencies: +dependencies: analyzer: ^1.2.0 built_collection: ^5.0.0 built_value: ^8.0.6 @@ -13,8 +13,7 @@ dependencies: gql: ^0.13.0 gql_exec: ^0.3.0 path: ^1.8.0 - recase: ^4.0.0 -dev_dependencies: +dev_dependencies: build_runner: ^2.0.0 gql_pedantic: ^1.0.2 test: ^1.16.8