Describe the bug
It looks like mappings for GRPC call are not created correctly when created through __admin/mappings endpoint. It doesn't matter if we register proto at server level or pass its content to mapping response and request, directly. Created mapping miss some parts which causes requests to fail (returning 404 status code).
When proto is registered at server level following parts are not created despite the fact they are included in the JSON request for creating mappings:
- Mapping.ProtoDefinition
- Response.TrailingHeaders
- Response.ProtoBufMessageType
When proto is passed as text directly (for request and response) following parts are not created despite the fact they are included in the JSON request for creating mappings:
- Response.ProtoDefinition
- Response.TrailingHeaders
- Response.ProtoBufMessageType
Expected behavior:
Above parts of the mapping are created thus mapping works correctly and the same way as if they were created through code at server start.
Test to reproduce
Start server with below code, register attached proto, don't add any mappings, e.g.:
var urlGrpc = "grpc://*:9093/";
var urlGrpcSecure = "grpcs://*:9094/";
var urlHttp = "http://*:80/";
var urlHttpSecure = "https://*:443/";
WireMockServerSettings settings = new WireMockServerSettings
{
UseHttp2 = true,
Urls = [urlGrpc, urlGrpcSecure, urlHttp, urlHttpSecure],
Logger = new WireMockConsoleLogger(),
StartAdminInterface = true
};
_server = WireMockServer.Start(settings);
string protosFolder = args[0];
string[] filePaths = Directory.GetFiles(protosFolder);
foreach (string filePath in filePaths)
{
_server.AddProtoDefinition(Path.GetFileNameWithoutExtension(filePath), File.ReadAllText(filePath));
}
Console.Out.WriteLine($"{DateTime.UtcNow} Press Ctrl+C to shut down");
Proto definition:
syntax = "proto3";
package greet;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply);
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
Register following mapping through __admin/mappings endpoint:
[
{
"Guid": "3c16e119-fe92-43cf-a006-260514569e06",
"UpdatedAt": "2025-01-08T11:50:01.3475097Z",
"Request": {
"Methods": [
"POST"
],
"Body": {
"Matcher": {
"Name": "ProtoBufMatcher",
"ProtoBufMessageType": "greet.HelloRequest"
}
}
},
"Response": {
"BodyAsJson": {
"message": "hello {{request.BodyAsJson.name}} {{request.method}}"
},
"UseTransformer": true,
"TransformerType": "Handlebars",
"TransformerReplaceNodeOptions": "EvaluateAndTryToConvert",
"Headers": {
"Content-Type": "application/grpc"
},
"TrailingHeaders": {
"grpc-status": "0"
},
"ProtoBufMessageType": "greet.HelloReply"
},
"ProtoDefinition": "greet"
}
]
Inspect mapping using __admin/mappings endpoint for missing parts of the mapping.
Sample code to get server working correctly (i.e. return proper response to client):
_server
.Given(Request.Create()
.UsingPost()
.WithBodyAsProtoBuf("greet.HelloRequest")
.WithProtoDefinition("greet")
.RespondWith(Response.Create()
.WithHeader("Content-Type", "application/grpc")
.WithTrailingHeader("grpc-status", "0")
.WithBodyAsProtoBuf("greet.HelloReply", new { message = "hello {{request.BodyAsJson.name}} {{request.method}}" })
.WithBodyAsProtoBuf(File.ReadAllText(filePaths.Where(x => Path.GetFileNameWithoutExtension(x).Equals("greet")).First()), "greet.HelloReply", new { message = "hello {{request.BodyAsJson.name}} {{request.method}}" })
.WithTransformer());
__admin/mappings endpoint may be used to obtain JSON mappings, posted earlier in this post.
Other related info
In case there is any problem with the approach I take, or maybe there is some specific convention required in terms of JSON mapping I tried I am more than happy to be corrected.
Describe the bug
It looks like mappings for GRPC call are not created correctly when created through __admin/mappings endpoint. It doesn't matter if we register proto at server level or pass its content to mapping response and request, directly. Created mapping miss some parts which causes requests to fail (returning 404 status code).
When proto is registered at server level following parts are not created despite the fact they are included in the JSON request for creating mappings:
When proto is passed as text directly (for request and response) following parts are not created despite the fact they are included in the JSON request for creating mappings:
Expected behavior:
Above parts of the mapping are created thus mapping works correctly and the same way as if they were created through code at server start.
Test to reproduce
Start server with below code, register attached proto, don't add any mappings, e.g.:
Proto definition:
Register following mapping through __admin/mappings endpoint:
[ { "Guid": "3c16e119-fe92-43cf-a006-260514569e06", "UpdatedAt": "2025-01-08T11:50:01.3475097Z", "Request": { "Methods": [ "POST" ], "Body": { "Matcher": { "Name": "ProtoBufMatcher", "ProtoBufMessageType": "greet.HelloRequest" } } }, "Response": { "BodyAsJson": { "message": "hello {{request.BodyAsJson.name}} {{request.method}}" }, "UseTransformer": true, "TransformerType": "Handlebars", "TransformerReplaceNodeOptions": "EvaluateAndTryToConvert", "Headers": { "Content-Type": "application/grpc" }, "TrailingHeaders": { "grpc-status": "0" }, "ProtoBufMessageType": "greet.HelloReply" }, "ProtoDefinition": "greet" } ]Inspect mapping using __admin/mappings endpoint for missing parts of the mapping.
Sample code to get server working correctly (i.e. return proper response to client):
__admin/mappings endpoint may be used to obtain JSON mappings, posted earlier in this post.
Other related info
In case there is any problem with the approach I take, or maybe there is some specific convention required in terms of JSON mapping I tried I am more than happy to be corrected.