Skip to content

Enums as Types #26

@that-hatter

Description

@that-hatter

Should Enums be usable as Types? e.g.:

parameters:
  - name: loc
    type: [ Location ]
    description: The location to check.

instead of using int and linking to the enum in the description:

parameters:
  - name: loc
    type: [ int ]
    description: The [Location](/api/enums/Location) to check.

This means the signature of Card.IsLocation in the site would be displayed as Card.IsLocation(Card c, Location loc) instead of Card.IsLocation(Card c, int loc).

Pros:

  • The allowed values are formalized and summarized nicely. Can also help static analyzers narrow down erroneous values.
  • No need to redundantly link to the enum in the description, especially if the enum's name gets mentioned more than once. (Related: shorthand for linking to api entries)

Cons:

  • Could confuse people expecting an "enum" to represent all allowed values when used as a type. For example, in the case of the Location enum, you could actually pass a combination of LOCATION_ constants, e.g. LOCATION_MZONE|LOCATION_SZONE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions