override fun unionBodyByConstants()

in build-logic/generatorlegacybuild/src/main/kotlin/karakum/common/UnionConverter.kt [124:151]


    override fun unionBodyByConstants(
        name: String,
        constants: List<UnionConstant>,
    ): String {
        val interfaceName = name.substringBefore('<')
        val hasGenerics = interfaceName != name

        val extensions = constants.joinToString("\n\n") {
            require(!hasGenerics || it.type != null) {
                "You should specify types for all generic unions. Wrong constant: $it."
            }

            it.withComment(
                """
            inline val $interfaceName.Companion.${it.name}: ${it.type ?: name}
                get() = unsafeCast(${it.jsValue})
            """,
            )
        }

        return """
               sealed external interface $name {
                  companion object
               }

               $extensions
               """.trimIndent()
    }