Mule 4 - 如果传递未在 raml 中定义的有效负载请求参数,则 Return 错误
Mule 4 - Return error if passing payload request parameter that was not defined in the raml
只是想检查一下,如果用户传递了 api raml 中未定义的参数,是否可能 return 出错?例如,下面是我在 api raml
中定义的主体有效载荷结构
{
"test1": "value1",
"test2": "value2",
"test3": "value3"
}
如果用户传递了任何未在上面的主体有效负载结构中定义的参数,我想return出错,例如
{
"test1": "value1",
"test2": "value2",
"test3": "value3",
"4": "5"
}
供讨论的 RAML 样本
#%RAML 1.0
title: Sample API
version: 1.0
/users:
description: This is sample only
post:
body:
application/json:
example: |
{
"test1": "value1",
"test2": "value2",
"test3": "value3"
}
responses:
200:
body:
application/json:
example: |
{
"message":"This is for testing purposes"
}
首先您需要定义正文的类型。 JSON 模式也可能有效。示例不是模式,也不会用于验证输入。尽管在现代版本的 MuleSoft 产品中,该示例将得到验证。我对类型使用 additionalProperties: false
配置,因此验证会拒绝额外的属性。
示例:
#%RAML 1.0
title: Sample API
version: 1.0
types:
test_type:
additionalProperties: false
type: object
properties:
test1:
type: string
required: true
test2:
type: string
required: true
test3:
type: string
required: true
/users:
description: This is sample only
post:
body:
application/json:
type: test_type
example: |
{
"test1": "value1",
"test2": "value2",
"test3": "value3"
}
responses:
200:
body:
application/json:
example: |
{
"message":"This is for testing purposes"
}
只是想检查一下,如果用户传递了 api raml 中未定义的参数,是否可能 return 出错?例如,下面是我在 api raml
中定义的主体有效载荷结构{
"test1": "value1",
"test2": "value2",
"test3": "value3"
}
如果用户传递了任何未在上面的主体有效负载结构中定义的参数,我想return出错,例如
{
"test1": "value1",
"test2": "value2",
"test3": "value3",
"4": "5"
}
供讨论的 RAML 样本
#%RAML 1.0
title: Sample API
version: 1.0
/users:
description: This is sample only
post:
body:
application/json:
example: |
{
"test1": "value1",
"test2": "value2",
"test3": "value3"
}
responses:
200:
body:
application/json:
example: |
{
"message":"This is for testing purposes"
}
首先您需要定义正文的类型。 JSON 模式也可能有效。示例不是模式,也不会用于验证输入。尽管在现代版本的 MuleSoft 产品中,该示例将得到验证。我对类型使用 additionalProperties: false
配置,因此验证会拒绝额外的属性。
示例:
#%RAML 1.0
title: Sample API
version: 1.0
types:
test_type:
additionalProperties: false
type: object
properties:
test1:
type: string
required: true
test2:
type: string
required: true
test3:
type: string
required: true
/users:
description: This is sample only
post:
body:
application/json:
type: test_type
example: |
{
"test1": "value1",
"test2": "value2",
"test3": "value3"
}
responses:
200:
body:
application/json:
example: |
{
"message":"This is for testing purposes"
}