Skip to content

Commit 80316b2

Browse files
committed
Merge remote-tracking branch 'origin/main' into live-publish
2 parents 7b32fcc + 1334214 commit 80316b2

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

_docs/request-matching.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ The full list of comparison types used by default is as follows:
11081108
`SCHEMA_LOCATION`
11091109
`NO_NAMESPACE_SCHEMA_LOCATION`
11101110
`NODE_TYPE`
1111+
`NAMESPACE_PREFIX`
11111112
`NAMESPACE_URI`
11121113
`TEXT_VALUE`
11131114
`PROCESSING_INSTRUCTION_TARGET`
@@ -1166,6 +1167,56 @@ and
11661167
</body>
11671168
```
11681169
If third argument is passed as `false` then first xml will not match the stub
1170+
1171+
#### Namespace awareness
1172+
1173+
To configure how [XML namespaces](https://www.w3schools.com/xml/xml_namespaces.asp) are handled, the
1174+
`namespaceAwareness` property can be set.
1175+
1176+
{% codetabs %}
1177+
1178+
{% codetab Java %}
1179+
```java
1180+
.withRequestBody(equalToXml("<body>" +
1181+
" <entry>1</entry>" +
1182+
" <entry>2</entry>" +
1183+
"</body>").withNamespaceAwareness(EqualToXmlPattern.NamespaceAwareness.STRICT))
1184+
```
1185+
{% endcodetab %}
1186+
1187+
{% codetab JSON %}
1188+
```json
1189+
{
1190+
"request": {
1191+
...
1192+
"bodyPatterns" : [ {
1193+
"equalToXml" : "<body><entry>1</entry><entry>2</entry></body>",
1194+
"namespaceAwareness": "STRICT"
1195+
} ]
1196+
...
1197+
},
1198+
...
1199+
}
1200+
```
1201+
{% endcodetab %}
1202+
1203+
{% endcodetabs %}
1204+
1205+
The available options for namespace awareness behaviour are `STRICT`, `NONE` and `LEGACY`.
1206+
1207+
`STRICT` adheres to strict XML namespace comparison.
1208+
Namespace prefixes must be bound to a namespace URI.
1209+
Namespace prefixes as well as namespace URIs must match (for both elements and attributes), unless explicitly excluded
1210+
by the `exemptedComparisons` parameter.
1211+
1212+
`NONE` does not consider XML namespaces when reading and comparing XML documents.
1213+
Namespace prefixes do not need to be bound to a namespace URI and are not considered a separate part of an
1214+
element/attribute name (i.e. the entire element/attribute name must match, not just the local name, regardless of
1215+
the `exemptedComparisons` parameter).
1216+
`xmlns` namespaced attributes are treated no differently to any other attribute.
1217+
1218+
`LEGACY` is not recommended and is only kept as an option for backwards compatibility.
1219+
11691220
### XPath
11701221

11711222
Deems a match if the attribute value is valid XML and matches the XPath expression supplied. An XML document will be considered to match if any elements are returned by the XPath evaluation. WireMock delegates to Java's in-built XPath engine (via XMLUnit), therefore up to (at least) Java 8 it supports XPath version 1.0.

_docs/response-templating.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,43 @@ Like the `jsonArrayAdd` helper, the second object can be provided as a block:
10821082

10831083
{% endraw %}
10841084

1085+
### Removing attributes
1086+
The `jsonMerge` helper has an optional `removeNulls` parameter which, when set to true will remove any attributes from the resulting JSON that
1087+
have null values in the second JSON document.
1088+
1089+
So for instance, given the following template:
1090+
1091+
{% raw %}
1092+
1093+
```handlebars
1094+
{{#assign 'object1'}}
1095+
{
1096+
"keepMe": 1,
1097+
"removeMe": 2
1098+
}
1099+
{{/assign}}
1100+
1101+
{{#jsonMerge object1 removeNulls=true}}
1102+
{
1103+
"removeMe": null
1104+
}
1105+
{{/jsonMerge}}
1106+
```
1107+
1108+
{% endraw %}
1109+
1110+
The resulting JSON would be:
1111+
1112+
{% raw %}
1113+
1114+
```json
1115+
{
1116+
"keepMe": 1
1117+
}
1118+
```
1119+
1120+
{% endraw %}
1121+
10851122
## Removing from a JSON Array or Object
10861123

10871124
The `jsonRemove` helper was introduced in WireMock `3.10.0` and allows you to remove an element from an existing json

0 commit comments

Comments
 (0)