From 6633b8aa5161c5aac5b6b2cfa400638164ee4fde Mon Sep 17 00:00:00 2001 From: liangsky <640634387@qq.com> Date: Fri, 16 Aug 2024 11:36:34 +0800 Subject: [PATCH] fix(http-mock-gen): methods should in serverName, to fix generater error --- packages/grpc-mock/src/gen/gen-mock-data.ts | 3 +- .../proto-servers/server2/activity2-new.proto | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/grpc-mock/test/proto-servers/server2/activity2-new.proto diff --git a/packages/grpc-mock/src/gen/gen-mock-data.ts b/packages/grpc-mock/src/gen/gen-mock-data.ts index d68467a..c9ab757 100644 --- a/packages/grpc-mock/src/gen/gen-mock-data.ts +++ b/packages/grpc-mock/src/gen/gen-mock-data.ts @@ -97,7 +97,7 @@ const genMockData = async ( rootPathServerNameMap?.[spaceServerName] ?? spaceServerName; const root = protobufjs.Root.fromJSON(rootObject[spaceServerName]); const result: IInspectNamespace = inspectNamespace(root); - const { services, methods } = result!; + const { services } = result!; const genServiceMockData = new GenServiceMockData({ genServerPath, prettierOptions, @@ -109,6 +109,7 @@ const genMockData = async ( const protoName = service.fullName.split('.')[0]; const protoPath = `${spaceServerName}.${service.fullName}`; const serviceCodeName = firstWordNeedLetter(service.name); + const methods = service.methods ?? []; await new GenProtoMockData({ index, diff --git a/packages/grpc-mock/test/proto-servers/server2/activity2-new.proto b/packages/grpc-mock/test/proto-servers/server2/activity2-new.proto new file mode 100644 index 0000000..8dda8e4 --- /dev/null +++ b/packages/grpc-mock/test/proto-servers/server2/activity2-new.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; + +package activity_package_new; + + +// 活动服务 +service ActivityService2 { + // 新增活动 + rpc Create(CreateActivityRequest2New) returns (CreateActivityResponse2New); +} + +message CreateActivityRequest2New { + // 活动Id + string activityId = 1; +} + +message CreateActivityResponse2New { + // 活动名称 + string activityName = 1; + // key:活动ID, value: 资源提供方(0:配置 1:分销通:中介门店 2:分销通项目地址) + // @required + map activityResourceProviders = 2; + + // 微信订阅通知模板列表 + // { + // "a-id": "模板a", + // "b-id": "模板b", + // } + // @required + map templates = 3; + // @required + map intKeyTemplates = 4; + // number类型 + int32 count = 5; + // string 转 number类型 + int64 longCount = 6; + // bool类型 + bool isGood = 7; +} + +message ResourceProviders{ + // @required + repeated int32 resourceProviders = 1; +}