Creating an array of elements declared previously on enum


#1

I’m stuck in one point developing this RAML thing. In my included JSON to test the hierarchy of the RAML objects I need to construct like this:

"communicationWays": [
   {
     "SMS": false,
     "EMAIL": true,
     "VOICE": false,
     "MAIL": false
   }
 ]

But my question is: how can I implement it on RAML part?? I think about something like this…

types:
  communicationWays:
    type: array
      items:
        enum:
        - "SMS"
          # type of each element on enum
            type: boolean
        - "EMAIL"
          # type of each element on enum
            type: boolean
        - "VOICE"
          # type of each element on enum
            type: boolean
        - "MAIL"
          # type of each element on enum
            type: boolean

But, obviously, this is incorrect . I’m just try to explain the structure with the code. I tried to find out in the official RAML documentation but I couldn’t see this example case, nor I couldn’t find anything on forum. Can you help me, please, with this kind of structure?


#2

Your first (JSON) example seems to indicate that you may be trying to model an array of objects while your second (RAML) example seems to indicate that you may be trying to model an array of strings. Let me cover both.

For the former, you can simply write:

types:
  communicationWays:
    type: array
    items:
      properties:
        SMS: boolean
        EMAIL: boolean
        VOICE: boolean
        MAIL: boolean

For the latter, you can use the “enum” facet in a type declaration:

types:
  communicationWays:
    type: array
    items: 
      enum: [SMS, EMAIL, VOICE, MAIL]

in which case the JSON could look something like:

{
  "communicationWays": ["EMAIL"]
}