我在mulesoft api设计器中使用的是RAML 1.0。
我想使用类型/属性来描述我的api响应,并启用mocking服务,这样我就可以运行api并返回示例响应。我想,如果我给该类型一个示例值,模拟服务将能够生成示例json响应。这是我的测试,raml
#%RAML 1.0
title: Test
baseUri: https://mocksvc.mulesoft.com/mocks/<removed>
types:
Email:
description: Email address
example: Steve@test.com
/user:
get:
responses:
200:
body:
application/json:
properties:
email: Email
当我通过模拟服务运行api时,我希望我的响应正文是这样的:
{
"email": "Steve@test.com"
}
但是该服务报告它没有任何信息,并在主体中返回以下内容
{
"message": "RAML had no response information for application/json"
}
发布于 2016-06-29 22:27:43
不,这将是一个很酷的功能,但它不是这样工作的。
您需要在响应中添加示例:
...
types:
Email:
description: Email address
/user:
get:
responses:
200:
body:
application/json:
properties:
email: Email
example: { "email": "Steve@test.com" }
发布于 2016-07-05 12:26:55
我们需要提供我们期望的示例类型,请检查此链接http://raml.org/developers/raml-200-tutorial
下面是在响应正文中添加的示例,在那里我们可以提供多个结果。
RAML 1.0 %
标题:测试baseUri:https://mocksvc.mulesoft.com/mocks/
类型:
电子邮件:描述:电子邮件地址示例: Steve@test.com
/user: get: responses: 200: body: application/json: properties: email: Email示例:"email“:{ "email”:"Steve@test.com"}
发布于 2017-10-03 18:05:54
RAML1.0中的Types标签功能更强大。您已经按照自己的习惯设计了自定义类型,并提高了代码的可信度
#%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
https://stackoverflow.com/questions/38090612
复制相似问题