MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / resolveCollisions

Function resolveCollisions

pkg/codegen/resolve_names.go:106–137  ·  view source on GitHub ↗

resolveCollisions detects and resolves naming collisions among the resolved names. It applies strategies in global phases of increasing aggressiveness: 1. Context suffix (Schema, Parameter, Response, etc.) 2. Per-schema disambiguation (content type, status code, etc.) 3. Numeric fallback Each strat

(names []*ResolvedName)

Source from the content-addressed store, hash-verified

104// oscillation between strategies (e.g., context suffix and content type
105// suffix repeatedly appending to the same names without resolution).
106func resolveCollisions(names []*ResolvedName) {
107 strategies := []func([]*ResolvedName) bool{
108 strategyContextSuffix,
109 strategyPerSchemaDisambiguate,
110 strategyNumericFallback,
111 }
112
113 const maxIterations = 20
114
115 for _, strategy := range strategies {
116 for range maxIterations {
117 groups := groupByName(names)
118 anyCollision := false
119 anyProgress := false
120 for _, group := range groups {
121 if len(group) <= 1 {
122 continue
123 }
124 anyCollision = true
125 if strategy(group) {
126 anyProgress = true
127 }
128 }
129 if !anyCollision {
130 return
131 }
132 if !anyProgress {
133 break // This strategy can't help; try the next one
134 }
135 }
136 }
137}
138
139// groupByName groups ResolvedNames by their current GoName.
140func groupByName(names []*ResolvedName) map[string][]*ResolvedName {

Callers 1

ResolveNamesFunction · 0.85

Calls 1

groupByNameFunction · 0.85

Tested by

no test coverage detected