Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `` to "default" Swift enum value #125

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading