I'm trying to validate/match a request body against a JSON schema with Wiremock. AFAIK, Wiremock does not have first class support for schema validation, but only supports JSONPath.
Unfortunately, I can't wrap my head around the correct JSON-Path expression which would match valid request bodies.
Let's assume, I've an endpoint where you can POST/PATCH book titles. The following request body should be matched:
{
"title": "Harry Potter and the Philosopher's Stone"
}
Easy with a JsonPath expression that looks for the title
property.
Request bodies with additional properties, however, should NOT be valid. I don't know in advance which or how many additional properties clients will be sending, but the following documents should - for example - not match:
{
"title": "Harry Potter and the Philosopher's Stone",
"isbn": "0-7475-3269-9"
}
{
"title": "Harry Potter and the Philosopher's Stone",
"isbn": "0-7475-3269-9",
"author": "J. K. Rowling"
}
{
"title": "Harry Potter and the Philosopher's Stone",
"xyz": "bla-bla-bla"
}
How should the JSON Path expression look like, so that only request bodies with only a title and nothing else are matched?
Or is there any other way apart from (misusing) JSONPath in Wiremock to achieve my goal?
WireMock uses Goessner's JSON-Path implementation under the hood, if that is of any significance