Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pinguet62/wiremock-files-extension
Wiremock extension defining helpers for reusing files from the "__files" folder
https://github.com/pinguet62/wiremock-files-extension
Last synced: about 2 months ago
JSON representation
Wiremock extension defining helpers for reusing files from the "__files" folder
- Host: GitHub
- URL: https://github.com/pinguet62/wiremock-files-extension
- Owner: pinguet62
- License: apache-2.0
- Created: 2024-03-31T14:17:24.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-04-07T18:49:11.000Z (9 months ago)
- Last Synced: 2024-04-14T04:42:28.530Z (8 months ago)
- Language: Java
- Size: 78.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WireMock files extension
## Helpers
### `file-content`: include file from "__files" folder
Sample: `GET /person/42` will return content of file `/home/wiremock/__files/person-42.json`
```json
{
"request": {
"method": "GET",
"urlPattern": "/person/\\d+"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{{#assign 'filename'}}person-{{{request.pathSegments.1}}}.json{{/assign}} {{file-content filename}}"
}
}
```### `file-exists`: tests existence of file in "__files" folder
```json
{
"response": {
"body": "{{#assign 'filename'}}person-{{{request.pathSegments.1}}}.json{{/assign}} {{#if (file-exists filename)}} [...] {{/if}}"
}
}
```## Real use case
Build "get multiple" response dynamically from splitted unitary files:
```
[
{{#each (parseJson request.body) as |id|}}
{{#assign 'filename'}}subFolder/{{{id}}}.json{{/assign}}{{#if (file-exists filename)}}
{{file-content filename}}
{{/if}}{{#if @last}}{{else}},{{/if}}
{{/each}}
]
```## Installation
The extension
is [auto-loaded](https://wiremock.org/docs/extending-wiremock/#extension-registration-via-service-loading): just add JAR
to classpath.### Sample
```shell
wget https://.../wiremock-files-extension.jar
```Docker compose:
```yaml
services:
mocks:
image: wiremock/wiremock:3x
volumes:
- ./wiremock-files-extension.jar:/var/wiremock/extensions/wiremock-files-extension.jar
```