Skip to content

Make enum trait a list of structures#326

Merged
mtdowling merged 1 commit into0.10from
simplify-enum-trait
Mar 27, 2020
Merged

Make enum trait a list of structures#326
mtdowling merged 1 commit into0.10from
simplify-enum-trait

Conversation

@mtdowling
Copy link
Copy Markdown
Member

@mtdowling mtdowling commented Mar 26, 2020

The enum trait is currently a map of enum value to the enum definition.
This means that models often look like this:

@enum(foo: {}, bar: {})
string MyString

Ideally, a name and documentation are provided too:

@enum(
    foo: {name: "FOO", documentation: "foo docs..."},
    bar: {name: "BAR", documentation: "bar docs..."})

However, the difference between the key and "name" has resulted in
confusion as to which is which. This is caused by a couple things:

  1. The key doesn't tell you what it defines. You have to know that the
    the key defines the value of the enum to make sense of the trait.
  2. The key has to be quoted if it deviates from the allows ABNF for node
    object keys. This has also led to confusion.

Although this is a breaking change, using a list of structures where
everything has a name will result in models that are easier to
understand, and hopefully modelers will more often include properties
like name and documentation.

This now looks like:

@enum([
    {
        value: "foo",
        name: "FOO",
        documentation: "foo docs..."
    },
    {
        value: "bar",
        name: "BAR",
        documentation: "bar docs..."
    }
])

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

The enum trait is currently a map of enum value to the enum definition.
This means that models often look like this:

```
@enum(foo: {}, bar: {})
string MyString
```

Ideally, a name and documentation are provided too:

```
@enum(
    foo: {name: "FOO", documentation: "foo docs..."},
    bar: {name: "BAR", documentation: "bar docs..."})
```

However, the difference between the key and "name" has resulted in
confusion as to which is which. This is caused by a couple things:

1. The key doesn't tell you what it defines. You have to know that the
the key defines the value of the enum to make sense of the trait.
2. The key has to be quoted if it deviates from the allows ABNF for node
object keys. This has also led to confusion.

Although this is a breaking change, using a list of structures where
everything has a name will result in models that are easier to
understand, and hopefully modelers will more often include properties
like `name` and `documentation`.
@mtdowling mtdowling merged commit 918bab2 into 0.10 Mar 27, 2020
@mtdowling mtdowling deleted the simplify-enum-trait branch March 27, 2020 17:41
@kstich kstich mentioned this pull request Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants