- edited description
- changed title to Pact Validation failed in case map is expected in request
Pact Validation failed in case map is expected in request
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)
-
reporter -
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
-
Issue
#170was marked as a duplicate of this issue. -
reporter Thanks @jnavin for the hint.. I tried whitelisting this error using guide: https://bitbucket.org/atlassian/swagger-request-validator/src/4ab287ab02aaaec074918c9775b93d566d4f99c2/swagger-request-validator-core/README.md. Created a whitelist object but can't use that with
ValidatedPactProviderRule
. Not sure how to pass whitelist object to validator. Can you pls give a hint. I am using version 1.5.0.Thanks, Kumar
-
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 aswagger-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) -
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.
-
It is intended to be fully backwards compatible with v2 specs. If you upgrade and find a regression please raise a ticket.
Cheers,
James
-
reporter Thanks. Raised a ticket:
#172 - Log in to comment