diff --git a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy index 863be3cf16..0ed877d86b 100644 --- a/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy +++ b/spring-cloud-contract-spec/src/main/groovy/org/springframework/cloud/contract/spec/internal/PatternValueDslProperty.groovy @@ -37,7 +37,7 @@ abstract class PatternValueDslProperty { if (!matches) { throw new IllegalStateException("The generated value [${generatedValue}] doesn't match the pattern [${pattern.pattern()}]") } - return createProperty(pattern, generatedValue) + return createProperty(pattern, object) } return createProperty(pattern, object) } diff --git a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategySpec.groovy b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategySpec.groovy index 3a047d25c3..61a94cdfd7 100644 --- a/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategySpec.groovy +++ b/spring-cloud-contract-verifier/src/test/groovy/org/springframework/cloud/contract/verifier/dsl/wiremock/WireMockResponseStubStrategySpec.groovy @@ -1,9 +1,12 @@ package org.springframework.cloud.contract.verifier.dsl.wiremock +import groovy.json.JsonSlurper import org.springframework.cloud.contract.spec.Contract +import spock.lang.Issue import spock.lang.Specification class WireMockResponseStubStrategySpec extends Specification { + def "should not quote floating point numbers"() { given: def irrelevantStatus = 200 @@ -23,4 +26,32 @@ class WireMockResponseStubStrategySpec extends Specification { then: '{"value":1.5}'.equals(content.body) } + + @Issue("#468") + def "should not quote generated numbers"() { + given: + def irrelevantStatus = 200 + def contract = Contract.make { + request { + } + response { + status irrelevantStatus + body([ + number: anyNumber(), + integer: anyInteger(), + positiveInt: anyPositiveInt(), + double: anyDouble(), + ]) + } + } + when: + def subject = new WireMockResponseStubStrategy(contract) + def content = subject.buildClientResponseContent() + then: + Map body = new JsonSlurper().parseText(content.body) as Map + assert body.get("number") instanceof Number + assert body.get("integer") instanceof Integer + assert body.get("positiveInt") instanceof Integer + assert body.get("double") instanceof BigDecimal + } }