我正在使用YAML DSL编写spring-cloud-contracts,并遇到了以下问题。
我试图从我的响应主体中的请求中动态返回一个布尔值。当我将body设置为请求中的布尔值时,响应将以字符串的形式返回布尔值,而不是布尔值。在下面的示例中,有没有一种方法可以动态返回布尔值来获得我想要的响应?
合同示例:
name: POST foo
request:
method: POST
urlPath: /foo
body:
myBool: true
matchers:
body:
- path: $.myBool
type: by_regex
predefined: any_boolean
response:
status: 201
body:
myBool: "{{{ jsonpath this '$.myBool' }}}"期望的响应:
{
myBool: true
}实际响应
{
myBool: "true"
}发布于 2020-01-21 07:22:42
根据文档(https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/2.2.1.RELEASE/reference/html/project-features.html#yaml),您可以使用regexType提供类型,如下所示
- path: $.thing1
type: by_regex
value: thing2
regexType: as_string因此在您情况下,只需提供regexType: as_boolean
https://stackoverflow.com/questions/59831583
复制相似问题