Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Move enumerations to enumerations attribute in enum #28

Merged
merged 1 commit into from
Jul 26, 2017

Conversation

kylef
Copy link
Member

@kylef kylef commented Jul 25, 2017

Enum was designed a little different to other data structure elements. Other Data Structure elements contain a value of the data structure under content, however enum doesn't contain a single value that the enum was representing but instead all the possible values (enumerations) that may be inside the enum.

This pull request changes enum so that the enum content contains the single selected enumeration, and move the available enumerations to the enumerations attribute. This allows the element to follow the normal data structure rules regarding the type for default and samples where they would match the same type as the data structure elements content.

Examples

To describe an enum with 4 possible string values, north, east, south, west we could represent that as an enum element as follows:

{
  "element": "enum",
  "attributes": {
    "enumerations": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "north"
        },
        {
          "element": "string",
          "content": "east"
        },
        {
          "element": "string",
          "content": "south"
        },
        {
          "element": "string",
          "content": "west"
        }
      ]
    }
  }
}

To describe the same enum with the four directions, and to provide a default value of north. We can represent that as an enum as follows:

{
  "element": "enum",
  "attributes": {
    "default": {
      "element": "string",
      "content": "north"
    },
    "enumerations": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "north"
        },
        {
          "element": "string",
          "content": "east"
        },
        {
          "element": "string",
          "content": "south"
        },
        {
          "element": "string",
          "content": "west"
        }
      ]
    }
  }
}

To describe the same enum, but also to provide a selected sample value of south:

{
  "element": "enum",
  "attributes": {
    "default": {
      "element": "string",
      "content": "north"
    },
    "enumerations": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "north"
        },
        {
          "element": "string",
          "content": "east"
        },
        {
          "element": "string",
          "content": "south"
        },
        {
          "element": "string",
          "content": "west"
        }
      ]
    }
  },
  "content": {
      "element": "string",
      "content": "south"
    }
}

@pksunkara
Copy link
Contributor

Can you add an example for non-selected sample in PR description? I am approving it for now, but not merging yet since @klokane and @w-vi need to take a look too.

@klokane
Copy link
Contributor

klokane commented Jul 26, 2017

👍

@pksunkara pksunkara merged commit 78d90a1 into pksunkara/refract-v1 Jul 26, 2017
@pksunkara pksunkara deleted the kylef/enum branch July 26, 2017 10:27
@klokane
Copy link
Contributor

klokane commented Aug 2, 2017

Ops, we need change description.

Enumeration type. Exclusive list of possible elements. The elements in content's array MUST be interpreted as mutually exclusive.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants