This is an extension for the pact DSL provided by consumer. The difference between
the default pact DSL and this lambda DSL is, as the name suggests, the usage of lambdas. The use of lambdas makes the code much cleaner.
Methods may only be called in certain states. For example object() may only be called when you're currently working on an array whereas object(name)
is only allowed to be called when working on an object. But both of the methods are available. You'll find out at runtime if you're using the correct method.
Finally, the need for opening and closing objects and arrays makes usage cumbersome.
The lambda DSL has no ambiguous methods and there's no need to close objects and arrays as all the work on such an object is wrapped in a lamda call.
When formatting your source code with an IDE the code becomes hard to read as there's no indentation possible. Of course, you could do it by hand but we want auto formatting!
Auto formatting works great for the new DSL!
array.object((o)->{
o.stringValue("foo","Foo"); # an attribute
o.stringValue("bar","Bar"); # an attribute
o.object("tar",(tarObject)->{ # an attribute with a nested object
tarObject.stringValue("a","A"); # attribute of the nested object
tarObject.stringValue("b","B"); # attribute of the nested object
Start with a static import of LambdaDsl. This class contains factory methods for the lambda dsl extension.
When you come accross the body() method of PactDslWithProvider builder start using the new extensions.
The call to LambdaDsl replaces the call to instance new PactDslJsonArray() and new PactDslJsonBody() of the pact library.