From 96e17a9c202f8e6b8f7fc23faadec16b7f1e3bb6 Mon Sep 17 00:00:00 2001 From: thinkgos Date: Thu, 14 Mar 2024 07:03:59 +0000 Subject: [PATCH] fix: check need annotation or not --- codegen/mapper.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/codegen/mapper.go b/codegen/mapper.go index 1a62210..6e7305a 100644 --- a/codegen/mapper.go +++ b/codegen/mapper.go @@ -25,8 +25,10 @@ func (g *CodeGen) GenMapper() *CodeGen { g.Println() } - g.Println(`import "protoc-gen-openapiv2/options/annotations.proto";`) - g.Println() + if needOpenapiv2Annotation(g.entities) { + g.Println(`import "protoc-gen-openapiv2/options/annotations.proto";`) + g.Println() + } for _, et := range g.entities { structName := utils.CamelCase(et.Name) @@ -67,3 +69,14 @@ func genMapperMessageField(seq int, m *ens.ProtoMessage) string { } return fmt.Sprintf("%s %s = %d%s;", m.DataType, m.Name, seq, annotation) } + +func needOpenapiv2Annotation(entities []*ens.EntityDescriptor) bool { + for _, entity := range entities { + for _, v := range entity.ProtoMessage { + if v.DataType == "int64" { + return true + } + } + } + return false +}