Skip to content

Commit

Permalink
Merge pull request #271 from snyk/revert/component-extension-behaviour
Browse files Browse the repository at this point in the history
fix: stop merging component extensions
  • Loading branch information
jlourenc authored Feb 7, 2023
2 parents 29347e2 + 5a0b876 commit 1318cca
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 28 deletions.
4 changes: 0 additions & 4 deletions merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ func mergeTags(dst, src *openapi3.T, replace bool) {
}

func initDestinationComponents(dst, src *openapi3.T) {
if src.Components.Extensions != nil && dst.Components.Extensions == nil {
dst.Components.Extensions = make(map[string]interface{})
}
if src.Components.Schemas != nil && dst.Components.Schemas == nil {
dst.Components.Schemas = make(map[string]*openapi3.SchemaRef)
}
Expand Down Expand Up @@ -101,7 +98,6 @@ func mergeComponents(dst, src *openapi3.T, replace bool) {

initDestinationComponents(dst, src)

mergeMap(dst.Components.Extensions, src.Components.Extensions, replace)
mergeMap(dst.Components.Schemas, src.Components.Schemas, replace)
mergeMap(dst.Components.Parameters, src.Components.Parameters, replace)
mergeMap(dst.Components.Headers, src.Components.Headers, replace)
Expand Down
18 changes: 0 additions & 18 deletions merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func TestMergeComponents(t *testing.T) {
dst := mustLoadFile(c, "merge_test_dst.yaml")
vervet.Merge(dst, src, false)

c.Assert(dst.Components.Extensions["x-snyk-extension-0"], openapiCmp, dstOrig.Components.Extensions["x-snyk-extension-0"])
c.Assert(dst.Components.Extensions["x-snyk-extension-1"], openapiCmp, dstOrig.Components.Extensions["x-snyk-extension-1"])
c.Assert(dst.Components.Extensions["x-snyk-extension-2"], openapiCmp, src.Components.Extensions["x-snyk-extension-2"])

c.Assert(dst.Components.Schemas["Foo"], openapiCmp, dstOrig.Components.Schemas["Foo"])
c.Assert(dst.Components.Schemas["Bar"], openapiCmp, src.Components.Schemas["Bar"])
c.Assert(dst.Components.Schemas["Baz"], openapiCmp, dstOrig.Components.Schemas["Baz"])
Expand Down Expand Up @@ -61,19 +57,13 @@ func TestMergeComponents(t *testing.T) {
c.Assert(dst.Components.Examples["Foo"], openapiCmp, dstOrig.Components.Examples["Foo"])
c.Assert(dst.Components.Examples["Bar"], openapiCmp, src.Components.Examples["Bar"])
c.Assert(dst.Components.Examples["Baz"], openapiCmp, dstOrig.Components.Examples["Baz"])

c.Assert(dst.Components.Extensions["x-extension"], qt.DeepEquals, dstOrig.Components.Extensions["x-extension"])
})
c.Run("component with replace", func(c *qt.C) {
src := mustLoadFile(c, "merge_test_src.yaml")
dstOrig := mustLoadFile(c, "merge_test_dst.yaml")
dst := mustLoadFile(c, "merge_test_dst.yaml")
vervet.Merge(dst, src, true)

c.Assert(dst.Components.Extensions["x-snyk-extension-0"], openapiCmp, dstOrig.Components.Extensions["x-snyk-extension-0"])
c.Assert(dst.Components.Extensions["x-snyk-extension-1"], openapiCmp, src.Components.Extensions["x-snyk-extension-1"])
c.Assert(dst.Components.Extensions["x-snyk-extension-2"], openapiCmp, src.Components.Extensions["x-snyk-extension-2"])

c.Assert(dst.Components.Schemas["Foo"], openapiCmp, src.Components.Schemas["Foo"])
c.Assert(dst.Components.Schemas["Bar"], openapiCmp, src.Components.Schemas["Bar"])
c.Assert(dst.Components.Schemas["Baz"], openapiCmp, dstOrig.Components.Schemas["Baz"])
Expand Down Expand Up @@ -101,19 +91,13 @@ func TestMergeComponents(t *testing.T) {
c.Assert(dst.Components.Examples["Foo"], openapiCmp, src.Components.Examples["Foo"])
c.Assert(dst.Components.Examples["Bar"], openapiCmp, src.Components.Examples["Bar"])
c.Assert(dst.Components.Examples["Baz"], openapiCmp, dstOrig.Components.Examples["Baz"])

c.Assert(dst.Components.Extensions["x-extension"], openapiCmp, src.Components.Extensions["x-extension"])
})
c.Run("component with missing sections", func(c *qt.C) {
src := mustLoadFile(c, "merge_test_src.yaml")
dstOrig := mustLoadFile(c, "merge_test_dst_missing_components.yaml")
dst := mustLoadFile(c, "merge_test_dst_missing_components.yaml")
vervet.Merge(dst, src, true)

c.Assert(dst.Components.Extensions["x-snyk-extension-0"], openapiCmp, dstOrig.Components.Extensions["x-snyk-extension-0"])
c.Assert(dst.Components.Extensions["x-snyk-extension-1"], openapiCmp, src.Components.Extensions["x-snyk-extension-1"])
c.Assert(dst.Components.Extensions["x-snyk-extension-2"], openapiCmp, src.Components.Extensions["x-snyk-extension-2"])

c.Assert(dst.Components.Schemas["Foo"], openapiCmp, src.Components.Schemas["Foo"])
c.Assert(dst.Components.Schemas["Bar"], openapiCmp, src.Components.Schemas["Bar"])
c.Assert(dst.Components.Schemas["Baz"], openapiCmp, dstOrig.Components.Schemas["Baz"])
Expand Down Expand Up @@ -141,8 +125,6 @@ func TestMergeComponents(t *testing.T) {
c.Assert(dst.Components.Examples["Foo"], openapiCmp, src.Components.Examples["Foo"])
c.Assert(dst.Components.Examples["Bar"], openapiCmp, src.Components.Examples["Bar"])
c.Assert(dst.Components.Examples["Baz"], openapiCmp, dstOrig.Components.Examples["Baz"])

c.Assert(dst.Components.Extensions["x-extension"], openapiCmp, src.Components.Extensions["x-extension"])
})
}

Expand Down
2 changes: 0 additions & 2 deletions testdata/merge_test_dst.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
components:
x-snyk-extension-0: "extension-0"
x-snyk-extension-1: "extension-1"
schemas:
Foo:
type: object
Expand Down
2 changes: 0 additions & 2 deletions testdata/merge_test_src.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
components:
x-snyk-extension-1: "extension-11"
x-snyk-extension-2: "extension-2"
schemas:
Foo:
type: object
Expand Down
3 changes: 1 addition & 2 deletions versionware/example/releases/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import "embed"

// Embed compiled OpenAPI specs in Go projects.

// Versions contains OpenAPI specs for each distinct release version.
//
//go:embed 2021-11-01~experimental/spec.json
//go:embed 2021-11-01~experimental/spec.yaml
//go:embed 2021-11-08~experimental/spec.json
//go:embed 2021-11-08~experimental/spec.yaml
//go:embed 2021-11-20~experimental/spec.json
//go:embed 2021-11-20~experimental/spec.yaml
// Versions contains OpenAPI specs for each distinct release version.
var Versions embed.FS

0 comments on commit 1318cca

Please sign in to comment.