Search code examples
muleramlraml-1.0

RAML Max length of an item in a String array


I am defining a RAML spec. I have an attribute to hold an array of string. I want to make a rule that a string value in the array can have only maximum 3 charactors only (For example: regions: ["wes","nrh"] is valid. regions: ["lenghthyvalue", "anotherLenghthyvalue"] invalid). How can I handle it in RAML. My current code is as following:

regions:  
     type: string []
     required: true

Available attributes are maxItems only. How to limit the character length of an item ?

I use raml 1.0


Solution

  • First create a string type that has maxLength and minLength attributes. Then you can reference that type in your array type instead of just a string array. Example:

    #%RAML 1.0
    title: test
    version: 1.0
    types:
      region:
        type: string
        minLength: 3
        maxLength: 3
      regions:  
         type: region []
         required: true
    
    /test:
      get:
        queryParameters:
          regions: region