🐺
WireMockでネストしたRequestBodyのmatch
はじめに
wiremock
でネストしたRequestBody
に対してmatch
させる方法を探しました。
結論
wiremock
のmatchesJsonPath
でmatch
させる。
{
"request": {
...
"bodyPatterns" : [ {
"matchesJsonPath" : {
"expression": "$..todoItem",
"contains": "wash"
}
} ]
...
},
...
}
matchesJsonPath
は別のmatcherと組み合わせることが可能です。
部分文字列はJsonPath
とcontains
により実現しています。
expression
matchさせたいKey名をJsonPath
で指定する
JsonPath
指定
ネストした構造のvalueに対してmatchする
{
"depth1": [
{
"depth2": [
{
"depth3": [
{
"value": "hoge"
}
]
}
]
},
{
"depth2": [
{
"depth3": [
{
"value": "fuga"
}
]
}
]
}
]
}
matchesJsonPath
{
"request": {
...
"bodyPatterns": [{
"matchesJsonPath": {
"expression": "$..[?(@.value)]",
"contains": "hoge"
}
}]
...
}
...
}
JsonPath
構文は下記ドキュメントを参考にしています。
contains
Substring
(部分文字列)で評価される
Discussion