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

PactDslJsonBody#eachKeyMappedToAnArrayLike does not work on "nested" property #401

Closed
flyinfish opened this issue Apr 10, 2017 · 19 comments
Closed

Comments

@flyinfish
Copy link

PactDslJsonBody#eachKeyMappedToAnArrayLike(exampleKey) works as expected on "level-0":

But if we move the same structure in a property "events" the verification fails:

  1. every property is validated against structure
    $.body.newFeature -> Expected ant=List(Map(title -> ant)) but was missing
  2. the validation ist not "by example" as expeted and working in first case but strict
    $.body.events -> Expected ant=List(Map(title -> ant)) but was missing
@flyinfish
Copy link
Author

Bug in V 3.3.7 and 3.5.0.beta3

@maxant
Copy link

maxant commented Apr 10, 2017

The problem with the "newFeature" attribute is that the consumer doesn't require it, but the pact fails when the provider runs it, since it seems to require that the attribute is mentioned in the pact.

@maxant
Copy link

maxant commented Apr 10, 2017

@flyinfish sorry, I think I broke your line numbers with my last commits :-(

@joelgithub
Copy link

Are there any planned fixes for this issue? It's really problematic for us as well.

@mboudreau
Copy link

@uglyog @mefellows @bethesque
Anyone have any insights for this? I can try to fix it myself, but I don't have enough context to make my effort efficient.

@bethesque
Copy link
Member

@uglyog will be able to help when he has time

@joelgithub
Copy link

Just for my own understanding, Is this a bug that has a fix within v.3 spec?

@uglyog
Copy link
Member

uglyog commented Mar 11, 2018

@joelgithub I added an item to the V4 WIP for this feature, but I don't think any of the other Pact implementations support it.

@mboudreau
Copy link

mboudreau commented Mar 11, 2018 via email

@uglyog
Copy link
Member

uglyog commented Mar 11, 2018

The problem is that this behaviour may have been introduced due to a workaround for #313, so in essence it would be a workaround for a workaround. It is also not a trivial problem to solve in a general way, hence the amount of time this issue has been open.

The best solution would be to make it explicit with a new type of matcher, but that would be specific to the JVM version and would not be supported with any other language. I'll going to try replicate the problem and see if I can work something out in the short term that does not make the matching logic worse.

@mboudreau
Copy link

mboudreau commented Mar 11, 2018 via email

@uglyog
Copy link
Member

uglyog commented Mar 11, 2018

Good news is that the root of this issue was in the Java DSL which was not generating the correct matchers. I have corrected this.

I am still going to implement the correct solution, which will be disabled behind a feature toggle.

@uglyog
Copy link
Member

uglyog commented Mar 19, 2018

3.5.14 has been released with the corrected DSL method

@joelgithub
Copy link

Thanks @uglyog ! Will verify if this fixes the problem.

@joelgithub
Copy link

I did a test and it seems to not verify the inner structure of the array objects.

This is my dsl:

dslBody
            .date("date", "yyyyMMdd'T'HHmmss")
            .stringMatcher("system", ".+", "systemname")
            .object("data")
            .eachKeyMappedToAnArrayLike("subsystem_name")
            .stringType("id","1234567")
            .closeArray()
            .closeObject()
        ;

And when running the provider test responding with:

{
  "date": "19880101T120101",
  "system_name": "s1",
  "data": {
    "sub": [
      {
        "hop":"san"
      }
    ]
  }
}

It passes without complaints. I expected it to fail on the missing "id" attribute of the array object.

This is the generated pact file:

{
    "provider": {
        "name": "provxxx"
    },
    "consumer": {
        "name": "consxxx"
    },
    "interactions": [
        {
            "description": "GET data for system",
            "request": {
                "method": "GET",
                "path": "/xxxx"
            },
            "response": {
                "status": 200,
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": {
                    "date": "20000131T140000",
                    "system": "systemname",
                    "data": {
                        "subsystem_name": [
                            {
                                "id": "1234567"
                            }
                        ]
                    }
                },
                "matchingRules": {
                    "header": {
                        "Content-Type": {
                            "matchers": [
                                {
                                    "match": "regex",
                                    "regex": ".*application/json.*"
                                }
                            ],
                            "combine": "AND"
                        }
                    },
                    "body": {
                        "$.date": {
                            "matchers": [
                                {
                                    "match": "date",
                                    "date": "yyyyMMdd'T'HHmmss"
                                }
                            ],
                            "combine": "AND"
                        },
                        "$.system": {
                            "matchers": [
                                {
                                    "match": "regex",
                                    "regex": ".+"
                                }
                            ],
                            "combine": "AND"
                        },
                        "$.data.*": {
                            "matchers": [
                                {
                                    "match": "type",
                                    "min": 0
                                }
                            ],
                            "combine": "AND"
                        },
                        "$.data.*[*].id": {
                            "matchers": [
                                {
                                    "match": "type"
                                }
                            ],
                            "combine": "AND"
                        }
                    }
                },
                "generators": {
                    "body": {
                        "$.date": {
                            "type": "Date",
                            "format": "yyyyMMdd'T'HHmmss"
                        }
                    }
                }
            },
            "providerStates": [
                {
                    "name": "That data exist"
                }
            ]
        }
    ],
    "metadata": {
        "pact-specification": {
            "version": "3.0.0"
        },
        "pact-jvm": {
            "version": "3.5.14"
        }
    }
}

@uglyog
Copy link
Member

uglyog commented Mar 22, 2018

Ok, will have a look using your example.

@rholshausen
Copy link
Contributor

/jira ticket

@github-actions
Copy link

👋 Thanks, Jira [PACT-593] ticket created.

@rholshausen
Copy link
Contributor

Closing this, as this functionality has been replaced with the Values matcher. Using the given DSL, the matching on the given provider response works as expected with the following errors:

$: Actual map is missing the following keys: system
$.data.sub.0: Actual map is missing the following keys: id

rholshausen added a commit that referenced this issue Jan 17, 2023
rholshausen added a commit that referenced this issue Jan 17, 2023
rholshausen added a commit that referenced this issue Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants