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

Use actual enum types for strings that have a finite set of possible values #90

Closed
joffrey-bion opened this issue May 13, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@joffrey-bion
Copy link
Owner

joffrey-bion commented May 13, 2021

Some inputs contain string properties that are in fact enums with a specific set of values. For instance, DispatchMouseEventRequest.type is technically sent as a string on the wire, but is defined as an enum with specific possible values in the protocol.

It would be nice if this was exposed to the user as an enum instead of a string. We would need to make sure that the enum constants are properly defined so that Kotlinx Serialization sends the proper string on the wire.

@joffrey-bion joffrey-bion added the enhancement New feature or request label May 13, 2021
joffrey-bion added a commit that referenced this issue May 13, 2021
@joffrey-bion
Copy link
Owner Author

joffrey-bion commented May 17, 2021

The challenge here is that these "inline" enums have no name, so we need to generate one that somehow conveys the correct meaning, which is not reliable and thus not ideal. The better way to fix that would be to actually declare these enums as domain types at the top level, like other object and enum types (see ChromeDevTools/devtools-protocol#244).

If this doesn't happen, one strategy to generate the name of the enum type could be the following:

  • for properties of an object: the name of the enum type could be the containing object type name suffixed by the capitalized property name. Example
    • type: LogEntry
    • property: level
    • inferred enum type name: LogEntryLevel
  • for parameters of a command's input/output type: the name of the command without the leading word + the capitalized parameter name. Removing the leading word allows to get rid of the verb of the command (which is the most common case). For example:
    • command: dispatchDragEvent
    • parameter: type
    • inferred enum type name: DragEventType
  • for parameters of an event: the capitalized name of the event + the capitalized parameter name. For example:
    • command: frameDetached
    • parameter: reason
    • inferred enum type name: FrameDetachedReason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant