Open
Conversation
Introduces PartialMockDecider for applying targeted modifications to response JSON using JSONPath queries and JSON Patch operations. Supports wildcard URL/method matching, template variable resolution, and all six RFC 6902 operation types. Includes comprehensive unit tests (38 tests) and updates README with feature documentation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
yusufozgul
approved these changes
Mar 2, 2026
| } | ||
|
|
||
| /// Context about the original HTTP request, passed through for template variable resolution. | ||
| struct RequestContext { |
Collaborator
There was a problem hiding this comment.
we can rename it for better meaning
|
|
||
| let liveResult = try await proxyRequest(request: request, mockDomain: flags.domain) | ||
| var liveResult = try await proxyRequest(request: request, mockDomain: flags.domain) | ||
| liveResult.body = await applyPartialMocks(to: liveResult.body, request: request, flags: flags) |
Collaborator
There was a problem hiding this comment.
should we save partial modified mock, or save as original?
|
|
||
| final class HandlePartialMock: HTTPHandler { | ||
| static var handler: PartialMockHandlerInterface? | ||
| private let jsonDecoder = JSONDecoder() |
Collaborator
There was a problem hiding this comment.
please use JSONDecoder.shared
| private let logger = Logger(category: "HandlePartialMock") | ||
|
|
||
| func handleRequest(_ request: HTTPRequest) async throws -> HTTPResponse { | ||
| logger.debug("New request handled") |
Collaborator
There was a problem hiding this comment.
it would be better add more context to this log. like path
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.
Add partial mock support with RFC 9535 JSONPath and RFC 6902 JSON Patch
Introduces PartialMockDecider for applying targeted modifications to response JSON using JSONPath queries and JSON Patch operations. Supports wildcard URL/method matching, template variable resolution, and all six RFC 6902 operation types.
Endpoint: /partial-mock
Route: /partial-mock
PUT /partial-mock — Add a partial mock
DELETE /partial-mock — Remove partial mocks
Example PUTS:
Matches all responses (wildcard url + method), finds every child under any marketing object at any depth, and injects the matched node's JSONPath, domain, and request path.
Replaces price and adds discountLabel inside $.product for product detail responses.
Adds "sponsored": true to every item in the results array.