mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Dynamic response files using Handlebars templating #174
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @denstorti on GitHub (May 3, 2019).
Hi,
I have a question about the current capabilities of templating.
I'd like to retrieve responses from files using WireMock.Net, and for that I am using static mappings with "BodyAsFile" attribute.
Example:
But I'd like to vary the response directory based on the request attributes, pretty much as Handlebars templates do.
Example (MyUniqueNumber would be the name of each folder):
In this example the variable is in the Path, but it could be appended to the file name as well.
I did test it and it seems the library tries to load the file from disk when loaded and not per request, so it cannot find the invalid path "c:\temp-wiremock\__admin\mappings\{{request.query.MyUniqueNumber}}\MyXmlResponse.xml".
Is this scenario currently supported (maybe in a different way)?
@StefH commented on GitHub (May 3, 2019):
This scenario is not yet supported, I'll take a look and modify the code.
@StefH commented on GitHub (May 3, 2019):
@denstorti
Can you try MyGet version WireMock.Net.1.0.15-ci-11270 ?
Note that you need to set
"UseTransformer": truein the mapping.@denstorti commented on GitHub (May 4, 2019):
@StefH, I could test it using the MyUniqueNumber as query string and also as JSON Path
Example using JSON Path
Input data (save as data.json):
Mapping:
curl test:
curl -d @data.json http://localhost:9091/postbodyasfileThank you!
@StefH commented on GitHub (May 4, 2019):
OK.
I will release a new NuGet today.
Note that instead of JsonPath, you can also use JmesPath as a matcher.
http://jmespath.org/
https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching#jmes-path-jmespathmatcher