Skip to content

Commit

Permalink
chore: add string to pascal case extension (#643)
Browse files Browse the repository at this point in the history
PR: #643
  • Loading branch information
OmarAlJarrah authored Aug 1, 2024
1 parent 510c0ae commit 6b4a5a8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.expediagroup.sdk.generators.openapi

/**
* This extension function converts a string to PascalCase.
* PascalCase is a type of identifier that consists of compound words or phrases such that each word or abbreviation begins with a capital letter.
* Non-alphabetic characters are ignored, and the next alphabetic character after them is capitalized.
*
* @receiver String The string to be converted to PascalCase.
* @return String The string converted to PascalCase.
*/
fun String.pascalCase(): String {
var capitalizeNext = true
val builder = StringBuilder()
forEach { char ->
when {
char.isLetterOrDigit().and(capitalizeNext) -> builder.append(char.uppercaseChar())
char.isLetterOrDigit() -> builder.append(char)
}
capitalizeNext = char.isLetter().not().or(builder.isEmpty())
}
return builder.toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class OpenApiSdkGenerator {
// Template specific properties
addAdditionalProperty("shadePrefix", product.shadePrefix)
addAdditionalProperty("namespace", product.namespace)
addAdditionalProperty("clientClassname", namespace.replaceFirstChar { it.uppercaseChar() })
addAdditionalProperty("clientClassname", namespace.pascalCase())
addAdditionalProperty("language", product.programmingLanguage.id)
addAdditionalProperty("isKotlin", ProgrammingLanguage.isKotlin(product.programmingLanguage))
addAdditionalProperty("isRapid", ProductFamily.isRapid(product.namespace))
Expand Down

0 comments on commit 6b4a5a8

Please sign in to comment.