RAML多值表单参数

时间:2015-06-09 03:37:49

标签: api rest raml

我一直在研究RAML规范,试图找到如何表示可以包含多个值的表单参数(比如说"选择:[choice1,choice2,choice3]")。有一个"重复"规范中的属性,它应该允许您在" post"中重用参数名称。定义(或接受请求属性的任何其他http方法),但RAML api-designer(截至2015年8月6日)无法识别"重复"并将其标记为错误。有没有人找到解决方法?

实施例

预期资源

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

这失败

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!

如果您选择拆分参数

,这可以解决问题
{
  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 个答案:

答案 0 :(得分:0)

在上面的第一个规范中,choices部分中formParameters两次没有意义。它是相同的参数:它必须只列出一次,repeat: true将其标记为重复参数。

答案 1 :(得分:0)

您可以将您选择的类型定义为数组,通过添加以下内容,

  

类型:字符串[]

这会将您的资源定义为String 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!