Search code examples
springspring-cloudspring-cloud-contract

Reference regex string In JSON response


How to reference regex string In the JSON response

url value(consumer(regex('/connectors/(.*?)/status')))

So that if I request '/connectors/foo/status' I get { "name": "foo" }


Solution

  • Please read the docs - https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/project-features.html#contract-dsl-referencing-request-from-response

    You'd need to do

    response {
      body(name: fromRequest().path(1))
    }