RAML multivalued form parameter

1.1k views Asked by At

I have been looking at the RAML spec trying to find how to represent a form parameter that can contain multiple values (like say "choices: [choice1, choice2, choice3]"). There's a "repeat" attribute in the spec, which is supposed to allow you to reuse a parameter name in a "post" definition (or any other http methods that accept request attributes), but the RAML api-designer (as of 06/08/2015) does not recognize "repeat" and flags it as an error. Has anyone found a way around this?

Example

Expected resource

{choices : ["Choice 1 rocks", "Choice 2 rocks"]}

This fails

post:
    description: create a resource
    body:
      application/x-www-form-urlencoded:
        formParameters:
          choices:
            displayName: Choice 1
            description: first choice
            type: string
            required: true
            repeat: true
            example: Choice 1 rocks!
          choices:
            displayName: Choice 2
            description: second choice
            type: string
            required: true
            repeat: true
            example: Choice 2 rocks!

This circumvents the problem if you choose to split the parameters

{
  choice1 : "Choice 1 rocks!",
  choice2 : "Choice 2 rocks!"
}


post:
    description: create a resource
    body:
      application/x-www-form-urlencoded:
        formParameters:
          choice1:
            displayName: Choice 1
            description: first choice
            type: string
            required: true
            example: Choice 1 rocks!
          choice2:
            displayName: Choice 2
            description: second choice
            type: string
            required: true
            example: Choice 2 rocks!
2

There are 2 answers

0
David Dossot On

In the first spec above, it does not make sense to have choices twice in the formParameters section. It's the same parameter: it must be listed only once, with repeat: true to mark it as a repeated parameter.

0
Hemin On

You can Define type of your choice as an array, By adding following,

type:String[]

This will define your resource as Array of String.

post:
    description: create a resource
    body:
      application/x-www-form-urlencoded:
        formParameters:
          choice1:
            displayName: Choice 1
            description: first choice
            type: string[]
            required: true
            example: Choice 1 rocks!
          choice2:
            displayName: Choice 2
            description: second choice
            type: string[]
            required: true
            example: Choice 2 rocks!