2017-04-06 94 views
1

我有一個要求,我們必須將其中一個頭定義爲RAML 1.0中的一個數組。 它可以在任意點API平臺上正常工作。但是,我無法爲它提供輸入值。在RAML中定義數組

任何人都有類似的經驗,在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"} 
+0

你能舉一個你爲該頭文件定義的RAML片段的例子嗎? –

+0

#%RAML 1.0 基本URI:https://mocksvc.mulesoft.com/mocks/5b0f764c-844a-4a70-a188-d48a50bcc532 標題:ArrayTest中 版本:V1 類型: ARRAY1: 類型:對象 屬性: 名: 類型:字符串 /arraycheck: GET: 頭: 的x arraynos: 類型:陣列 項目:ARRAY1 響應: 200: 體: 應用/ JSON: 示例:{「AA 「:」aa「} –

回答

0

我由RAML 1.0 spec了這個例子。

這ilustrate你所遇到的問題:

#%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 
+0

讓我試試這個 –

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"}