如何以 Spring 云合同的 Yaml 格式指定可选请求参数?
How to specify optional request parameter in Yaml format of Spring Cloud Contracts?
我已将合同定义为
request:
method: "POST"
url: "/some/resource"
headers:
Content-Type: "application/json;charset=UTF-8"
body:
id: "id123"
desc: "Some description"
matchers:
body:
- path: "$.id"
type: "by_regex"
predefined: "non_blank"
response:
status: 200
headers:
Content-Type: "application/json"
body:
message: "Success"
我想让 desc
字段可选。
在 groovy dsl 语法中我可以定义为 desc: optional(regex(nonBlank()))
相同的 Yaml 是什么?
您不能将字段设为可选。您可以使给定键的值可选。所以 groovy 代码的作用是将正则表达式包装在 0 或 1 个出现值中。你可以在yaml
中自己写这样的表达式
我已将合同定义为
request:
method: "POST"
url: "/some/resource"
headers:
Content-Type: "application/json;charset=UTF-8"
body:
id: "id123"
desc: "Some description"
matchers:
body:
- path: "$.id"
type: "by_regex"
predefined: "non_blank"
response:
status: 200
headers:
Content-Type: "application/json"
body:
message: "Success"
我想让 desc
字段可选。
在 groovy dsl 语法中我可以定义为 desc: optional(regex(nonBlank()))
相同的 Yaml 是什么?
您不能将字段设为可选。您可以使给定键的值可选。所以 groovy 代码的作用是将正则表达式包装在 0 或 1 个出现值中。你可以在yaml
中自己写这样的表达式