Fixed the error when using optional() and anyOf() together
fixes gh-1215
This commit is contained in:
@@ -45,8 +45,16 @@ class OptionalProperty implements Serializable, CanBeDynamic {
|
||||
}
|
||||
|
||||
String value() {
|
||||
return this.value instanceof RegexProperty ?
|
||||
((RegexProperty) this.value).pattern.pattern() : this.value
|
||||
Object valueToCheck = valueToCheck()
|
||||
return (valueToCheck instanceof RegexProperty || valueToCheck instanceof Pattern) ?
|
||||
new RegexProperty(valueToCheck).pattern.pattern() : valueToCheck
|
||||
}
|
||||
|
||||
private Object valueToCheck() {
|
||||
if (this.value instanceof ClientDslProperty) {
|
||||
return ((ClientDslProperty) this.value).getClientValue()
|
||||
}
|
||||
return this.value
|
||||
}
|
||||
|
||||
protected Pattern optionalPatternValue() {
|
||||
|
||||
@@ -442,4 +442,23 @@ then:
|
||||
then:
|
||||
thrown(AssertionError)
|
||||
}
|
||||
|
||||
@Issue("1215")
|
||||
def 'should work fine when dealing with anyOf'() {
|
||||
when:
|
||||
Contract.make {
|
||||
request {
|
||||
method 'GET'
|
||||
url '/any'
|
||||
body (
|
||||
foo: $(consumer(optional(anyOf('WORKS','MIGHTY', 'DESPAIR'))), producer('DESPAIR'))
|
||||
)
|
||||
}
|
||||
response {
|
||||
status OK()
|
||||
}
|
||||
}
|
||||
then:
|
||||
noExceptionThrown()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user