Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parse standalone types correctly #47

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{})
}