2015-06-09 37 views
1

我一直在寻找RAML规范试图找到如何表示一个可以包含多个值的表单参数(如说“选择:[choice1,choice2,choice3]”)。规范中有一个“repeat”属性,它可以让你在“post”定义中重用参数名称(或任何其他接受请求属性的http方法),但RAML API设计器(截至06/08/2015)不识别“重复”并将其标记为错误。有没有人找到解决这个问题的方法?RAML多值表单参数

预计资源

{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! 

回答

0

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

0

你可以定义你所选择的类型的数组,通过添加以下内容,

类型:字符串[]

这将定义你的资源作为字符串数组。

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!