10BC0 feat: admin API endpoints to find/remove unmatched stub mappings by MasonM · Pull Request #2991 · wiremock/wiremock · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@MasonM
Copy link
Contributor
@MasonM MasonM commented Mar 15, 2025

This integrates the functionality of https://github.com/MasonM/wiremock-unused-stubs-extension into WireMock proper, as requested in #615 (comment).

Specifically, it adds two endpoints:

References

Submitter checklist

  • Recommended: Join WireMock Slack to get any help in #help-contributing or a project-specific channel like #wiremock-java
  • The PR request is well described and justified, including the body and the references
  • The PR title represents the desired changelog entry
  • The repository's code style is followed (see the contributing guide)
  • Test coverage that demonstrates that the change works as expected
  • For new features, there's necessary documentation in this pull request or in a subsequent PR to wiremock.org

@MasonM MasonM force-pushed the remove-unused-mappings branch from 302e68d to 3ae35e7 Compare March 15, 2025 21:20
},
"after-pattern": {
"title": "Before datetime",
"title": "After datetime",
Copy link
Contributor Author
@MasonM MasonM Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change (and the rest of the changes in this file) are unrelated and the result of running cd ui && npm run swagger to regenerate this file, so I assume somebody forgot to do that. Probably should automate that as part of the build process.

This integrates the functionality of
https://github.com/MasonM/wiremock-unused-stubs-extension into WireMock
proper, as requested in wiremock#615 (comment).

Specifically, it adds two endpoints:
* `GET /__admin/mappings/unmatched` - Retrieve stub mappings that
  haven't matched any requests in the journal.
* `DELETE /__admin/mappings/unmatched` - Remove all such stub mappings.

  Note that the extension supports an additional `?remove_files=1` query
  parameter that I didn't include here because that introduces some
  additional complications:
  https://github.com/MasonM/wiremock-unused-stubs-extension/blob/424dfad1a21e25d588ac9230a46be820a579d7cf/src/main/java/com/github/masonm/wiremock/UnusedStubsAdminExtension.java#L71
  I added that feature because it was requested in
  MasonM/wiremock-unused-stubs-extension#1,
  though I haven't personally used it much, so I'm not sure if it's
  worth porting.

Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
@MasonM MasonM force-pushed the remove-unused-mappings branch from 3ae35e7 to 74c40ed Compare March 15, 2025 21:29
@MasonM MasonM marked this pull request as ready for review March 15, 2025 21:41
@MasonM MasonM requested a review from a team as a code owner March 15, 2025 21:41
}

@Test
void findUnmatchedStubMappingsWithNoMappings() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's probably best to split this up into separate test files for each endpoint or group (e.g. AdminApiMappingsTest, AdminApiRequestsTest, etc), since it's getting a bit hard to follow. I'm not sure where to put them, though. Maybe src/test/java/com/github/tomakehurst/wiremock/admin/acceptance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could do that as a separate refactor PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, but I don't know where to put these tests.

@leeturner leeturner self-assigned this Mar 18, 2025
@leeturner
Copy link
Contributor

This looks great. Would it be possible to add a docs PR to explain how to use the new endpoint and update the API reference here - https://wiremock.org/docs/standalone/admin-api-reference/

MasonM added a commit to MasonM/wiremock.org that referenced this pull request Apr 11, 2025
This documents the functionality in
wiremock/wiremock#2991, as requested by
@leeturner.

I wasn't able to get the dev environment running because of multiple different
errors. For example, `yarn` failed to install or compile `node-sass` for some
reason:
```console
$ yarn
yarn install v1.22.22
[1/5] Validating package.json...
[2/5] Resolving packages...
warning @redocly/cli > glob@7.2.3: Glob versions prior to v9 are no longer supported
[3/5] Fetching packages...
[4/5] Linking dependencies...
warning " > redoc@2.1.5" has unmet peer dependency "core-js@^3.1.4".
warning " > redoc@2.1.5" has unmet peer dependency "mobx@^6.0.4".
warning " > redoc@2.1.5" has unmet peer dependency "react@^16.8.4 || ^17.0.0 || ^18.0.0".
warning " > redoc@2.1.5" has unmet peer dependency "react-dom@^16.8.4 || ^17.0.0 || ^18.0.0".
warning " > redoc@2.1.5" has unmet peer dependency "styled-components@^4.1.1 || ^5.1.1 || ^6.0.5".
warning "redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "enzyme@^3.11.0".
warning "redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "react@>=18".
warning "redoc > @cfaester/enzyme-adapter-react-18@0.8.0" has unmet peer dependency "react-dom@>=18".
warning "redoc > mobx-react@9.1.1" has unmet peer dependency "mobx@^6.9.0".
warning "redoc > mobx-react@9.1.1" has unmet peer dependency "react@^16.8.0 || ^17 || ^18".
warning "redoc > react-tabs@6.0.2" has unmet peer dependency "react@^18.0.0".
warning "redoc > @cfaester/enzyme-adapter-react-18 > react-shallow-renderer@16.15.0" has unmet peer dependency "react@^16.0.0 || ^17.0.0 || ^18.0.0".
warning "redoc > mobx-react > mobx-react-lite@4.0.7" has unmet peer dependency "mobx@^6.9.0".
warning "redoc > mobx-react > mobx-react-lite@4.0.7" has unmet peer dependency "react@^16.8.0 || ^17 || ^18".
warning "redoc > mobx-react > mobx-react-lite > use-sync-external-store@1.2.2" has unmet peer dependency "react@^16.8.0 || ^17.0.0 || ^18.0.0".
warning "@redocly/cli > @redocly/respect-core > better-ajv-errors@1.2.0" has unmet peer dependency "ajv@4.11.8 - 8".
[5/5] Building fresh packages...
[1/4] ⡀ node-sass
[2/4] ⡀ core-js
[-/4] ⡀ waiting...
error /home/masonm/src/wiremock.org/node_modules/node-sass: Command failed.
Exit code: 1
Command: node scripts/build.js
Arguments:
Directory: /home/masonm/src/wiremock.org/node_modules/node-sass
Output:
Binary found at /home/masonm/src/wiremock.org/node_modules/node-sass/vendor/linux-x64-127/binding.node
Testing binary
Binary has a problem: Error: /home/masonm/src/wiremock.org/node_modules/node-sass/vendor/linux-x64-127/binding.node: file too short
    at Object..node (node:internal/modules/cjs/loader:1734:18)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:219:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:138:16)
    at module.exports (/home/masonm/src/wiremock.org/node_modules/node-sass/lib/binding.js:19:10)
    at Object.<anonymous> (/home/masonm/src/wiremock.org/node_modules/node-sass/lib/index.js:13:35)
    at Module._compile (node:internal/modules/cjs/loader:1565:14) {
  code: 'ERR_DLOPEN_FAILED'
}
Building the binary locally
Building: /home/masonm/.volta/tools/image/node/22.12.0/bin/node /home/masonm/src/wiremock.org/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
<SNIP THOUSANDS OF LINES OF COMPILER ERRORS>
```

Also, Jekyll gave a different error:
```console
$ bundle exec jekyll serve --config '_config.yml'

Configuration file: /home/masonm/src/wiremock.org/_config.yml
To use retry middleware with Faraday v2.0+, install `faraday-retry` gem
            Source: /home/masonm/src/wiremock.org
       Destination: /home/masonm/src/wiremock.org/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
       Jekyll Feed: Generating feed for posts
                    ------------------------------------------------
      Jekyll 4.3.2   Please append `--trace` to the `serve` command
                     for any additional information or backtrace.
                    ------------------------------------------------
/home/masonm/src/wiremock.org/vendor/bundle/ruby/3.2.0/gems/json-1.8.6/lib/json/common.rb:155:in `initialize': wrong number of arguments (given 2, expected 1) (ArgumentError)

    Parser.new(source, opts).parse
               ^^^^^^^^^^^^
        from /home/masonm/src/wiremock.org/vendor/bundle/ruby/3.2.0/gems/json-1.8.6/lib/json/common.rb:155:in `new'
        from /home/masonm/src/wiremock.org/vendor/bundle/ruby/3.2.0/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
```

I'm guessing the Jekyll error is because I'm on Ruby 3.2, and I don't have Ruby
2.7 installed. If there's a Docker container for this, I can try that, but I really
don't want to install more stuff on my host machine.

Signed-off-by: Mason Malone <651224+MasonM@users.noreply.github.com>
@MasonM
Copy link
Contributor Author
MasonM commented Apr 11, 2025

@leeturner Sure, done: wiremock/wiremock.org#351

@MasonM MasonM requested a review from leeturner April 11, 2025 02:36
@leeturner leeturner merged commit 4da8c0f into wiremock:master Apr 17, 2025
11 checks passed
@leeturner
Copy link
Contributor

Many thanks for your contribution

josetruta pushed a commit to grupo5-ES-2025-1/wiremock that referenced this pull request Aug 31, 2025
feat: admin API endpoints to find/remove unmatched stub mappings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a list with unused mappings

2 participants

0