Skip to content

Commit

Permalink
Added JSON schema request matching doc section
Browse files Browse the repository at this point in the history
  • Loading branch information
tomakehurst committed Dec 11, 2023
1 parent 2087eba commit 9c704ea
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions _docs/request-matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,53 @@ JSON:
}
```

### JSON schema

Deems a match if the value conforms to the expected JSON schema.

By default the [V202012](https://json-schema.org/draft/2020-12/schema){:target="{{site.data.misc.blank}}"} version of the JSON schema spec will be used, but this can be changed to one of `V4`, `V6`, `V7`, `V201909`, `V202012` via the `schemaVersion` parameter.

Java:

```java
stubFor(
post(urlPathEqualTo("/schema-match"))
.withRequestBody(matchingJsonSchema("{\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"name\"\n" +
" ],\n" +
" \"properties\": {\n" +
" \"name\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"tag\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" }\n" +
"}"))
.willReturn(ok()));
```

JSON:

```json
{
"request" : {
"urlPath" : "/schema-match",
"method" : "POST",
"bodyPatterns" : [ {
"matchesJsonSchema" : "{\n \"type\": \"object\",\n \"required\": [\n \"name\"\n ],\n \"properties\": {\n \"name\": {\n \"type\": \"string\"\n },\n \"tag\": {\n \"type\": \"string\"\n }\n }\n}",
"schemaVersion" : "V202012"
} ]
},
"response" : {
"status" : 200
}
}
```


### XML equality

Deems a match if the attribute value is valid XML and is semantically equal to the expected XML document. The underlying engine for determining XML equality is [XMLUnit](http://www.xmlunit.org/).
Expand Down

0 comments on commit 9c704ea

Please sign in to comment.