Support for json arrays on root level of body.
See original GitHub issueWith 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:
- Created 8 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
I thought this was supported, but I can’t seem to find the implementation.