Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Apr 21, 2024
1 parent eabf83c commit d91f36f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index/extract_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
continue
}
// issue #481, don't look at refs in arrays, the next node isn't the value.
if utils.IsNodeArray(node) {
if utils.IsNodeArray(node) {
continue

Check warning on line 220 in index/extract_refs.go

View check run for this annotation

Codecov / codecov/patch

index/extract_refs.go#L220

Added line #L220 was not covered by tests
}
}
Expand Down Expand Up @@ -444,6 +444,9 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
if utils.IsNodeArray(node) {
continue
}
if slices.Contains(seenPath, "example") || slices.Contains(seenPath, "examples") {
continue
}

ref := &DescriptionReference{
ParentNode: parent,
Expand All @@ -462,6 +465,10 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,

if n.Value == "summary" {

if slices.Contains(seenPath, "example") || slices.Contains(seenPath, "examples") {
continue
}

var b *yaml.Node
if len(node.Content) == i+1 {
b = node.Content[i]
Expand Down
15 changes: 15 additions & 0 deletions index/spec_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,3 +1701,18 @@ components:
schemas := index.GetAllSchemas()
assert.Equal(t, 6, len(schemas))
}

func TestSpecIndex_CheckIgnoreDescriptionsInExamples(t *testing.T) {
yml := `openapi: 3.1.0
components:
examples:
example1:
description: this should be ignored`

var rootNode yaml.Node
_ = yaml.Unmarshal([]byte(yml), &rootNode)

index := NewSpecIndexWithConfig(&rootNode, CreateOpenAPIIndexConfig())
schemas := index.GetAllDescriptions()
assert.Equal(t, 0, len(schemas))
}

0 comments on commit d91f36f

Please sign in to comment.