Groovy 和 Spring 云合同 - bodyAsValue 中的变量

Groovy and Spring Cloud Contract - Variable in the bodyAsValue

我想知道如何在 Groovy 中创建具有随机值的 Json 负载。 例如

Contract.make {
    name"MyFirstContract"
    description "A description"

    request {
        method "POST"
        url "/api/team/createTeam"
        headers {
            contentType applicationJson()
            accept applicationJson()
            header"Authorization", execute('bearerOfAccessToken()')
        }
        body """ {
    "authenticatedUserCode":"papas",
    "input": {
        "name":"${execute('generateTeamUniqueName()')}",
        "teamDefinitionName":  "JUNIT TEST NAME",
        "context":"context AHO",
        "description":"team Description",
        "members":
           [
           {"role":"Junit Reviewer",
           "memberType":"USER",
           "reference":"papas"
           },
           {"role":"Junit Observer",
           "memberType":"USER",
           "reference":"papas"
           },
           {"role":"Junit Collaborator",
           "memberType":"USER",
           "reference":"papas"
           },
           {"role":"Junit Reviewer",
           "memberType":"USER",
           "reference":"papas"
           }
           ]     
    } } """
    }

前面代码的重要部分是以下在编译过程中失败的部分。

        "name":"${execute('generateTeamUniqueName()')}",

出现以下错误消息:

 Execution default-generateTests of goal org.springframework.cloud:spring-cloud-contract-maven-plugin:3.0.2:gener
ateTests failed: expecting '}' or ',' but got current char 'E' with an int value of 69

是否可以在正文中调用方法,或者我必须通过相同的方法 return 正文中的所有内容???

谢谢!

全身都要叫,局部不行