Pact Validation failed in case map is expected in request

Issue #171 new
Kumar Gaurav created an issue

Hello, I am getting validation error if a provider server expects a map of string and object in request, defined as:

private Map<String, Object> myMap;

Which in swagger spec can be seen as:

"myMap": {
          "type": "object"
 } 

And when my consumer sends following in pact mock request

"myMap":{"myKey":true}

I get error:

com.atlassian.oai.validator.pact.ValidatedPactProviderRule$PactValidationError: Validation failed.
[ERROR] [Path '/myMap'] Object instance has properties which are not allowed by the schema: ["myKey"]

    at com.atlassian.oai.validator.pact.ValidatedPactProviderRule.validatePactDef(ValidatedPactProviderRule.java:98)
    at com.atlassian.oai.validator.pact.ValidatedPactProviderRule.access$000(ValidatedPactProviderRule.java:27)

Can you please help what could be happening. Thanks a lot. (Please delete Issue #170, I was not logged in when creating that :) )

Comments (8)

  1. James Navin

    Hi Kumar,

    There's a couple things you can do here.

    The way to define an arbitrary map of String -> Object in swagger is:

    "myMap": {
      "type": "object",
      "additionalProperties": true
     } 
    

    If you add that to your spec you should stop getting the validation errors.

    Alternatively, if that's not an option for you you can ignore the additionalProperties validations (see the FAQ for examples on how to do that).

    Hope that helps.

    James

  2. James Navin

    Ah.

    In the 1.x branch the ValidatedPactProviderRule is missing the ability to pass in a configured validator, so you won't be able to use the whitelisting there. That has been fixed in 2.x. If you are able to upgrade I would recommend you try the latest 2.x release.

    If you can't upgrade, you could try setting validation.schema.additionalProperties=IGNORE in a swagger-validator.properties config file (see the section "Controlling Validation Behavior" in https://bitbucket.org/atlassian/swagger-request-validator/src/master/swagger-request-validator-core/README.md)

  3. Kumar Gaurav reporter

    Isn't 2.x supporting openAPI spec v3? If it is fully backward compatible and would work with spec v2 then I can think about upgrading. Would be better idea than using swagger-validator.properties.

  4. James Navin

    It is intended to be fully backwards compatible with v2 specs. If you upgrade and find a regression please raise a ticket.

    Cheers,

    James

  5. Log in to comment