Skip to content

Commit

Permalink
Fix standalone types parsing (#47)
Browse files Browse the repository at this point in the history
Standalone types were previously only parsed correctly if they were part of a structure and parsed as a structure field.
---
Signed-off-by: Amund Tenstad <github@amund.io>
  • Loading branch information
tenstad committed Aug 4, 2023
1 parent 76b92fd commit cffe2b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/api/v1/guestbook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{})
}

0 comments on commit cffe2b7

Please sign in to comment.