Skip to content

Added feature to enable and disable mappings#1437

Open
jayaraman-venkatesan wants to merge 3 commits intowiremock:masterfrom
jayaraman-venkatesan:feat/1421
Open

Added feature to enable and disable mappings#1437
jayaraman-venkatesan wants to merge 3 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
…tion that is causing upstream connection from proxy to teardown prematurely before test ends
@StefH StefH changed the title feat/1421 added feature to enable and disable mappings Added feature to enable and disable mappings Apr 3, 2026
await Task.Delay(500, _ct);

// Assert
// Assert immediately — receivedData is already in memory, no delay needed.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change looks good, however can you remove this change in this PR?

I'll make a new PR which I use to fix these failing tests.

/// <summary>
/// Value to determing if the mapping is active
/// </summary>
public bool? IsEnabled { get; set; }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's better to make the functionality the other way around.

So

public bool IsDisabled { get; set; }

In this way,it's backwards compatible.

var possibleMappings = new List<MappingMatcherResult>();

var mappings = _options.Mappings.Values
.Where(m=>m.IsEnabled)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do a format-file, so that the code is alligned (extra spaces)

@StefH StefH added the feature label Apr 3, 2026
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