Class WireMockStubScanner

java.lang.Object
com.arc_e_tect.gradle.mirage.scan.WireMockStubScanner

public class WireMockStubScanner extends Object
Scans WireMock stub mapping files (*.json) for the request each one stubs, treating every stubbed request as an implemented endpoint.

Stub files are data, not code - this is a plain line/regex scan, deliberately without a JSON parser or the WireMock library itself on the classpath. One file is expected to describe one stub, the common convention for files stored under a mappings directory: the first method field and the first url/urlPath/urlPattern/ urlPathPattern field found in the file are used.

urlPattern/urlPathPattern are WireMock regular expressions, not Spring/ OpenAPI path templates - see normalizePattern(String) for how a regex path-variable segment (e.g. "[0-9]+") is recognised and rewritten into the "{id}"-style placeholder a declared/implemented endpoint's path actually uses, so this scanner's stub evidence can be recognised as evidence for that endpoint instead of accumulating as a permanently unmatched, orphaned path in its own right.

url/urlPath are literal WireMock matchers, never regular expressions - but a purely numeric segment (e.g. "700336" in "/persons/700336") is, just as heuristically, rewritten into a "{id}" placeholder too, by normalizeLiteral(String): a hand-written literal stub overwhelmingly picks an arbitrary example value to stand in for a path variable, the same way normalizePattern(String) already treats a regular expression's own numeric-id shape. This is a deliberately imprecise heuristic, not a certainty, and it is not reversible for a specific stub - a genuinely numeric literal path segment that isn't a path variable at all (e.g. a year in a URL) is indistinguishable from an example id by shape alone, and is rewritten the same way, which then fails to match that segment's own, genuinely literal, declared/implemented path instead. See the plugin README's "Matching a stub's id segment to its declared/implemented endpoint's path variable" section for the accepted trade-off this represents.

  • Constructor Details

    • WireMockStubScanner

      public WireMockStubScanner()
      Creates a new WireMockStubScanner.
  • Method Details

    • scan

      public List<com.arc_e_tect.gradle.detector.core.model.Endpoint> scan(File rootDir) throws IOException
      Scans every .json file under rootDir, recursively, for the stubbed method and URL.
      Parameters:
      rootDir - directory to search; may not exist, in which case an empty list is returned
      Returns:
      one Endpoint per stub file that has both a recognised method and URL
      Throws:
      IOException - if a stub file cannot be read