From f3650d053553bf1f1b7378fa7056acaabe5a1c22 Mon Sep 17 00:00:00 2001 From: Adphi Date: Mon, 27 Sep 2021 17:37:21 +0200 Subject: [PATCH] custom type: check for optional --- patch/field_type.go | 5 +++++ patch/patcher.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/patch/field_type.go b/patch/field_type.go index 8e3dad6..9917ccf 100644 --- a/patch/field_type.go +++ b/patch/field_type.go @@ -43,6 +43,11 @@ func (p *Patcher) patchTypeDef(id *ast.Ident, obj types.Object) { return true } return false + case *ast.StarExpr: + t.X = &ast.Ident{ + Name: fieldType, + } + return true default: return false } diff --git a/patch/patcher.go b/patch/patcher.go index 026bf91..c51e70f 100644 --- a/patch/patcher.go +++ b/patch/patcher.go @@ -320,7 +320,7 @@ func (p *Patcher) scanField(f *protogen.Field) { switch { case f.Message != nil && !f.Desc.IsList(): log.Printf("Warning: type declared for message field: %s", f.Desc.Name()) - case f.Oneof != nil: + case f.Oneof != nil && !f.Desc.HasOptionalKeyword(): p.Type(ident.WithChild(f.GoIdent, f.GoName), fieldType) p.Type(ident.WithChild(m.GoIdent, "Get"+f.GoName), fieldType) default: