Skip to content

Commit cd4f5aa

Browse files
mromaszewiczclaude
andauthored
fix: allOf cycle detection oversight (#2316)
PR #1377 was merged too early. This is a small follow-up tweak to make sure that #1373 is fixed properly. seed allOf[0] ref into cycle detection to prevent stack overflow when self-ref is first When the self-referencing $ref appears at position 0 in allOf, its ref was never added to seenSchemaRef. If s1's own AllOf contained a back-reference to itself, mergeAllOf would not detect the cycle. Seed allOf[0].Ref into a top-level seen set that is copied into each iteration's seenSchemaRef map, closing this gap. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 20bf6e1 commit cd4f5aa

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

pkg/codegen/merge_schemas.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ func mergeSchemas(allOf []*openapi3.SchemaRef, path []string) (Schema, error) {
3232
return Schema{}, err
3333
}
3434

35+
// Seed allOf[0]'s ref so that if s1's own AllOf contains a back-reference
36+
// to itself, the cycle is detected during recursive merging.
37+
seenTopLevel := make(map[string]bool)
38+
if allOf[0].Ref != "" {
39+
seenTopLevel[allOf[0].Ref] = true
40+
}
41+
3542
for i := 1; i < n; i++ {
3643
var err error
3744
oneOfSchema, err := valueWithPropagatedRef(allOf[i])
@@ -40,8 +47,12 @@ func mergeSchemas(allOf []*openapi3.SchemaRef, path []string) (Schema, error) {
4047
}
4148

4249
seenSchemaRef := make(map[string]bool)
50+
for k := range seenTopLevel {
51+
seenSchemaRef[k] = true
52+
}
4353
if allOf[i].Ref != "" {
4454
seenSchemaRef[allOf[i].Ref] = true
55+
seenTopLevel[allOf[i].Ref] = true
4556
}
4657
schema, err = mergeOpenapiSchemas(schema, oneOfSchema, true, seenSchemaRef)
4758
if err != nil {

0 commit comments

Comments
 (0)