Search code examples
groovyspring-cloud-contract

Spring Cloud Contract HTTP output body from file dynamically from request


It would be a nice and agile way to provide "test data" for mock server if it were possible to get a response file name from request dynamically. I wonder if someone could find some kind of workaround to implement something like :

import org.springframework.cloud.contract.spec.Contract

Contract.make {

    request {
        url "/one/two/three/response"
        method GET()
    }

    response {
        status OK()
        headers {
            contentType applicationJson()
        }
        body ( file( '' + $(consumer(fromRequest().path(3)), producer("response")) + '.json'))
    }
}

Or it just is not possible to determine output file dynamically from request?


Solution

  • You can't do such things unfortunately. You would have to create the body manually and its part should have references to fromRequest.