Skip to content

Commit

Permalink
Add `` to "default" Swift enum value (#125)
Browse files Browse the repository at this point in the history
* Fix: add `` to "default" swift enum value.

* Add `default` enum value to demo
  • Loading branch information
liangdrime authored Jul 2, 2024
1 parent 8b1c7c2 commit c4394ce
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
7 changes: 5 additions & 2 deletions demo/basic/generated/kotlin/BridgeTypes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ data class OverriddenFullSize(
)

enum class NumEnum(val value: Int) {
DEFAULT(0),
ONE(1),
TWO(2);

Expand All @@ -57,13 +58,15 @@ class NumEnumTypeAdapter : JsonSerializer<NumEnum>, JsonDeserializer<NumEnum> {
}

enum class StringEnum {
@SerializedName("default") DEFAULT,
@SerializedName("a") A,
@SerializedName("b") B
}

enum class DefaultEnum(val value: Int) {
DEFAULT_VALUE_C(0),
DEFAULT_VALUE_D(1);
DEFAULT(0),
DEFAULT_VALUE_C(1),
DEFAULT_VALUE_D(2);

companion object {
fun find(value: Int) = values().find { it.value == value }
Expand Down
7 changes: 5 additions & 2 deletions demo/basic/generated/swift/SharedTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ public struct OverriddenFullSize: Codable {
}

public enum NumEnum: Int, Codable {
case `default` = 0
case one = 1
case two = 2
}

public enum StringEnum: String, Codable {
case `default` = "default"
/// Description for enum member a
case a = "a"
case b = "b"
}

public enum DefaultEnum: Int, Codable {
case defaultValueC = 0
case defaultValueD = 1
case `default` = 0
case defaultValueC = 1
case defaultValueD = 2
}

public enum OverriddenFullSizeMembersStringUnionType: String, Codable {
Expand Down
3 changes: 3 additions & 0 deletions demo/basic/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface CustomSize {
}

enum StringEnum {
default = 'default',
/**
* Description for enum member a
*/
Expand All @@ -21,11 +22,13 @@ enum StringEnum {
}

enum NumEnum {
default = 0,
one = 1,
two = 2,
}

enum DefaultEnum {
default,
defaultValueC,
defaultValueD,
}
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/value-transformer/SwiftValueTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export class SwiftValueTransformer implements ValueTransformer {
return '';
}

if (text.toLowerCase() === 'default') {
return '`default`';
}

let index = 0;
// Get the index of the first lowercased letter
while (index < text.length) {
Expand Down

0 comments on commit c4394ce

Please sign in to comment.