Repository: cjbooms/fabrikt (kotlin)

Issue:
Unable to generate files with Norwegian letters øåø
Hei, I have been trying to make fabrikt generate files with utf-8 encoding by passing file encoding to the file generation task but without luck. The files generated do not contain norwgian charactes øæå . Am I setting the encoding wrong ?

tasks {
    val generateCode by creating(JavaExec::class) {
        print(apiFile)
        inputs.files(apiFile)
        outputs.dir(generationDir)
        outputs.cacheIf { true }
        classpath(fabrikt)
        main = "com.cjbooms.fabrikt.cli.CodeGen"
        jvmArgs?.add("-Dfile.encoding=UTF-8")
        args = listOf(
            "--output-directory", generationDir,
            "--base-package", "xxxxxxxxx",
            "--api-file", apiFile,
            "--targets", "http_models",
            "--http-client-opts", "resilience4j"
        )
    }

Pull request description:
Not the prettiest, but this fixes #167

Patch:
diff --git a/src/main/kotlin/com/cjbooms/fabrikt/util/NormalisedString.kt b/src/main/kotlin/com/cjbooms/fabrikt/util/NormalisedString.kt
index 2d346742..f957d11c 100644
--- a/src/main/kotlin/com/cjbooms/fabrikt/util/NormalisedString.kt
+++ b/src/main/kotlin/com/cjbooms/fabrikt/util/NormalisedString.kt
@@ -11,10 +11,10 @@ object NormalisedString {
             .joinToString("") { it.capitalized() }
 
     private fun String.replaceSpecialCharacters() =
-        Regex("[^A-Za-z0-9]").replace(this, "_")
+        Regex("[^A-Za-z0-9øæåØÆÅ]").replace(this, "_")
 
     private fun String.camelToSnake() =
-        Regex("[a-z][A-Z]")
+        Regex("[a-zøæå][A-ZØÆÅ]")
             .replace(this) { pair ->
                 val characters = pair.value.toCharArray()
                 "${characters[0]}_${characters[1]}"


Test patch:
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/util/NormalisedStringTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/util/NormalisedStringTest.kt
index 069cd6b8..886e0fb3 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/util/NormalisedStringTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/util/NormalisedStringTest.kt
@@ -13,6 +13,10 @@ class NormalisedStringTest {
     fun `should transform string with underscores to pascal case`() {
         assertThat("abc_def-hij".pascalCase()).isEqualTo("AbcDefHij")
     }
+    @Test
+    fun `should handle norwegian characters`() {
+        assertThat("Åabc_øæå-ØÆÅ-hij".pascalCase()).isEqualTo("ÅabcØæåØÆÅHij")
+    }
 
     @Test
     fun `should transform string with underscores to camel case`() {
@@ -49,4 +53,9 @@ class NormalisedStringTest {
         assertThat("PascalCase_enumWith-special/characters.json".toEnumName())
             .isEqualTo("PASCAL_CASE_ENUM_WITH_SPECIAL_CHARACTERS_JSON")
     }
+    @Test
+    fun `toEnumName should return an upper snake case enum with with norwegian characters`() {
+        assertThat("PascalCase_enumWith-ÅabcØæ-åØÆÅHij-special/characters.json".toEnumName())
+            .isEqualTo("PASCAL_CASE_ENUM_WITH_ÅABC_ØÆ_Å_ØÆÅHIJ_SPECIAL_CHARACTERS_JSON")
+    }
 }