Skip to content

Enum value is lost in the Typescript to Kotlin - Just Types conversation. #1601

Description

@svendvd

Hi, great tool!

But unfortunately, there is an issue in the conversion to Kotlin - Just Types.

As you can see in the Kotlin - Just Types conversation (https://app.quicktype.io?share=cOBGvVmpkp0Ota6z7rno)
You do not have the value information as in the Java - "Plain types only" conversation. (https://app.quicktype.io?share=LvTtRA7APM4tiMM2LnKs)

The typescript definition:

export enum CanvasAction {
  ADD = 'add',
  BRING_TO_FRONT = 'bringtofront',
  DELETE = 'delete',
  FLIP = 'flip',
  INVERT = 'invert',
  UNDO = 'undo',
  REDO = 'redo',
}

is becoming:

enum class CanvasAction {
    Add,
    Bringtofront,
    Delete,
    Flip,
    Invert,
    Redo,
    Undo
}

But it should be:

enum class CanvasAction(private val value: String) {
    ADD("add"),
    BRINGTOFRONT("bringtofront"),
    DELETE("delete"),
    FLIP("flip"),
    INVERT("invert"),
    REDO("redo"),
    UNDO("undo");

    fun toValue() = value

    companion object {
        @Throws(IOException::class)
        fun forValue(id: String) = values().find { it.value == id } 
           ?: throw IOException("Cannot deserialize CanvasAction")
    }
}

Best,
Sven

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions