Skip to content
Open
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
6 changes: 6 additions & 0 deletions internal/analysis/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func Parse(r io.Reader) (Document, error) {
line := parseLine(scanner.Bytes(), lineNum)
document.Lines = append(document.Lines, line.line)

// A blank line parses as indent 0, which would reset the parent
// stack and orphan everything below it in the same mapping.
if len(bytes.TrimSpace(scanner.Bytes())) == 0 {
continue
}

for len(parentStack) > 0 && parentStack[len(parentStack)-1].indent >= line.indent {
parentStack = parentStack[:len(parentStack)-1]
}
Expand Down
24 changes: 24 additions & 0 deletions internal/analysis/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,30 @@ components:
}
}

func TestRefs_BlankLineBetweenSchemas(t *testing.T) {
document, err := Parse(bytes.NewReader([]byte(`openapi: 3.0.0
components:
schemas:
Foo:
type: object

Bar:
type: object
`)))
if err != nil {
t.Fatal(err)
}

for _, ref := range []string{
"#/components/schemas/Foo",
"#/components/schemas/Bar",
} {
if document.Locate(ref) == nil {
t.Errorf("could not locate %s", ref)
}
}
}

func TestParse_PetStore(t *testing.T) {
f, err := os.Open("testdata/petstore.yaml")
if err != nil {
Expand Down