diff --git a/encoding/protobuf/parse.go b/encoding/protobuf/parse.go index b962112ad..9e7f914f7 100644 --- a/encoding/protobuf/parse.go +++ b/encoding/protobuf/parse.go @@ -277,7 +277,11 @@ func (p *protoConverter) resolveTopScope(pos scanner.Position, name string, opti if k == -1 { i = len(name) } - if m, ok := p.scope[0][name[:i]]; ok { + curName := name[:i] + if local, ok := strings.CutPrefix(curName, p.protoPkg+"."); ok { + curName = local + } + if m, ok := p.scope[0][curName]; ok { if m.pkg != nil { p.imported[m.pkg.qualifiedImportPath()] = true } diff --git a/encoding/protobuf/protobuf_test.go b/encoding/protobuf/protobuf_test.go index c08696116..ad2aefe03 100644 --- a/encoding/protobuf/protobuf_test.go +++ b/encoding/protobuf/protobuf_test.go @@ -37,6 +37,7 @@ func TestExtractDefinitions(t *testing.T) { "mixer/v1/attributes.proto", "mixer/v1/config/client/client_config.proto", "other/trailcomment.proto", + "other/full_references.proto", } for _, file := range testCases { t.Run(file, func(t *testing.T) { diff --git a/encoding/protobuf/testdata/full_references.proto.out.cue b/encoding/protobuf/testdata/full_references.proto.out.cue new file mode 100644 index 000000000..a1f947941 --- /dev/null +++ b/encoding/protobuf/testdata/full_references.proto.out.cue @@ -0,0 +1,13 @@ +package full_references + +#FullReferenceMsg: { + nestedMsg?: #FullReferenceNestedMsg @protobuf(1,istio.io.api.other.full_references.FullReferenceNestedMsg,name=nested_msg) +} + +#FullReferenceNestedMsg: { + + #FullReferenceDoubleNestedMsg: { + value?: string @protobuf(1,string) + } + nestedMsg?: #FullReferenceNestedMsg.#FullReferenceDoubleNestedMsg @protobuf(1,istio.io.api.other.full_references.FullReferenceNestedMsg.FullReferenceDoubleNestedMsg,name=nested_msg) +} diff --git a/encoding/protobuf/testdata/istio.io/api/other/full_references.proto b/encoding/protobuf/testdata/istio.io/api/other/full_references.proto new file mode 100644 index 000000000..2c81bde5d --- /dev/null +++ b/encoding/protobuf/testdata/istio.io/api/other/full_references.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package istio.io.api.other.full_references; + +message FullReferenceMsg { + istio.io.api.other.full_references.FullReferenceNestedMsg nested_msg = 1; +} + +message FullReferenceNestedMsg { + message FullReferenceDoubleNestedMsg { + string value = 1; + } + + istio.io.api.other.full_references.FullReferenceNestedMsg.FullReferenceDoubleNestedMsg nested_msg = 1; +}