2016-06-29 34 views
1

我在mulesoft api設計器中使用RAML 1.0。Raml 1.0類型與示例和mulesoft嘲笑服務

我想使用類型/屬性來描述我的api響應,並啓用模擬服務,以便我可以運行api並獲取示例響應。我想如果我給這個類型一個示例值,模擬服務將能夠生成示例json響應。這是我的測試錯構瘤

#%RAML 1.0 
title: Test 
baseUri: https://mocksvc.mulesoft.com/mocks/<removed> 

types: 

    Email: 
    description: Email address 
    example: [email protected] 

/user: 
    get: 
    responses: 
     200: 
     body: 
      application/json: 
      properties: 
       email: Email 

當我通過嘲諷服務運行的API,我希望我的迴應的身體是這樣的:

{ 
    "email": "[email protected]" 
} 

但服務報告說,它沒有任何信息,並返回此在身體

{ 
    "message": "RAML had no response information for application/json" 
} 

回答

1

不,這將是一個很酷的功能,但它不會這樣工作。

您需要添加在響應中的例子:

... 
types: 

    Email: 
    description: Email address 

/user: 
    get: 
    responses: 
     200: 
     body: 
      application/json: 
      properties: 
       email: Email 
      example: { "email": "[email protected]" } 
+0

我想用類型來表示我的數據庫表的取得名聲,和不同的API可以嵌套在一起超過一個表返回數據,如果我必須爲每個響應手動創建示例,然後對其中一個表進行更改,我必須手動編輯所有使用此表的apis的響應。 –

+0

如果您更改了表格,則必須更改示例以及類型。 但是,我明白你的觀點,包括嵌套類型的例子會很酷,你可以要求這個功能https://github.com/mulesoft/api-console – Pedro

+0

是的,但我只需要在一個地方更改類型和示例!如果有人感興趣,我已經打開了一個問題:https://github.com/mulesoft/api-console/issues/302 –

0

我們需要提供我們所期待的例子類型,檢查響應身體剛剛添加例如下面這個鏈接http://raml.org/developers/raml-200-tutorial

,還有我們可以提供多種結果。

%RAML 1.0

標題:測試 基本URI:https://mocksvc.mulesoft.com/mocks/

類型:

電子郵件: 描述:電子郵件地址 例如:[email protected]

/用戶: 得到: 迴應: 200: 身體: 應用/ JSON: 屬性: email:電子郵件 例如: 「電子郵件」:[{ 「電子郵件」: 「[email protected]」} ]在RAML

0

類型標籤1.0是更強大的。你必須設計您的自定義類型,每舒適性,還可以提高代碼

#%RAML 1.0 
title: Brochure 
version: v1 
baseUri: https://mocksvc.mulesoft.com/mocks/63063930-851d-41cc-b021-36d8a435d800 # baseUri: http://localhost:8080 
protocols: HTTP 
mediaType: application/json 
types: 
    ModelTree: 
    type: object 
    properties: 
     modelTreeReference: string 
     brand: string 
     series?: string 
     constructionSeries?: string 
     bodyType?: string 
     AGModelCode?: string 
     UKModelCode?: string 
     levelCode?: number 
    Brochure: 
    type: object 
    properties: 
     recordNumber: number 
     partNumber: number 
     name: string 
     brand: string 
     brochureType: string 
     CRMGroup: string 
     CRMSubGroup: string 
     isActiveIndicator: string 
     modelTree: ModelTree 
    Status: 
    type: object 
    properties: 
     responseStatus: 
     enum: [COMPLETE, ERROR, FATAL] 
     responseId: number 
    Transaction: 
    type: object 
    properties: 
     status: Status 
     data: 
     type: object 
     properties: 
      brochures?: Brochure[] 
/brochures: 
    get: 
    responses: 
     200: 
     description: Status and a list of Brochures 
     body: 
      application/json: 
      example: { 
       status: { 
       responseStatus: 'COMPLETE', 
       responseId: 123 
       }, 
       data: { 
       brochures: [{ 
        recordNumber: 1, 
        partNumber: 56, 
        name: "Activity Brochure", 
        brand: "My Brand Ltd", 
        brochureType: "HARDCOPY", 
        CRMGroup: "Sales", 
        CRMSubGroup: "Lifestyle/Access", 
        isActiveIndicator: "N", 
        modelTree: { 
         modelTreeReference: "My Brand", 
         brand: "My Brand Ltd", 
         levelCode: 1 
         } 
        } 
       ] 
       } 
       } 
      type: Transaction