From 84c4d61e3a1aeced94eeb977b0ef9c501a519c01 Mon Sep 17 00:00:00 2001 From: Michael van Tellingen Date: Tue, 3 Feb 2026 15:39:12 +0100 Subject: [PATCH] fix(go): handle brackets in identifer name Prevent generating invalid function names like `Filter[attributes]` by rewriting them as ` FilterAttributes` This should fix #333 --- .../io/vrap/codegen/languages/go/GoStringExtension.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/GoStringExtension.kt b/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/GoStringExtension.kt index 180515f67..a0d64ba24 100644 --- a/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/GoStringExtension.kt +++ b/languages/go/src/main/kotlin/io/vrap/codegen/languages/go/GoStringExtension.kt @@ -38,10 +38,11 @@ fun String.exportName(): String { if (this.contains("/")) { throw Exception("Invalid identifier name: " + this) } - if (this[0].isUpperCase()) { - return this + val sanitized = this.replace("[", "_").replace("]", "") + if (sanitized[0].isUpperCase()) { + return sanitized } - var name = StringCaseFormat.UPPER_CAMEL_CASE.apply(this.replace(".", "_")) + var name = StringCaseFormat.UPPER_CAMEL_CASE.apply(sanitized.replace(".", "_")) mapOf( "^Id$" to "ID" ).forEach { (key, value) -> name = name.replace(key.toRegex(), value) }