Skip to content

Commit

Permalink
Merge pull request #391 from snyk/fix/dereference-additional-properites
Browse files Browse the repository at this point in the history
fix: openapi walker walks into additional properties
  • Loading branch information
tinygrasshopper authored Oct 18, 2024
2 parents 43e9f15 + ce79d95 commit 5d2eda2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/openapiwalker/walker.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ func ProcessRefs(data any, p RefProcessor) error {
if err := ProcessRefs(v.Not, p); err != nil {
return err
}
if err := ProcessRefs(v.AdditionalProperties, p); err != nil {
return err
}

case openapi3.AdditionalProperties:
if err := ProcessRefs(v.Schema, p); err != nil {
return err
}

case *openapi3.PathItem:
if v != nil {
Expand Down
35 changes: 35 additions & 0 deletions internal/openapiwalker/walker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,41 @@ func TestProcessRefs(t *testing.T) {
},
})
})

c.Run("processes schema refs inside additional properties", func(c *qt.C) {
doc := &openapi3.T{}
doc.Components = &openapi3.Components{
Schemas: openapi3.Schemas{
"key-1": {
Value: &openapi3.Schema{
AdditionalProperties: openapi3.AdditionalProperties{
Schema: &openapi3.SchemaRef{
Ref: "value-1",
},
},
},
},
},
}

recorder := &recordRefProcessor{}
err := ProcessRefs(doc, recorder)
c.Assert(err, qt.IsNil)
c.Assert(toJson(c, recorder.SchemaRefs), qt.JSONEquals, []*openapi3.SchemaRef{
{
Value: &openapi3.Schema{
AdditionalProperties: openapi3.AdditionalProperties{
Schema: &openapi3.SchemaRef{
Ref: "value-1",
},
},
},
},
{
Ref: "value-1",
},
})
})
}

func toJson(c *qt.C, obj any) []byte {
Expand Down

0 comments on commit 5d2eda2

Please sign in to comment.