diff --git a/cmd/hz/protobuf/plugin.go b/cmd/hz/protobuf/plugin.go index e25803860..eb812894a 100644 --- a/cmd/hz/protobuf/plugin.go +++ b/cmd/hz/protobuf/plugin.go @@ -364,6 +364,10 @@ func (plugin *Plugin) GenerateFile(gen *protogen.Plugin, f *protogen.File) error if strings.HasPrefix(impt, plugin.Package) { impt = impt[len(plugin.Package):] } + // The file name must be the relative path, reference https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/plugin.proto#L122 + if strings.HasPrefix(impt, "/") { + impt = impt[1:] + } f.GeneratedFilenamePrefix = filepath.Join(util.ImportToPath(impt, ""), util.BaseName(f.Proto.GetName(), ".proto")) f.Generate = true // if use third-party model, no model code is generated within the project