2016-06-29 31 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