thoughtworks / pacto

Pacto settles disputes between JSON providers and consumers
thoughtworks.github.io/pacto
MIT License
400 stars 58 forks source link

Generation: record examples #121

Open maxlinc opened 10 years ago

maxlinc commented 10 years ago

There should at least be an option for recording samples while generating contracts. Especially since JSON::Generator-based stubbing only supports json-schema draft3 (https://github.com/thoughtworks/pacto/issues/10), but generation and example-based stubbing supports draft3 or draft4.

maxlinc commented 10 years ago

Oh, just had an awesome idea :)

I will probably hook it up so there's three choices for recording examples:

I think "structurally_distinct" is the most interesting and should be the default behavior. Consider how it works for a service like Get Server Details where you're polling a resource as it builds.

If you record and stub with:

You could achieve similar results with by explicitly tracking state, which can often be linked to a field ("status" in this case) or calculated via a callback. That'd have the advantage of working if the structure doesn't change but the nature of the data does (e.g. IP address changes from "" to a real IP). However, since that's more complex I'll likely leave it for a future enhancement.

maxlinc commented 10 years ago

Right now only the first example is being recorded. This is probably good enough for v4.0.0 but could be improved within v4.x.x. It might be worth postponing the "structurally_distinct" idea until the contract format is settled.