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

Array examples not accepting unnamed items #299

Closed
AlyGryf opened this issue Aug 4, 2016 · 3 comments
Closed

Array examples not accepting unnamed items #299

AlyGryf opened this issue Aug 4, 2016 · 3 comments

Comments

@AlyGryf
Copy link

AlyGryf commented Aug 4, 2016

I have a consumer pact body that includes GeoJSON e.g.
"coordinates": [ [ [ -7.55717, 49.766896 ], [ -7.557159, 49.766807 ] ] ]

A response could hold any number of coordinates so I want to use eachLike() or minArrayLike().
.object("geometry") .stringType("type") .array("coordinates") .array() .minArrayLike(0) .decimalType() //unsupported .decimalType() //unsupported .closeObject() .closeArray() .closeArray() .closeArray() .closeObject();

However, neither of these methods allows the use of unnamed example items, so the above insists on using decimalType(String) which GeoJSON does not provide. As I can use unnamed types outside these methods I don't see why I can't use them inside the eachLike/minArrayLike/maxArrayLike functions

As a work around I tried leaving the coordinates array empty for Postel's law, but I ran into this issue #298

@uglyog
Copy link
Member

uglyog commented Aug 6, 2016

I see your problem. I'll add a new set of methods to allow you to define arrays of arrays with the each/min/max matchers.

@uglyog
Copy link
Member

uglyog commented Aug 6, 2016

I added eachArrayLike methods and was able to replicate the GeoJSON structure with:

new PactDslJsonBody()
      .stringType('type', 'FeatureCollection')
      .eachLike('features')
        .stringType('type', 'Feature')
        .object('geometry')
          .stringType('type', 'Point')
          .eachArrayLike('coordinates')
            .decimalType(-7.55717)
            .decimalType(49.766896)
            .closeArray()
          .closeArray()
        .closeObject()
        .object('properties')
          .stringType('prop0', 'value0')
        .closeObject()
        .closeObject()
      .closeArray()

This generated the following JSON:

{
  "features": [
    {
      "geometry": {
        "coordinates": [[-7.55717, 49.766896]],
        "type": "Point"
      },
      "type": "Feature",
      "properties": { "prop0": "value0" }
    }
  ],
  "type": "FeatureCollection"
}

@AlyGryf
Copy link
Author

AlyGryf commented Aug 8, 2016

That's brilliant, thank you!

@uglyog uglyog closed this as completed Aug 20, 2016
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