Skip to content

Instantly share code, notes, and snippets.

@klokane
Last active August 16, 2017 15:26
Show Gist options
  • Save klokane/db31ca1383e33cc71a4e168e398c1271 to your computer and use it in GitHub Desktop.
Save klokane/db31ca1383e33cc71a4e168e398c1271 to your computer and use it in GitHub Desktop.
API elements - Enum

Enum part of definition

- size16: A (enum) 
    - D
    - E

    - sample
        - F
        - G

    - default
        - H

Is converted into:

{
  "element": "enum",
  "attributes": {
    "samples": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "F"
        },
        {
          "element": "string",
          "content": "G"
        }
      ]
    },
    "enumerations": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "D"
        },
        {
          "element": "string",
          "content": "E"
        }
      ]
    },
    "default": {
      "element": "string",
      "content": "H"
    }
  },
  "content": {
    "element": "string",
    "content": "A"
  }
}

I'm not satisfied with, default and samples. For other cases there is in this attributes Element it self

e.g. for same definition of array instead of enum

{
  "element": "array",
  "attributes": {
    "samples": {
      "element": "array",
      "content": [
        {
          "element": "array",
          "content": [
            {
              "element": "string",
              "content": "F"
            },
            {
              "element": "string",
              "content": "G"
            }
          ]
        }
      ]
    },
    "default": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "H"
        }
      ]
    }
  },
  "content": [
    {
      "element": "string",
      "content": "A"
    },
    {
      "element": "string",
      "content": "D"
    },
    {
      "element": "string",
      "content": "E"
    }
  ]
}

So it is question, what should be result for enum To be consistent it has to be array of enum elements for samples and enum element for element.

There is question if sample should be more enums with individual values

{
  "element": "enum",
  "attributes": {
    "samples": {
      "element": "array",
      "content": [
        {
          "element" : "enum"
          "content" : {
            "element": "string",
            "content": "F"
          }
        },
        {
          "element" : "enum"
          "content" : {
            "element": "string",
            "content": "G"
          }
        },
      ]
    },
    "enumerations": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "D"
        },
        {
          "element": "string",
          "content": "E"
        }
      ]
    },
    "default": {
      "element": "enum",
      "content": {
        "element": "string",
        "content": "H"
      }
    }
  },
  "content": {
    "element": "string",
    "content": "A"
  }
}

Or one enum with attribute enumerations

{
  "element": "enum",
  "attributes": {
    "samples": {
      "element": "array",
      "content": [
        {
          "element": "enum",
          "attributes" : {
            "enumerations": {
              "element": "array",
              "content": [
                {
                  "element": "string",
                  "content": "D"
                },
                {
                  "element": "string",
                  "content": "E"
                }
              ]
            }
          }
        }
      ]
    },
    "enumerations": {
      "element": "array",
      "content": [
        {
          "element": "string",
          "content": "D"
        },
        {
          "element": "string",
          "content": "E"
        }
      ]
    },
    "default": {
      "element": "enum",
      "content": {
        "element": "string",
        "content": "H"
    }
  },
  "content": {
    "element": "string",
    "content": "A"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment