Skip to content

Commit

Permalink
fix: check need annotation or not
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Mar 14, 2024
1 parent 3a92741 commit 96e17a9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions codegen/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 96e17a9

Please sign in to comment.