question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for json arrays on root level of body.

See original GitHub issue

With using the groovy pact consumer there is no way, when using the withBody() dsl & matchers, to declare a json array on the root body. While I’ve heard of this being a bad idea for API design, it should still be supported.

I’ve tried looking at JsonBuilder as an example, it can build a root level array in a few different ways, seen here and here, but they don’t feel like the right fit for the PactBodyBuilder, so I’ve come up with my own pretty basic solution.

It involves the keyword ‘rootJsonArray’ in the dsl.

withBody() {
  rootJsonArray maxLike(10) {
    id identifier
      lineItems minLike(1) {
        id identifier
          amount numeric
          productCodes eachLike { code string('A100') }
      }
  }
}

commit is here: 💥 stefan-lz/pact-jvm@7bd807fc689b35da0bf833d4a827e15d53938b4a

I was also toying around with the idea of something like another dsl method similar to maxLike/minLike.

withBody() {
  orders rootJsonArray maxLike(10) {
    id identifier
      lineItems minLike(1) {
        id identifier
          amount numeric
          productCodes eachLike { code string('A100') }
      }
  }
}

but failed to get anything working quickly.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
uglyogcommented, Mar 23, 2017

Found it, but it was only implemented for arrays on objects: https://github.com/DiUS/pact-jvm/issues/256#issuecomment-222295887

I’ll re-open that issue.

0reactions
uglyogcommented, Mar 23, 2017

I thought this was supported, but I can’t seem to find the implementation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support for json arrays on root level of body. #141 - GitHub
I've tried looking at JsonBuilder as an example, it can build a root level array in a few different ways, seen here and...
Read more >
Can an array be top-level JSON-text? - Stack Overflow
Yes, an array is legal as top-level JSON-text. There are four standard documents defining JSON: RFC 4627, RFC 7159 (which obsoletes RFC ...
Read more >
Creating a JSON message - IBM
You can create JSON message data that contains JSON objects, JSON arrays, or both, by creating elements in the logical message tree, under...
Read more >
Solve common issues with JSON in SQL Server
I want to produce complex JSON with several arrays on the same level. FOR JSON PATH can create nested objects using paths, and...
Read more >
array — Understanding JSON Schema 2020-12 documentation
To do this, we use the prefixItems keyword. prefixItems is an array, where each item is a schema that corresponds to each index...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found