ITV/scala-pact

Inconsistent parsing of Pact Links

Closed this issue ยท 3 comments

The Pact case class is defined as the following:

case class Pact(
    ...
    _links: Option[Links],
    ...
)

type Links = Map[String, LinkValues]

case class LinkValues(title: Option[String], name: Option[String], href: String, templated: Option[Boolean])

This does not match the actual response of Pact Broker where sometimes a link is actually an array.

Example of JSON not matching the case class:

"_links": {
    "pb:consumer-version": {
      "title": "Consumer version",
      "name": "1.4.3.x",
      "href": "http://pact-broker.mycompany.com:9292/pacticipants/my-consumer/versions/1.4.3.x"
    },
    "pb:consumer-versions": [
      {
        "title": "Consumer version",
        "name": "1.4.3.x",
        "href": "http://pact-broker.mycompany.com:9292/pacticipants/my-consumer/versions/1.4.3.x"
      }
    ]
}

This results in a response from Pact Broker being unparseable and unable to use.

Context: trying to use verifyPact.withPactSource(pactBrokerWithVersionSelectors(...))

Am I missing something?

I am also seeing the same problem where an array link makes the contract indecipherable, resulting in pipeline failures from the pact verification step.

This is a critical blocker for our pipelines. I've done some debugging and it seems that the pb:consumer-versions array-type field was only very recently added to the response from the broker.

I've raised a PR to remove this field from _links when decoding the pact, which should provide an interim solution to the problem until the Links type can be updated to correctly support both single-valued and multi-valued links: #233

More info/discussion on the Pact foundation slack: https://pact-foundation.slack.com/archives/CLS16AVEE/p1635324284042200

thanks @jbwheatley - can confirm this is fixed by v4.3.0! ๐Ÿ˜„