Skip to content
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
41 changes: 0 additions & 41 deletions internal/analyzer/aliascycles.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package analyzer

import (
"slices"
"strings"

"github.com/parallelworks/openapi-client-generator/internal/ir"
Expand Down Expand Up @@ -101,46 +100,6 @@ func breakStructCycles(types []*ir.TypeDef) {
}
}

// dropShadowedCatchAlls removes the catch-all from a struct that embeds one,
// whose promoted marshalers would otherwise win and emit only their own fields.
func dropShadowedCatchAlls(types []*ir.TypeDef) {
byName := ir.TypesByName(types)

hasCatchAll := func(td *ir.TypeDef) bool {
return slices.ContainsFunc(td.Fields, func(f *ir.Field) bool { return f.CatchAll })
}

// Reports whether td or anything it embeds carries a catch-all.
var embedsCatchAll func(td *ir.TypeDef, depth int) bool
embedsCatchAll = func(td *ir.TypeDef, depth int) bool {
if td == nil || depth > len(types) {
return false
}
for _, f := range td.Fields {
if !f.Embedded {
continue
}
embedded := ir.StructNamed(byName, strings.TrimPrefix(f.Type, "*"))
if embedded == nil {
continue
}
if hasCatchAll(embedded) || embedsCatchAll(embedded, depth+1) {
return true
}
}
return false
}

for _, td := range types {
if td == nil || td.Kind != ir.TypeKindStruct || !hasCatchAll(td) {
continue
}
if embedsCatchAll(td, 0) {
td.Fields = slices.DeleteFunc(td.Fields, func(f *ir.Field) bool { return f.CatchAll })
}
}
}

// aliasTarget returns the named type an alias's Go type expression refers to,
// peeling the slice, pointer, and map wrappers that do not stop a Go alias from
// expanding. It returns "" for a builtin or a composite with no single referent.
Expand Down
1 change: 0 additions & 1 deletion internal/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func (a *Analyzer) Analyze(packageName string) (*ir.Package, error) {
// a struct may only do it through an indirection.
breakAliasCycles(pkg.Types)
breakStructCycles(pkg.Types)
dropShadowedCatchAlls(pkg.Types)

// Detect paginated operations.
a.detectPagination(pkg)
Expand Down
Loading
Loading