File tree Expand file tree Collapse file tree 7 files changed +26
-30
lines changed
should_generate_basic_enums_correctly
should_generate_enums_properly
should_honor_base_configs
should_honor_onlyTypes_config
should_include_dependent_types_in_onlyTypes_config Expand file tree Collapse file tree 7 files changed +26
-30
lines changed Original file line number Diff line number Diff line change 11overwrite : true
22schema :
33 - " test/**/*.graphql"
4+ config :
5+ namingConvention : " keep"
46generates :
57 test/integration/Types.kt :
68 plugins :
Original file line number Diff line number Diff line change @@ -35,12 +35,11 @@ export function buildEnumTypeDefinition(
3535 config,
3636 definitionNode : node ,
3737 } ) ;
38- return `${ annotations } enum class ${ enumName } (val value: String) {
38+ return `${ annotations } enum class ${ enumName } {
3939${ indentMultiline ( enumValues . join ( ",\n" ) + ";" , 2 ) }
4040
4141 companion object {
42- fun findByName(name: String): ${ enumName } ? = values().find { it.name == name }
43- fun findByValue(value: String): ${ enumName } ? = values().find { it.value == value }
42+ fun findByName(name: String, ignoreCase: Boolean = false): ${ enumName } ? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
4443 }
4544}` ;
4645}
@@ -53,5 +52,5 @@ function buildEnumValueDefinition(
5352 config,
5453 definitionNode : node ,
5554 } ) ;
56- return `${ annotations } ${ config . convert ( node ) } (" ${ node . name . value } ") ` ;
55+ return `${ annotations } ${ config . convert ( node ) } ` ;
5756}
Original file line number Diff line number Diff line change @@ -2,13 +2,12 @@ package com.kotlin.generated
22
33import com.expediagroup.graphql.generator.annotations.*
44
5- enum class UserRole ( val value : String ) {
6- Admin ( " ADMIN " ) ,
7- User ( " USER " ) ,
8- Editor ( " EDITOR " ) ;
5+ enum class UserRole {
6+ Admin ,
7+ User ,
8+ Editor ;
99
1010 companion object {
11- fun findByName (name : String ): UserRole ? = values().find { it.name == name }
12- fun findByValue (value : String ): UserRole ? = values().find { it.value == value }
11+ fun findByName (name : String , ignoreCase : Boolean = false): UserRole ? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
1312 }
1413}
Original file line number Diff line number Diff line change @@ -3,13 +3,12 @@ package com.kotlin.generated
33import com.expediagroup.graphql.generator.annotations.*
44
55@GraphQLDescription(" A description for MyEnum" )
6- enum class MyEnum ( val value : String ) {
7- This ( " THIS " ) ,
6+ enum class MyEnum {
7+ This ,
88 @GraphQLDescription(" A description for THAT" )
9- That ( " THAT " ) ;
9+ That ;
1010
1111 companion object {
12- fun findByName (name : String ): MyEnum ? = values().find { it.name == name }
13- fun findByValue (value : String ): MyEnum ? = values().find { it.value == value }
12+ fun findByName (name : String , ignoreCase : Boolean = false): MyEnum ? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
1413 }
1514}
Original file line number Diff line number Diff line change @@ -3,13 +3,12 @@ package com.kotlin.generated
33import com.expediagroup.graphql.generator.annotations.*
44
55@GraphQLDescription(" A description for MyEnum" )
6- enum class MyEnum ( val value : String ) {
7- THIS ( " THIS " ) ,
6+ enum class MyEnum {
7+ THIS ,
88 @GraphQLDescription(" A description for THAT" )
9- THAT ( " THAT " ) ;
9+ THAT ;
1010
1111 companion object {
12- fun findByName (name : String ): MyEnum ? = values().find { it.name == name }
13- fun findByValue (value : String ): MyEnum ? = values().find { it.value == value }
12+ fun findByName (name : String , ignoreCase : Boolean = false): MyEnum ? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
1413 }
1514}
Original file line number Diff line number Diff line change @@ -11,13 +11,12 @@ data class MyType(
1111)
1212
1313@GraphQLDescription(" A description for MyEnum" )
14- enum class MyEnum ( val value : String ) {
15- This ( " THIS " ) ,
14+ enum class MyEnum {
15+ This ,
1616 @GraphQLDescription(" A description for THAT" )
17- That ( " THAT " ) ;
17+ That ;
1818
1919 companion object {
20- fun findByName (name : String ): MyEnum ? = values().find { it.name == name }
21- fun findByValue (value : String ): MyEnum ? = values().find { it.value == value }
20+ fun findByName (name : String , ignoreCase : Boolean = false): MyEnum ? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
2221 }
2322}
Original file line number Diff line number Diff line change @@ -25,13 +25,12 @@ data class NestedListType(
2525 val field : String? = null
2626)
2727
28- enum class MyEnum ( val value : String ) {
29- This ( " THIS " ) ,
30- That ( " THAT " ) ;
28+ enum class MyEnum {
29+ This ,
30+ That ;
3131
3232 companion object {
33- fun findByName (name : String ): MyEnum ? = values().find { it.name == name }
34- fun findByValue (value : String ): MyEnum ? = values().find { it.value == value }
33+ fun findByName (name : String , ignoreCase : Boolean = false): MyEnum ? = values().find { it.name.equals(name, ignoreCase = ignoreCase) }
3534 }
3635}
3736
You can’t perform that action at this time.
0 commit comments