定义契约DSL以将JSON元素的计数从请求发送到响应

我已经为spring cloud合约测试定义了合约。我在请求正文中发送JSON,希望在响应'responseMsg‘中返回'keyValues’的计数。

我可以返回'requestedKeys‘中的'keyValues’,但无法获取计数。任何帮助都将不胜感激。

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


Contract.make {


    name("lockUnlockKeys")

    request {
        method(POST())
        url("/api/v1.0/license/lockunlockkeys")
        headers {
            header 'Content-Type': 'application/json'
        }
        body(
                [
                        "keyValues":
                                [
                                        "0048Q-0MK1N-38V8C-013KP-0NQ00",
                                        "00497-4MK17-38V82-0L28M-11Q24"
                                ],
                        "lockflag": matching(regex("[YN]{1}"))
                ]
        )
        bodyMatchers {
            jsonPath('$.keyValues', byType {
                minOccurrence(1)
            })
        }
    }
    response {
        status(200)
        body(
                [
                        "requestedKeyList": value(fromRequest().body('$.keyValues')),
                        "responseMsg": ?????????
                ]
        )
        headers {
            header 'Content-Type': 'application/json'
        }
    }
}

有什么建议可以代替“?”

转载请注明出处:http://www.cntdm.com/article/20230516/2011805.html