Skip to content

Added feature to enable and disable mappings#1437

Merged
StefH merged 4 commits intowiremock:masterfrom
jayaraman-venkatesan:feat/1421
Apr 24, 2026
Merged

Added feature to enable and disable mappings#1437
StefH merged 4 commits intowiremock:masterfrom
jayaraman-venkatesan:feat/1421

Conversation

@jayaraman-venkatesan
Copy link
Copy Markdown
Contributor

@jayaraman-venkatesan jayaraman-venkatesan commented Apr 2, 2026

feat: add soft-disable support for mappings (#1421)

Summary

  • Introduces IsEnabled flag on mappings (defaults to true) that prevents a mapping from being matched without deleting it, preserving it for post-test inspection
  • Adds PUT /__admin/mappings/{guid}/enable and PUT /__admin/mappings/{guid}/disable admin endpoints
  • Adds EnableMappingAsync / DisableMappingAsync to IWireMockAdminApi typed client
  • IsEnabled: false can be set in POST/PUT mapping body and round-trips through GET /mappings and static mapping files
  • Disabled mappings appear in GET /mappings and server.Mappings — only request matching skips them

Changes

  • IRespondWithAProvider — new WithIsEnabled(bool) builder method (fluent, consistent with WithProbability / WithTitle)
  • RespondWithAProvider — stores _isEnabled, applies it during RespondWith()
  • WireMockServer.ConvertMapping — calls WithIsEnabled(false) when mappingModel.IsEnabled == false
  • MappingConverter.ToMappingModel — serializes IsEnabled as false only when disabled (null = enabled, sparse/backward-compatible)
  • WireMockServer.Admin — two new regex path matchers, two route registrations, MappingEnable / MappingDisable handlers, TryParseGuidFromSecondToLastSegment helper
  • MappingMatcherTests — fixed InitMappings helper and exception test mock to set IsEnabled = true (required after .Where(m => m.IsEnabled) was added); added WhenMappingIsDisabled_ShouldReturnNull test
  • WireMockAdminApiTests.IsEnabled — 4 integration tests covering create-disabled, disable endpoint, enable endpoint, GET serialization

Backward compatibility

  • IsEnabled defaults to true everywhere — existing mappings, JSON files, and API clients are unaffected
  • IsEnabled field is omitted from JSON when true (null) and only written when false

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

@jayaraman-venkatesan jayaraman-venkatesan marked this pull request as ready for review April 3, 2026 01:15
@StefH StefH changed the title feat/1421 added feature to enable and disable mappings Added feature to enable and disable mappings Apr 3, 2026
Comment thread test/WireMock.Net.Tests/WebSockets/WebSocketIntegrationTests.cs Outdated
Comment thread src/WireMock.Net.Abstractions/Admin/Mappings/MappingModel.cs Outdated
Comment thread src/WireMock.Net.Minimal/Owin/MappingMatcher.cs Outdated
@StefH StefH added the feature label Apr 3, 2026
@StefH
Copy link
Copy Markdown
Collaborator

StefH commented Apr 11, 2026

@jayaraman-venkatesan
Can you take a look at my comments?

@jayaraman-venkatesan
Copy link
Copy Markdown
Contributor Author

@StefH I have made all the suggested changes

@StefH
Copy link
Copy Markdown
Collaborator

StefH commented Apr 23, 2026

@jayaraman-venkatesan
One thing I was thinking about.
Technically it's possible to disable an Admin mapping?

@jayaraman-venkatesan
Copy link
Copy Markdown
Contributor Author

@StefH

The 2 APIs (/enable and /disable ) to trigger this action is guarded by IsAdminInterface check.
WithIsDisabled(true) builder is only used when constructing user mappings
I can see even the PUT api to update the mapping has the same check.

I dont think there are any more interfaces that can trigger this action. But please let me know if had missed something.

If needed, on top of this I can also add if .Where(m => m.IsAdminInterface || !m.IsDisabled) check in MappingMatcher.cs to ignore the flag.

@StefH
Copy link
Copy Markdown
Collaborator

StefH commented Apr 24, 2026

Ok. It's fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants