Hey folks, I have a repeated field of a message ty...
# protobufs
s
Hey folks, I have a repeated field of a message type, ie strucutred. What's the right way to express that this field can have zero elements, or one, or many, but each matching the specific structure? According to https://github.com/pact-foundation/pact-plugins/blob/main/docs/matching-rule-definition-expressions.md, you can do
eachValue()
but that seems to work only for simple value fields. I'm currently doing smth like this, but this defines one element, and I'm not sure how to specify counts. @rholshausen you've added
atLeast
and
atMost
but I'm not sure where to put it, should it be just the element in the list? Thanks!
Copy code
{
  "availability_zones": [
    {
      "cloud_provider": "notEmpty('AWS')",
      "zone_name": "notEmpty('us-east-1a')"
    }
  ]
}
ah, shows my reading comprehension is lacking:
Copy code
The final form is a reference to another key. This is used to setup type matching using an example value, and is normally used for collections. The name of the key must be a string value in single quotes.

For example, to configure a type matcher where each value in a list must match the definition of a person:

{
  "pact:match": "eachValue(matching($'person'))",
  "person": {
    "name": "Fred",
    "age": 100
  }
}
so in this final form of matching syntax, is the field name looked up on the same level or across all of the proto? Like can I lookup the field in the parent or a child structure? e.g. with a proto similar to this, if I've already defined
config
field in my response, can I just refer to it from under the custom_config?
Copy code
message Config {}
message CustomConfig {
   Config config = 1;
   string whatever = 2;
}
message Response {
  Config config = 1;
  CustomConfig custom_config = 2;
}
r
atLeast
and
atMost
are currently a work in progress, and will be able with the next release of the protobuf plugin
so in this final form of matching syntax, is the field name looked up on the same level or across all of the proto?
It's defined on the same level
s
thank you!