Skip to content

Commit

Permalink
fix: parser markers and remove workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Amund Tenstad committed Aug 8, 2023
1 parent 9ae0ce1 commit 290f46b
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func newProcessor(compiledConfig *compiledConfig, maxDepth int) *processor {
compiledConfig: compiledConfig,
maxDepth: maxDepth,
parser: &crd.Parser{
Collector: &markers.Collector{Registry: &markers.Registry{}},
Collector: &markers.Collector{Registry: mkRegistry()},
Checker: &loader.TypeChecker{},
},
groupVersions: make(map[schema.GroupVersion]*groupVersionInfo),
Expand Down Expand Up @@ -208,8 +208,6 @@ func (p *processor) findAPITypes(directory string) error {
typeDef = p.processType(pkg, info, 0)
}

populateMarkers(info, typeDef)

p.types[key] = typeDef
if typeDef != nil && typeDef.Kind != types.BasicKind {
gvInfo.types[info.Name] = typeDef
Expand All @@ -230,30 +228,6 @@ func (p *processor) findAPITypes(directory string) error {
return nil
}

// populateMarkers popuplates type and field with markers. Markes are missing
// when type is first parsed as a field within struct.
func populateMarkers(src *markers.TypeInfo, dest *types.Type) {
dest.Markers = src.Markers

for _, f := range src.Fields {
jsonFieldName := f.Name
// extract json name if present
if tagVal, ok := f.Tag.Lookup("json"); ok {
args := strings.Split(tagVal, ",")
if len(args) > 0 && args[0] != "" {
jsonFieldName = args[0]
}
}
for index := range dest.Fields {
field := dest.Fields[index]
if jsonFieldName == field.Name {
field.Markers = f.Markers
break
}
}
}
}

func (p *processor) extractGroupVersionIfExists(collector *markers.Collector, pkg *loader.Package) *groupVersionInfo {
markerValues, err := markers.PackageMarkers(collector, pkg)
if err != nil {
Expand Down Expand Up @@ -569,6 +543,7 @@ func (p *processor) loadAliasType(typeDef *types.Type, pkg *loader.Package, unde
if bt, ok := underlying.(*gotypes.Basic); ok {
typeDef.UnderlyingType = &types.Type{Name: bt.String(), Kind: types.BasicKind}
typeDef.Doc = tInfo.Doc
typeDef.Markers = tInfo.Markers
return typeDef
}

Expand Down

0 comments on commit 290f46b

Please sign in to comment.