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

Is "min": 0 needed in matchers generated by Consumer PactDSL? (GroovyDSL doesn't use it) #1289

Closed
tlinkowski opened this issue Jan 20, 2021 · 2 comments

Comments

@tlinkowski
Copy link

tlinkowski commented Jan 20, 2021

Current status

Right now:

  • PactDSL generates an extra "min": 0 entry on calls to each*Like methods (source)
  • while GroovyDSL does no such thing (source)

Example:

  • Pact DSL: new PactDslJsonBody().eachLike("values", stringType("example")) generates
     "$.values": {
       "matchers": [{"match": "type", "min": 0}],
       "combine": "AND"
     }
     "$.values[*]": {
       "matchers": [{"match": "type"}],
       "combine": "AND"
     }
  • Groovy DSL: { values eachLike(string('example')) } generates
     "$.values": {
       "matchers": [{"match": "type"}],
       "combine": "AND"
     }
     "$.values[*]": {
       "matchers": [{"match": "type"}],
       "combine": "AND"
     }

Consequences

Apart from the obvious (and unintuitive) discrepancy between PactDSL and GroovyDSL, the main drawback is that Pact Broker does not render the content of such eachLikes when it renders them.

That is, instead of:

"values": [
  "example"
]

Pact broker renders:

"values": [
]

which makes the preview in Pact Broker very much useless 😞

Question

Can the following occurrences of matchMin(0) below be replaced with TypeMatcher.INSTANCE?

  1. matchers.addRule(matcherKey(name, rootPath), matchMin(0));
  2. matchers.addRule(matcherKey(name, rootPath), matchMin(0));
  3. matchers.addRule(matcherKey(name, rootPath), matchMin(0));
  4. matchers.addRule(rootPath + "*", matchMin(0));
  5. matchers.addRule(rootPath + appendArrayIndex(1), matchMin(0));
  6. matchers.addRule(rootPath + appendArrayIndex(1), matchMin(0));
  7. parent.matchers.addRule("", parent.matchMin(0));
  8. parent.matchers.addRule("", parent.matchMin(0));
  9. matchers.addRule(rootPath + appendArrayIndex(1), matchMin(0));
  10. matchers.addRule(rootPath + appendArrayIndex(1), matchMin(0));

Would you accept a PR with such a change?

@uglyog
Copy link
Member

uglyog commented Feb 10, 2021

PRs are always welcome, but in this case it was a small change so I just did it.

@uglyog
Copy link
Member

uglyog commented Feb 11, 2021

4.1.17 has been released

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