Sorry if this is simple stuff, but I feel like I a...
# pact-jvm
d
Sorry if this is simple stuff, but I feel like I am doing something fundamentally wrong when writing my (first more complex) body matcher (with Kotlin Lambda DSL). I guess I am misunderstanding one of the methods and its syntax. Unfortunately, the doc only showed very simple examples when it comes to the Lambda DSL.
Copy code
body(newJsonObject {
    newArray("value_added_taxes") {
        eachLike {
            integerType("id")
            newArray("values") {
                decimalType("rate")
                datetime("valid_since") // "2020-04-15T17:30:00Z"
                datetime("valid_until") // "2020-06-15T17:30:00Z"
            }
        }
    }
})

https://i.imgur.com/mLhIT5Y.png

the generator creates this response (from the debug logger):

https://i.imgur.com/yNrfnCS.png

which is definitely not what I intended to get. i was more thinking of:
Copy code
{
  "value_added_taxes": [
    {
      "id": 0,
      "values": [
         "rate": 0.12,
         "valid_since": "2020-04-15T17:30:00Z",
         "valid_until": "2020-06-15T17:30:00Z"
      ]
    }
  ]
}
1
b
Sorry my reply is a bit late, I did just post a
datetime
example over in the other thread 🙂 it's a bit fiddly to get things working as DSL out of the gate, I mostly got those helpers from making them work manually, then extracting them out.
d
thanks for the datetime example. but what about the test? something in the DSL syntax must be terribly wrong, cause the generated json has a totally wrong structure
i just want a basic check that i get a json object that has an array where each array item has some entries. but somehow it moved all stuff into the top level in the generated json
nvm. i found the issue. 2 mistakes: 1.
eachLike
is already an array. so
Copy code
newArray("foo") {
  eachLike {
    ...
  }
}
should just be:
Copy code
eachLike("foo") {
  ...
}
and 2. i was mixing up all the implicit
this
and explicit `it`s, ultimately adding to the wrong object
👌 1