How to define a Map type property wich may contain any number of key-values


#1

Hi,
I am novice to RAML, try to write specification for an api. I am having issue in designing response body for an object which contains a property (Map type collection) to hold any number of keys and values. Please help me. In attached picture, there is property “collections” inside “adhocMetaData” object. This “collections” property may get any number of key-value pairs on different requests. How can define this propery while writting responsebody example in raml. Somebody please help me


#2

Can you share your RAML?


#3

I believe you can use regex as property keys.

#%RAML 1.0 DataType
properties:
  /(\d+)x(\d+)/:
    type: string
description: key -> dimension, value -> image url

Above data type will allow examples like below.

{
  "110x110": "https://alpha-kcdn.net/dn/bgqKmP/ZSc0LE9UE0/5AVWhCbeJiIdb8dCObepH1/profile_110x110c.png",
  "640x640": "https://alpha-kcdn.net/dn/bgqKmP/ZSc0LE9UE0/5AVWhCbeJiIdb8dCObepH1/profile_640x640s.png"
}

Or you could set additionalProperties to true to pass any example validation and use description node for describing its structure.