Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to define different example values for each array element in PactDslJsonArray #379

Closed
alonpeer opened this issue Feb 20, 2017 · 1 comment

Comments

@alonpeer
Copy link
Contributor

When I currently do:

val matchers = new PactDslJsonBody().minArrayLike("foo", 2)
  .stringMatcher("bar", "[a-z0-9]+", "abc")
  .integerType("baz", 666)
  .close()

The body for the example will have a foo array, with 2 identical examples: {"bar": "abc", "baz": 666}.

I'd like to be able to define multiple example values, e.g. like this:

val matchers = new PactDslJsonBody().minArrayLike("foo", 2)
  .stringMatcher("bar", "[a-z0-9]+", List("abc", "def"))
  .integerType("baz", List(666, 90210))
  .close()

So that I'll get a body similar to:

{
  "foo": [
    {"bar": "abc", "baz": 666},
    {"bar": "def", "baz": 90210}
  ]
}
@uglyog
Copy link
Member

uglyog commented Aug 1, 2021

I've updated the DSL to use multiple values with varargs:

PactDslJsonBody body = new PactDslJsonBody()
      .minArrayLike('foo', 2)
        .stringMatcher('bar', '[a-z0-9]+', 'abc', 'def')
        .integerType('baz', 666, 90210)
      .close()

This now generates:

{
    "foo": [
      {"bar":"abc","baz":666},
      {"bar":"def","baz":90210}
    ]
}

@uglyog uglyog closed this as completed Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants