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
7 files changed +26
-30
lines changed Original file line number Diff line number Diff line change 1
1
overwrite : true
2
2
schema :
3
3
- " test/**/*.graphql"
4
+ config :
5
+ namingConvention : " keep"
4
6
generates :
5
7
test/integration/Types.kt :
6
8
plugins :
Original file line number Diff line number Diff line change @@ -35,12 +35,11 @@ export function buildEnumTypeDefinition(
35
35
config,
36
36
definitionNode : node ,
37
37
} ) ;
38
- return `${ annotations } enum class ${ enumName } (val value: String) {
38
+ return `${ annotations } enum class ${ enumName } {
39
39
${ indentMultiline ( enumValues . join ( ",\n" ) + ";" , 2 ) }
40
40
41
41
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) }
44
43
}
45
44
}` ;
46
45
}
@@ -53,5 +52,5 @@ function buildEnumValueDefinition(
53
52
config,
54
53
definitionNode : node ,
55
54
} ) ;
56
- return `${ annotations } ${ config . convert ( node ) } (" ${ node . name . value } ") ` ;
55
+ return `${ annotations } ${ config . convert ( node ) } ` ;
57
56
}
Original file line number Diff line number Diff line change @@ -2,13 +2,12 @@ package com.kotlin.generated
2
2
3
3
import com.expediagroup.graphql.generator.annotations.*
4
4
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 ;
9
9
10
10
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) }
13
12
}
14
13
}
Original file line number Diff line number Diff line change @@ -3,13 +3,12 @@ package com.kotlin.generated
3
3
import com.expediagroup.graphql.generator.annotations.*
4
4
5
5
@GraphQLDescription(" A description for MyEnum" )
6
- enum class MyEnum ( val value : String ) {
7
- This ( " THIS " ) ,
6
+ enum class MyEnum {
7
+ This ,
8
8
@GraphQLDescription(" A description for THAT" )
9
- That ( " THAT " ) ;
9
+ That ;
10
10
11
11
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) }
14
13
}
15
14
}
Original file line number Diff line number Diff line change @@ -3,13 +3,12 @@ package com.kotlin.generated
3
3
import com.expediagroup.graphql.generator.annotations.*
4
4
5
5
@GraphQLDescription(" A description for MyEnum" )
6
- enum class MyEnum ( val value : String ) {
7
- THIS ( " THIS " ) ,
6
+ enum class MyEnum {
7
+ THIS ,
8
8
@GraphQLDescription(" A description for THAT" )
9
- THAT ( " THAT " ) ;
9
+ THAT ;
10
10
11
11
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) }
14
13
}
15
14
}
Original file line number Diff line number Diff line change @@ -11,13 +11,12 @@ data class MyType(
11
11
)
12
12
13
13
@GraphQLDescription(" A description for MyEnum" )
14
- enum class MyEnum ( val value : String ) {
15
- This ( " THIS " ) ,
14
+ enum class MyEnum {
15
+ This ,
16
16
@GraphQLDescription(" A description for THAT" )
17
- That ( " THAT " ) ;
17
+ That ;
18
18
19
19
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) }
22
21
}
23
22
}
Original file line number Diff line number Diff line change @@ -25,13 +25,12 @@ data class NestedListType(
25
25
val field : String? = null
26
26
)
27
27
28
- enum class MyEnum ( val value : String ) {
29
- This ( " THIS " ) ,
30
- That ( " THAT " ) ;
28
+ enum class MyEnum {
29
+ This ,
30
+ That ;
31
31
32
32
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) }
35
34
}
36
35
}
37
36
You can’t perform that action at this time.
0 commit comments