From 40b6b24bfedf8ba16b5dbae2abbbdce2f73c1ffd Mon Sep 17 00:00:00 2001 From: Rakesh Mistry Date: Tue, 28 Sep 2021 16:10:13 +0000 Subject: [PATCH] fix: Property names with special characters in Kotlin SDK (#838) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 🦕 --- packages/sdk-codegen/src/kotlin.gen.spec.ts | 6 ++---- packages/sdk-codegen/src/kotlin.gen.ts | 6 +++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/sdk-codegen/src/kotlin.gen.spec.ts b/packages/sdk-codegen/src/kotlin.gen.spec.ts index ffff1acd2..4f890ecb1 100644 --- a/packages/sdk-codegen/src/kotlin.gen.spec.ts +++ b/packages/sdk-codegen/src/kotlin.gen.spec.ts @@ -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) diff --git a/packages/sdk-codegen/src/kotlin.gen.ts b/packages/sdk-codegen/src/kotlin.gen.ts index 3ce7e64f7..d32ce6e65 100644 --- a/packages/sdk-codegen/src/kotlin.gen.ts +++ b/packages/sdk-codegen/src/kotlin.gen.ts @@ -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 }