Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.
This repository was archived by the owner on Jul 7, 2026. It is now read-only.

Usage of MatchingRules for response header #583

Closed

Description

@farshidkeshavarz

I am using a PACT file of type JSON to test my API. I want to assert the value of a response header which is returned by my API. The value of the response header is an UUID automatically generated on every call. Hence, I need to use matchingRules with regex.

My Pact File:

{
  "metadata": {
    "pact-specification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "3.5.4"
    }
  },
  "interactions": [
    {
      "description": "some description",
      "request": {
        "method": "POST",
        "path": "/v1/accounts",
        "body": {
          "nickname": "Nickname"
        },
        "headers": {
          "Accept": "application/json",
          "Content-Type": "application/json;charset=UTF-8"
        }
      },
      "response": {
        "status": 201,
        "headers": {
          "Content-Type": "application/vnd.fraud.v1+json;charset=UTF-8"
        },
        "body": {
          "nickname": "Nickname"
        },
        "matchingRules": {
          "$.header.something": {
            "match": "regex",
            "regex": "[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9].*"
          },
          "$.body.createdDate": {
            "match": "regex",
            "regex": "[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9].*"
          }
        }
      }
    }
  ]
}

My maven config:

<plugin>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-contract-maven-plugin</artifactId>
                <version>1.2.1.RELEASE</version>
                <extensions>true</extensions>
                <configuration>
                    <packageWithBaseClasses>com.example.contract</packageWithBaseClasses>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.cloud</groupId>
                        <artifactId>spring-cloud-contract-spec-pact</artifactId>
                        <version>1.2.2.RELEASE</version>
                    </dependency>
                    <dependency>
                        <groupId>au.com.dius</groupId>
                        <artifactId>pact-jvm-model</artifactId>
                        <version>2.4.18</version>
                    </dependency>
                </dependencies>
            </plugin>

The generated Java class file does not assert the header with regex.

Activity

  1. marcingrzejszczak commented on Mar 21, 2018

    @marcingrzejszczak
    Contributor

    We're not planning on adding it to the 1.2.x branch. This feature will be added via this PR #569

  2. added a commit that references this issue on Apr 2, 2018
    de529e2
  3. added this to the 2.0.0.RC1 milestone on Apr 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions