Skip to content

Nested enum types have no name #244

@joffrey-bion

Description

@joffrey-bion

Some domain types/commands/events in the JSON protocol definitions have properties/parameters of enum types that are not references to a top-level domain enum type, but that are instead inlined on the spot. For instance here is one:

...
{
    "name": "emulateTouchFromMouseEvent",
    "description": "Emulates touch event from the mouse event parameters.",
    "experimental": true,
    "parameters": [
        {
            "name": "type",
            "description": "Type of the mouse event.",
            "type": "string",
            "enum": [
                "mousePressed",
                "mouseReleased",
                "mouseMoved",
                "mouseWheel"
            ]
...

I'm generating code from the JSON definitions, but I'm facing 2 problems with this at the moment:

  1. because these types are not defined at the top level as "domain types", they have no name so I have to either use a plain String type (which defeats the purpose of the enum) or generate a name (which might not be user-friendly). In the example above, a good name might be MouseEventType. This problem would affect any language that doesn't support string union types (in my case, Kotlin).
  2. some of these enums are implicitily reused across multiple commands/events (the example above appears in dispatchMouseEvent and emulateTouchFromMouseEvent), but there is no way to tell whether they are different types and just happen to have the same enum values (and thus might change independently), or whether they are a single reused type (and thus will evolve together and always stay in sync). This means I cannot choose systematically between declaring different enum types or just one. This problem would affect the same set of languages I believe, basically all those who have to declare enums as a named type.

I haven't found any inlined object type like this (these are only refs), I only found enums suffering from this problem.

It would be great if all enums were extracted into the domain types list and only references appeared in the properties and parameters. Some enums already are defined at the top level, just not all of them.

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