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

Nested objects in interfaces/types are overwritten by last @pact-matcher used #58

Closed
pawfa opened this issue Feb 3, 2022 · 1 comment · Fixed by #60
Closed

Nested objects in interfaces/types are overwritten by last @pact-matcher used #58

pawfa opened this issue Feb 3, 2022 · 1 comment · Fixed by #60
Assignees
Labels
bug Something isn't working

Comments

@pawfa
Copy link
Member

pawfa commented Feb 3, 2022

When api function return type/interface contains nested object which itself contains one of the @pact-matcher - whole nested object in body in generated pact is replaced with the last pact-matcher defined. Example definitions and output:

export interface PactMatchersNestedType {
    nestedObject: {
        /** @pact-matcher hex */
        matcher?: string;
    }
}

/**
 * @pact
 * @pact-method GET
 * @pact-path /api
 */
export function apiNestedFunction(): PactMatchersNestedType {
    return {
        nestedObject: {}
    };
}

generated interaction looks like this:

      "description": "apiNestedFunction",
      "request": Object {
        "headers": Object {},
        "method": "GET",
        "path": "/api",
      },
      "response": Object {
        "body": Object {
          "nestedObject": "3F",
        },
        "headers": Object {},
        "matchingRules": Object {
          "$.body": Object {
            "match": "type",
          },
          "$.body.nestedObject": Object {
            "match": "regex",
            "regex": "^[0-9a-fA-F]+$",
          },
        },
        "status": 200,
      },

where as you can see nestedObject property inside body is replaced with hex from defined pact-matcher.

I've tested a few pact-matchers and this issue happens every time. If more than one pact-matcher is defined then the last one is used.
Marked property can be optional or required, nested object can contain additional optional or required properties not marked with any matcher - with all this cases same issue occurs.

Same issue happens for interface and TS type definition.

@pawfa pawfa added the bug Something isn't working label Feb 3, 2022
@pawfa pawfa self-assigned this Feb 5, 2022
@pawfa
Copy link
Member Author

pawfa commented Feb 5, 2022

I will work on that if you don't mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant