diff --git a/cmd/oras/internal/display/metadata/tree/discover.go b/cmd/oras/internal/display/metadata/tree/discover.go index 64abbb811..496de1279 100644 --- a/cmd/oras/internal/display/metadata/tree/discover.go +++ b/cmd/oras/internal/display/metadata/tree/discover.go @@ -61,6 +61,9 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err if !ok { return fmt.Errorf("unexpected subject descriptor: %v", subject) } + if referrer.ArtifactType == "" { + referrer.ArtifactType = "" + } referrerNode := node.AddPath(referrer.ArtifactType, referrer.Digest) if h.verbose { for k, v := range referrer.Annotations { diff --git a/test/e2e/suite/command/discover.go b/test/e2e/suite/command/discover.go index ef320d0b2..58fba9942 100644 --- a/test/e2e/suite/command/discover.go +++ b/test/e2e/suite/command/discover.go @@ -172,6 +172,12 @@ var _ = Describe("1.1 registry users:", func() { MatchKeyWords(append(discoverKeyWords(true, referrers...), RegistryRef(ZOTHost, ArtifactRepo, foobar.Digest))...). Exec() }) + + It("should display if a referrer has an empty artifact type", func() { + ORAS("discover", RegistryRef(ZOTHost, ArtifactRepo, "multi"), "--format", format). + MatchKeyWords(""). + Exec() + }) }) When("running discover command with table output", func() { format := "table"