Updated Request Matching ProtoBuf (markdown)

Stef Heyenrath
2025-02-01 09:58:24 +01:00
parent 6f1d6b469a
commit 32ef09137a

@@ -6,7 +6,6 @@ See also [mstack.nl blog: gRPC / ProtoBuf Support](https://mstack.nl/blogs/wirem
### Proto Definition
Define a Proto Definition file (greet.proto)
syntax = "proto3";
``` proto
syntax = "proto3";
@@ -79,5 +78,51 @@ server
);
```
### Multiple Proto Definition files
If you have multiple proto files, you have to follow these 2 rules:
1. The first file provided in the array should be the main proto file.
2. A comment is needed for each referenced (imported) proto file, so that WireMock.Net knows how to resolve.
#### Main proto
``` proto
syntax = "proto3";
import "request.proto";
package greet;
service Greeter {
rpc SayHello (HelloRequest) returns (HelloReply);
}
message HelloReply {
string message = 1;
}
```
#### other proto file
``` proto
// request.proto
syntax = "proto3";
package greet;
message HelloRequest {
string name = 1;
}
```
#### C# code
``` c#
var greet = File.ReadAllText(@"c:\grpc\greet.proto");
var request = File.ReadAllText(@"c:\grpc\request.proto");
. . .
server
// Now call the new AddProtoDefinition method to register this identifier and the 2 ProtoDefinitions in WireMock.Net
.AddProtoDefinition(protoDefinitionId, greet, request)
```
#### JSON Mapping option
todo