matrix-org / matrix-analytics-events

Cross-platform definitions of analytics events raised by matrix SDKs
Apache License 2.0
8 stars 7 forks source link

Support enum with whitespaces #105

Closed BillCarsonFr closed 3 months ago

BillCarsonFr commented 3 months ago

When using white spaces in oneOf enum types the generated kotlin and swift code was not valid (white space in the property name).

The main changes are in kotlin.py and swift.py, typescript generation was ok with whitespaces.

The change will be invisible for users of the library.

Kotlin

For kotlin, a new field rawValue is added in the generated enum and is used in the getProperties method instead of the enum autogenerated name.

Before:

    enum class VerificationState {
          NotVerified,
          ...

          override fun getProperties(): Map<String, Any>? {
               ...
               put("verificationState", verificationState.name)
               ...
          }

After

    enum class VerificationState(val rawValue: String) {
          NotVerified("NotVerified"),
          ...

          override fun getProperties(): Map<String, Any>? {
               ...
               put("verificationState", verificationState.rawValue)
               ...
          }

Swift

The enum were alreasy : String just now explicitely adding the rawvalue

Before:

        public enum VerificationState: String {
            ...
            case NotVerified

Now:

        public enum VerificationState: String {
            ...
            case NotVerified = "NotVerified"