Skip to content

Commit

Permalink
fix: Property names with special characters in Kotlin SDK (#838)
Browse files Browse the repository at this point in the history
This PR fixes generation of kotlin classes which handle properties having special characters.

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/looker-open-source/sdk-codegen/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Appropriate docs were updated (if necessary)

Fixes #837 🦕
  • Loading branch information
mistryrakesh authored Sep 28, 2021
1 parent 4d1f789 commit 40b6b24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 2 additions & 4 deletions packages/sdk-codegen/src/kotlin.gen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ enum class PermissionType : Serializable {
*/
data class HyphenType (
var project_name: String? = null,
@get:JsonProperty("project-digest")
@param:JsonProperty("project-digest")
@SerializedName("project-digest")
var project_digest: String? = null,
@get:JsonProperty("computation time")
@param:JsonProperty("computation time")
@SerializedName("computation time")
var computation_time: Float? = null
) : Serializable`
expect(actual).toEqual(expected)
Expand Down
6 changes: 5 additions & 1 deletion packages/sdk-codegen/src/kotlin.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ import java.util.*
declareProperty(indent: string, property: IProperty) {
const optional = !property.required ? '? = null' : ''
const type = this.typeMap(property.type)
const result = `${indent}var ${property.name}: ${type.name}${optional}`
// handle property names with special characters
const attr = property.hasSpecialNeeds
? `${indent}@SerializedName("${property.jsonName}")\n`
: ''
const result = `${attr}${indent}var ${property.name}: ${type.name}${optional}`
return result
}

Expand Down

0 comments on commit 40b6b24

Please sign in to comment.