mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-26 19:11:04 +01:00
Updated Request Matching ProtoBuf (markdown)
@@ -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
|
||||
Reference in New Issue
Block a user