From 32ef09137a79824f3ecc11616b9c6536fa1c73bb Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 1 Feb 2025 09:58:24 +0100 Subject: [PATCH] Updated Request Matching ProtoBuf (markdown) --- Request-Matching-ProtoBuf.md | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/Request-Matching-ProtoBuf.md b/Request-Matching-ProtoBuf.md index fcbab6e..1833b02 100644 --- a/Request-Matching-ProtoBuf.md +++ b/Request-Matching-ProtoBuf.md @@ -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 \ No newline at end of file