Skip to content

Commit

Permalink
custom type: check for optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Adphi committed Sep 27, 2021
1 parent 5733dfd commit f3650d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions patch/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion patch/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f3650d0

Please sign in to comment.