Skip to content

Commit

Permalink
Merge pull request #301 from zanonena/feature/interface-companion
Browse files Browse the repository at this point in the history
Generate companion objects for union interfaces in Kotlin
  • Loading branch information
srinivasankavitha authored Dec 3, 2021
2 parents ece4e0d + 6d7dadb commit c651a77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class KotlinUnionTypeGenerator(private val config: CodeGenConfig) {
interfaceBuilder.addAnnotation(jsonTypeInfoAnnotation())
interfaceBuilder.addAnnotation(jsonSubTypesAnnotation(memberTypes))
}

interfaceBuilder.addType(TypeSpec.companionObjectBuilder().build())

val fileSpec = FileSpec.get(packageName, interfaceBuilder.build())
return CodeGenResult(kotlinInterfaces = listOf(fileSpec))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,9 @@ class KotlinCodeGenTest {
| JsonSubTypes.Type(value = Actor::class, name = "Actor"),
| JsonSubTypes.Type(value = Rating::class, name = "Rating")
|])
|public interface SearchResult
|public interface SearchResult {
| public companion object
|}
""".trimMargin()
)
Expand Down

0 comments on commit c651a77

Please sign in to comment.