From beb447d3da55e78964912796b3362b6889c0de53 Mon Sep 17 00:00:00 2001 From: Amund Tenstad Date: Wed, 2 Aug 2023 13:32:49 +0200 Subject: [PATCH] fix: parse standalone types correctly (before parsed as struct fields) Signed-off-by: Amund Tenstad --- processor/processor.go | 2 +- test/api/v1/guestbook_types.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/processor/processor.go b/processor/processor.go index 09caa79..fe95de7 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -283,7 +283,7 @@ func (p *processor) processType(pkg *loader.Package, info *markers.TypeInfo, dep return p.processStructFields(typeDef, pkg, info, depth) } - t := pkg.TypesInfo.TypeOf(info.RawSpec.Type) + t := pkg.TypesInfo.TypeOf(info.RawSpec.Name) if t == nil { zap.S().Warnw("Failed to determine AST type", "package", pkg.PkgPath, "type", info.Name) typeDef.Kind = types.UnknownKind diff --git a/test/api/v1/guestbook_types.go b/test/api/v1/guestbook_types.go index 7a6d69d..41daff2 100644 --- a/test/api/v1/guestbook_types.go +++ b/test/api/v1/guestbook_types.go @@ -48,6 +48,12 @@ type EmbeddedX struct { X string `json:"x,omitempty"` } +// NOTE: Rating is placed here to ensure that it is parsed as a standalone type +// before it is parsed as a struct field. + +// Rating is the rating provided by a guest. +type Rating string + // GuestbookSpec defines the desired state of Guestbook. type GuestbookSpec struct { // Page indicates the page number @@ -102,9 +108,6 @@ type GuestbookList struct { Items []Guestbook `json:"items"` } -// Rating is the rating provided by a guest. -type Rating string - func init() { SchemeBuilder.Register(&Guestbook{}, &GuestbookList{}) }