简体   繁体   English

我们可以将spring cloud contract请求/响应属性设为可选吗?

[英]can we make spring cloud contract request/response attribute optional?

I have a spring cloud contract(written in groovy dsl) which takes a object(Let's say Employee with 5 fields) as a request and updated object(Employee) back as a response. 我有一个spring cloud契约(用groovy dsl编写),它将一个对象(比方说有5个字段的Employee)作为请求,并将更新后的对象(Employee)作为响应。

Here scenario is all of 5 fields in Employee object is not mandatory. 这里的场景是Employee对象中的所有5个字段都不是必需的。 We can have any fields out of 5 fields in the request. 我们可以在请求中的5个字段中包含任何字段。

Is there a way to make those fields are optional in spring cloud contract? 有没有办法让这些字段在spring cloud合约中是可选的?

Note: email: $(consumer(optional(regex(email()))), producer('abc@abc.com')) does not work because it just makes value optional not field. 注意: email: $(consumer(optional(regex(email()))), producer('abc@abc.com'))不起作用,因为它只是使值可选而不是字段。

Any help will be appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

No you can't. 不,你不能。 You can make a value of a field optional. 您可以将字段的值设为可选。 If a field is optional then create two contracts. 如果字段是可选的,则创建两个合同。 One with the field and one without it. 一个与田地,一个没有它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM