Skip to content

Commit

Permalink
Merge pull request #106 from cmars/fix/merge-empty-dst
Browse files Browse the repository at this point in the history
fix: empty merge destination
  • Loading branch information
cmars committed Dec 17, 2021
2 parents 69a9763 + 8cde9c1 commit d8c8a6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ func mergeInfo(dst, src *openapi3.T, replace bool) {
}

func mergePaths(dst, src *openapi3.T, replace bool) {
if src.Paths != nil && dst.Paths == nil {
dst.Paths = make(openapi3.Paths)
}
for k, v := range src.Paths {
if _, ok := dst.Paths[k]; !ok || replace {
dst.Paths[k] = v
Expand Down
23 changes: 23 additions & 0 deletions merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,29 @@ servers:
})
}

func TestMergeIntoEmpty(t *testing.T) {
c := qt.New(t)
srcYaml := `
info:
title: Src
version: src
paths:
/foo:
get:
description: get a foo
responses:
200:
contents:
application/json:
schema:
type: object
`
src := mustLoad(c, srcYaml)
dst := &openapi3.T{}
vervet.Merge(dst, src, false)
c.Assert(dst.Paths, qt.HasLen, 1)
}

func mustLoadFile(c *qt.C, path string) *openapi3.T {
doc, err := vervet.NewDocumentFile(testdata.Path(path))
c.Assert(err, qt.IsNil)
Expand Down

0 comments on commit d8c8a6c

Please sign in to comment.