Adds support for mirroring mock responses. Closes #1384 - #1386
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for mirroring mock responses by allowing placeholder values in mock response bodies to be replaced with actual values from the incoming request body. The feature enables dynamic mock responses where values like @request.body.displayName in the mock configuration are replaced with the corresponding values from the request.
Key changes:
- Adds placeholder replacement functionality for mock response bodies using
@request.body.*syntax - Implements recursive JSON traversal to handle nested objects and arrays in mock responses
- Provides safe type conversion for various JSON value types (strings, numbers, booleans)
garrytrinder
approved these changes
Sep 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for mirroring mock responses. Closes #1384
Test:
devproxyrc.json
{ "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.1.0/rc.schema.json", "plugins": [ { "name": "GraphMockResponsePlugin", "enabled": true, "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll", "configSection": "mocksPlugin" } ], "urlsToWatch": [ "https://graph.microsoft.com/v1.0/users*" ], "mocksPlugin": { "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.1.0/mockresponseplugin.schema.json", "mocksFile": "mocks.json" }, "asSystemProxy": false }mocks.json
{ "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.1.0/mockresponseplugin.mocksfile.schema.json", "mocks": [ { "request": { "url": "https://graph.microsoft.com/v1.0/users", "method": "POST" }, "response": { "statusCode": 201, "body": { "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", "id": "12345678-1234-1234-1234-123456789abc", "businessPhones": "@request.body.businessPhones", "displayName": "@request.body.displayName", "givenName": "@request.body.givenName", "jobTitle": "@request.body.jobTitle", "mail": "@request.body.mail", "mobilePhone": "@request.body.mobilePhone", "officeLocation": "@request.body.officeLocation", "preferredLanguage": "@request.body.preferredLanguage", "surname": "@request.body.surname", "userPrincipalName": "@request.body.userPrincipalName", "accountEnabled": "@request.body.accountEnabled", "createdDateTime": "2024-01-15T10:30:00Z", "department": "@request.body.department", "companyName": "@request.body.companyName", "city": "@request.body.city", "country": "@request.body.country", "postalCode": "@request.body.postalCode", "state": "@request.body.state", "streetAddress": "@request.body.streetAddress", "usageLocation": "@request.body.usageLocation" }, "headers": [ { "name": "Content-Type", "value": "application/json; odata.metadata=minimal" }, { "name": "Location", "value": "https://graph.microsoft.com/v1.0/users/12345678-1234-1234-1234-123456789abc" }, { "name": "OData-Version", "value": "4.0" } ] } } ] }curl:
response: