Importing WireMock mappings and MockServer expectations¶
FastMock converts WireMock 3.x stub mappings and MockServer 5.x expectations into native stubs. The result is an
ordinary stub you can read, edit and export; nothing of the source format is kept at run time. Parts that have no
safe equivalent are dropped and reported as warnings, never silently.
mappings is a WireMock document {"mappings": [...]}, an array of mappings or a single mapping. tag (default
wiremock) is added to every stub; replace (default true) deletes the stubs that already carry the tag first;
dryRun: true converts and validates without saving and returns the stubs. A mapping without request, or one
whose conversion would match more than the original (an unsupported sub-matcher of matchesJsonPath, an
unsupported JSONPath construct), is skipped with a warning that names it; the other mappings are imported. A
document that yields no stub at all is answered 400 and nothing is deleted or replaced (see
Common behaviour).
{"imported":12,"removed":12,"warnings":["mapping #4: customMatcher (Java extension) is not supported and was ignored"]}
Files referenced by bodyFileName are not part of the mapping: upload the __files directory with
PUT /__admin/files/{name} (see Body files) using the same relative names.
At equal priority the first mapping of a document wins and a later import wins over an earlier one, as with WireMock's POST /__admin/mappings/import; URL specificity is not used (Stub lifecycle).
equalTo (case-insensitive becomes an escaped (?is) regex)
contains, doesNotContain
contains, contains + negate
matches, doesNotMatch
matches, matches + negate
equalToJson with ignoreExtraElements, ignoreArrayOrder, ${json-unit.*} placeholders
equalToJson with the same options and placeholders; ignoreExtraElements also sets ignoreExtraArrayItems (extra array elements are allowed, as in WireMock)
matchesJsonPath (string or {expression, <matcher>})
The body is one expectation, an array of expectations (the format of MockServer's PUT /mockserver/expectation
and of its initialization JSON), or a wrapper {"expectations": [...], "tag": "legacy", "replace": true,
"dryRun": false}. Query parameters tag (default mockserver), replace (default true) and dryRun (default
false) override the wrapper. The response has the same shape as the WireMock import:
{"imported":0,"removed":0,"dryRun":true,"warnings":["expectation #2: JAVASCRIPT response templates are not executed; the expectation was skipped"],"stubs":[{"name":"GET /ping","priority":5,"times":1,"request":{"method":"GET","urlPath":"/ping"},"response":{"status":200,"body":"pong"}}]}
Requires the editor role; at most 10,000 expectations per request. Converted stubs that do not validate (for example
an invalid regular expression) are skipped with a warning; the rest are imported.
queryStringParameters, headers, cookies (object or [{name, values}] form)
query, headers, cookies
secure: true/false
scheme: https/http
keepAlive: true/false
connection header must not / must contain close
body
body, see below
Values: a value with regex characters matches either literally or as a regular expression (MockServer's rule); other
values match exactly. "!value" and {"not": true, "value": ...} become not. {"schema": {...}} uses pattern,
enum, or typeinteger/number/boolean and formatuuid/date; other schemas become a presence check with
a warning. Several values for one name become includes (all must be present, others allowed). With
"keyMatchStyle": "MATCHING_KEY" the values become allValues (every value of the key must match one of them). An
optional key "?name" becomes or: [absent, value]; a negated key "!name" becomes absent: true.
body
FastMock body matcher
a string
equalTo
a JSON object without type
equalToJson with ignoreExtraElements, ignoreExtraArrayItems and ignoreArrayOrder
STRING (subString)
equalTo (contains)
REGEX
matches
JSONONLY_MATCHING_FIELDS (default) / STRICT
equalToJson lenient (extra fields, extra array elements, any array order) / exact
JSON_SCHEMA
jsonSchema
JSON_PATH
jsonPath with jsonPathDialect: "jayway"
XML
equalToXml with exemptedComparisons: ["CHILD_NODELIST_SEQUENCE"] (child order does not matter, as in MockServer)
Templates with sections ({{#...}}, {{^...}}), other values, or tags outside JSON strings are skipped with a
warning; rewrite them as a FastMock stub with Handlebars helpers.
Imports are validated exactly like stubs created through POST /__admin/stubs; templates are compiled, regular
expressions are size-limited and XML/JSON limits apply (see Limits). A converted
stub that fails validation is skipped with a warning naming it (its name, or its id); the rest are imported.
A document that yields no valid stub (wrong structure such as {"mappings": 5}, a misspelled key, only skipped
mappings or expectations) is answered 400 {"error": "the document produced no stubs; nothing was changed; ..."}
with the first warnings, and the stubs of the tag stay as they were. Counted in
fastmock_import_rejections_total{format}.
dryRun returns the converted stubs without storing them, so you can review or adjust them and send them to
POST /__admin/stubs/import yourself.
Every import is audited (import.wiremock, import.mockserver) and counted in
fastmock_imports_total{format, dry_run}.
POST /__admin/import detects the format of a document automatically and calls the same converters.