在RAML中定义数组

时间:2017-04-06 18:33:01

标签: api mule raml

我有一个要求,我们必须在RAML 1.0中将其中一个头定义为数组。 它在任何点API平台上都能正常工作。但是,我无法为其提供输入值。

任何人都有在raml 1.0标头中定义数组的类似经验吗?

#%RAML 1.0
baseUri: https://mocksvc.mulesoft.com/mocks/5b0f764c-844a-4a70-a188-d48a50bcc532
title: arraytest
version: v1
types:
  array1:
    type: object
    properties: 
      name:
        type: string
/arraycheck:
  get:
    headers: 
      x-arraynos:
        type: array
        items: array1
    responses: 
      200:
        body: 
          application/json:
            example: {"aa":"aa"}

2 个答案:

答案 0 :(得分:0)

我通过RAML 1.0 spec得到了这个例子。

这说明了你遇到的问题:

#%RAML 1.0
title: Example with headers
traits:
  chargeable:
    headers:
      X-Dept:
        type: array
        description: |
          A department code to be charged.
          Multiple of such headers are allowed.
        items:
          pattern: ^\d+\-\w+$
          example: 230-OCTO
  traceable:
    headers:
      X-Tracker:
        description: A code to track API calls end to end
        pattern: ^\w{16}$
        example: abcdefghijklmnop
/users:
  get:
    is: [ chargeable, traceable ]
    description: |
      The HTTP interaction will look like

      GET /users HTTP/1.1
      X-Dept: 18-FINANCE
      X-Dept: 200-MISC
      X-Tracker: gfr456d03ygh38s2
    headers:
      X-Dept:
        example: [ 18-FINANCE, 200-MISC ]
      X-Tracker:
        example: gfr456d03ygh38s2

答案 1 :(得分:0)

您可以尝试以下优化的代码。

#%RAML 1.0
baseUri: https://mocksvc.mulesoft.com/mocks/5b0f764c-844a-4a70-a188-d48a50bcc532
title: arraytest
version: v1
types:
  array1:
    type: object
    properties:
      name:
        type: string[]
/arraycheck:
  get:
    headers:
      x-arraynos:
        type: array1
    responses:
      200:
        body:
          application/json:
            example: {"aa":"aa"}