Skip to content

Commit

Permalink
Merge pull request #364 from snyk/fix/conflict-components-merge-main
Browse files Browse the repository at this point in the history
Fix/conflict components merge main
  • Loading branch information
tinygrasshopper authored Aug 16, 2024
2 parents 1acd209 + ab19151 commit 8c6966e
Show file tree
Hide file tree
Showing 89 changed files with 1,261 additions and 689 deletions.
2 changes: 1 addition & 1 deletion cmd/vervet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"log"
"os"

"github.com/snyk/vervet/v7/internal/cmd"
"github.com/snyk/vervet/v8/internal/cmd"
)

func main() {
Expand Down
12 changes: 6 additions & 6 deletions cmd/vu-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (
"github.com/rs/zerolog/log"
"golang.org/x/sync/errgroup"

"github.com/snyk/vervet/v7/config"
"github.com/snyk/vervet/v7/internal/handler"
"github.com/snyk/vervet/v7/internal/storage"
"github.com/snyk/vervet/v7/internal/storage/disk"
"github.com/snyk/vervet/v7/internal/storage/gcs"
"github.com/snyk/vervet/v7/internal/storage/s3"
"github.com/snyk/vervet/v8/config"
"github.com/snyk/vervet/v8/internal/handler"
"github.com/snyk/vervet/v8/internal/storage"
"github.com/snyk/vervet/v8/internal/storage/disk"
"github.com/snyk/vervet/v8/internal/storage/gcs"
"github.com/snyk/vervet/v8/internal/storage/s3"
)

func main() {
Expand Down
12 changes: 6 additions & 6 deletions cmd/vu-scraper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/snyk/vervet/v7/config"
"github.com/snyk/vervet/v7/internal/scraper"
"github.com/snyk/vervet/v7/internal/storage"
"github.com/snyk/vervet/v7/internal/storage/disk"
"github.com/snyk/vervet/v7/internal/storage/gcs"
"github.com/snyk/vervet/v7/internal/storage/s3"
"github.com/snyk/vervet/v8/config"
"github.com/snyk/vervet/v8/internal/scraper"
"github.com/snyk/vervet/v8/internal/storage"
"github.com/snyk/vervet/v8/internal/storage/disk"
"github.com/snyk/vervet/v8/internal/storage/gcs"
"github.com/snyk/vervet/v8/internal/storage/s3"
)

func main() {
Expand Down
10 changes: 5 additions & 5 deletions collator.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ func tagsEqual(x, y interface{}) bool {

func (c *Collator) mergePaths(rv *ResourceVersion) error {
if rv.T.Paths != nil && c.result.Paths == nil {
c.result.Paths = make(openapi3.Paths)
c.result.Paths = openapi3.NewPaths()
}
var errs error
for k, v := range rv.T.Paths {
for k, v := range rv.T.Paths.Map() {
for opName, opValue := range v.Operations() {
route := routeForPath(k, opName)
if _, ok := c.seenRoutes[route]; ok {
Expand All @@ -285,13 +285,13 @@ func (c *Collator) mergePaths(rv *ResourceVersion) error {
}
} else {
c.seenRoutes[route] = struct{}{}
if c.result.Paths[k] == nil {
if c.result.Paths.Value(k) == nil {
// Path doesn't exist in output
c.result.Paths[k] = v
c.result.Paths.Set(k, v)
} else {
// There is another operation on this path, merge the
// current operation into that one
c.result.Paths[k].SetOperation(opName, opValue)
c.result.Paths.Value(k).SetOperation(opName, opValue)
}
c.pathSources[k] = rv.path
}
Expand Down
50 changes: 24 additions & 26 deletions collator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import (

qt "github.com/frankban/quicktest"

"github.com/snyk/vervet/v7"
"github.com/snyk/vervet/v7/testdata"
"github.com/snyk/vervet/v8"
"github.com/snyk/vervet/v8/testdata"
)

func TestRefRemover(t *testing.T) {
c := qt.New(t)
doc, err := vervet.NewDocumentFile(testdata.Path("resources/projects/2021-08-20/spec.yaml"))
c.Assert(err, qt.IsNil)
resp400 := doc.Paths["/orgs/{org_id}/projects/{project_id}"].Delete.Responses["400"]
resp400 := doc.Paths.Value("/orgs/{org_id}/projects/{project_id}").Delete.Responses.Status(400)
errDoc := resp400.Value.Content["application/vnd.api+json"].Schema
c.Assert(err, qt.IsNil)
c.Assert("{\"$ref\":\"../errors.yaml#/ErrorDocument\"}", qt.JSONEquals, errDoc)
in := vervet.NewRefRemover(errDoc)
err = in.RemoveRef()
c.Assert(err, qt.IsNil)
err = vervet.RemoveRefs(errDoc)
c.Assert(err, qt.IsNil)
//nolint:lll // acked
c.Assert("{\"additionalProperties\":false,\"example\":{\"errors\":[{\"detail\":\"Permission denied for this "+
Expand Down Expand Up @@ -62,18 +60,18 @@ func TestCollator(t *testing.T) {

result := collator.Result()
c.Assert(
result.Paths["/orgs/{orgId}/projects"].
Get.Responses["200"].
result.Paths.Value("/orgs/{orgId}/projects").
Get.Responses.Status(200).
Value.
Content["application/vnd.api+json"].
Schema.Value.Properties["jsonapi"].Ref,
qt.Equals,
"#/components/schemas/JsonApi",
)
schemaRef := result.
Paths["/examples/hello-world/{id}"].
Paths.Value("/examples/hello-world/{id}").
Get.
Responses["200"].
Responses.Status(200).
Value.
Content["application/vnd.api+json"].
Schema.
Expand All @@ -86,23 +84,23 @@ func TestCollator(t *testing.T) {
":\"object\"}\n", qt.JSONEquals, schemaRef.Value)
c.Assert(result.Components.Schemas["JsonApi"], qt.IsNotNil)

projectParameterRef := result.Paths["/orgs/{orgId}/projects"].Get.Parameters[0]
projectParameterRef := result.Paths.Value("/orgs/{orgId}/projects").Get.Parameters[0]
c.Assert(projectParameterRef.Ref, qt.Equals, "#/components/parameters/Version")
exampleParameterRef := result.Paths["/examples/hello-world/{id}"].Get.Parameters[0]
exampleParameterRef := result.Paths.Value("/examples/hello-world/{id}").Get.Parameters[0]
c.Assert(exampleParameterRef.Ref, qt.Equals, "")
//nolint:lll // acked
c.Assert("{\"description\":\"The requested version of the endpoint to process the request\",\"example\""+
":\"2021-06-04\",\"in\":\"query\",\"name\":\"version\",\"required\":true,\"schema\":{\"description\":"+
"\"Requested API version\",\"pattern\":\"^(wip|work-in-progress|experimental|beta|((([0-9]{4})-([0-1][0-9]))"+
"-((3[01])|(0[1-9])|([12][0-9]))(~(wip|work-in-progress|experimental|beta))?))$\",\"type\":\"string\"}}\n", qt.JSONEquals, exampleParameterRef.Value)

projectConflictRef := result.Paths["/orgs/{orgId}/projects"].Get.Parameters[6]
exampleConflictRef := result.Paths["/examples/hello-world/{id}"].Get.Parameters[3]
projectConflictRef := result.Paths.Value("/orgs/{orgId}/projects").Get.Parameters[6]
exampleConflictRef := result.Paths.Value("/examples/hello-world/{id}").Get.Parameters[3]
c.Assert(projectConflictRef.Ref, qt.Not(qt.Equals), exampleConflictRef.Ref)

projectResp400Ref := result.Paths["/orgs/{orgId}/projects"].Get.Responses["400"]
projectResp400Ref := result.Paths.Value("/orgs/{orgId}/projects").Get.Responses.Status(400)
c.Assert(projectResp400Ref.Ref, qt.Equals, "#/components/responses/400")
exampleResp400Ref := result.Paths["/examples/hello-world/{id}"].Get.Responses["400"]
exampleResp400Ref := result.Paths.Value("/examples/hello-world/{id}").Get.Responses.Status(400)
c.Assert(exampleResp400Ref.Ref, qt.Equals, "")
c.Assert("{\"content\":{\"application/vnd.api+json\":{\"schema\":{\"additionalProperties\":false,\"example\":{"+
"\"errors\":[{\"detail\":\"Permission denied for this resource\",\"status\":\"403\"}],\"jsonapi\":{\"version\":"+
Expand Down Expand Up @@ -168,11 +166,11 @@ func TestCollateUseFirstRoute(t *testing.T) {
result := collator.Result()

// First path chosen, route matching rules ignore path variable
c.Assert(result.Paths["/examples/hello-world/{id1}"], qt.Not(qt.IsNil))
c.Assert(result.Paths["/examples/hello-world/{id2}"], qt.IsNil)
c.Assert(result.Paths.Value("/examples/hello-world/{id1}"), qt.Not(qt.IsNil))
c.Assert(result.Paths.Value("/examples/hello-world/{id2}"), qt.IsNil)

// First chosen path has description expected
c.Assert(result.Paths["/examples/hello-world/{id1}"].Get.Description, qt.Contains, " - from example 1")
c.Assert(result.Paths.Value("/examples/hello-world/{id1}").Get.Description, qt.Contains, " - from example 1")
}

func TestCollatePathConflict(t *testing.T) {
Expand Down Expand Up @@ -215,7 +213,7 @@ func TestCollateMergingResources(t *testing.T) {
c.Assert(err, qt.IsNil)

result := collator.Result()
c.Assert(result.Paths["/orgs/{org_id}/projects/{project_id}"].Delete.Responses["204"], qt.IsNotNil)
c.Assert(result.Paths.Value("/orgs/{org_id}/projects/{project_id}").Delete.Responses.Status(204), qt.IsNotNil)
}

func TestCollateOperationsOnSamePath(t *testing.T) {
Expand All @@ -238,10 +236,10 @@ func TestCollateOperationsOnSamePath(t *testing.T) {

result := collator.Result()

c.Assert(result.Paths["/examples/hello-world"].Get, qt.Not(qt.IsNil))
c.Assert(result.Paths["/examples/hello-world"].Get.Description, qt.Contains, " - from example 1")
c.Assert(result.Paths["/examples/hello-world"].Post, qt.Not(qt.IsNil))
c.Assert(result.Paths["/examples/hello-world"].Post.Description, qt.Contains, " - from example 1")
c.Assert(result.Paths["/examples/hello-world"].Put, qt.Not(qt.IsNil))
c.Assert(result.Paths["/examples/hello-world"].Put.Description, qt.Contains, " - from example 2")
c.Assert(result.Paths.Value("/examples/hello-world").Get, qt.Not(qt.IsNil))
c.Assert(result.Paths.Value("/examples/hello-world").Get.Description, qt.Contains, " - from example 1")
c.Assert(result.Paths.Value("/examples/hello-world").Post, qt.Not(qt.IsNil))
c.Assert(result.Paths.Value("/examples/hello-world").Post.Description, qt.Contains, " - from example 1")
c.Assert(result.Paths.Value("/examples/hello-world").Put, qt.Not(qt.IsNil))
c.Assert(result.Paths.Value("/examples/hello-world").Put.Description, qt.Contains, " - from example 2")
}
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

qt "github.com/frankban/quicktest"

"github.com/snyk/vervet/v7/config"
"github.com/snyk/vervet/v8/config"
)

func TestLoad(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion config/underground.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/viper"

"github.com/snyk/vervet/v7"
"github.com/snyk/vervet/v8"
)

// StorageType describes backend implementations supported by Vervet Underground.
Expand Down
4 changes: 2 additions & 2 deletions config/underground_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

qt "github.com/frankban/quicktest"

"github.com/snyk/vervet/v7"
"github.com/snyk/vervet/v7/config"
"github.com/snyk/vervet/v8"
"github.com/snyk/vervet/v8/config"
)

func createTestFile(c *qt.C, data []byte) *os.File {
Expand Down
3 changes: 3 additions & 0 deletions document.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ func NewDocumentFile(specFile string) (_ *Document, returnErr error) {
}

var t openapi3.T

contents, err := os.ReadFile(specFile)
if err != nil {
return nil, err
}

err = yaml.Unmarshal(contents, &t)
if err != nil {
return nil, err
Expand All @@ -85,6 +87,7 @@ func NewDocumentFile(specFile string) (_ *Document, returnErr error) {

l := openapi3.NewLoader()
l.IsExternalRefsAllowed = true

err = l.ResolveRefsIn(&t, specURL)
if err != nil {
return nil, fmt.Errorf("failed to load %q: %w", specBase, err)
Expand Down
8 changes: 4 additions & 4 deletions document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (

qt "github.com/frankban/quicktest"

"github.com/snyk/vervet/v7"
"github.com/snyk/vervet/v7/testdata"
"github.com/snyk/vervet/v8"
"github.com/snyk/vervet/v8/testdata"
)

func TestNewDocumentFile(t *testing.T) {
c := qt.New(t)
doc, err := vervet.NewDocumentFile(testdata.Path("resources/_examples/hello-world/2021-06-01/spec.yaml"))
c.Assert(err, qt.IsNil)
c.Assert(doc.Paths, qt.HasLen, 1)
c.Assert(doc.Paths["/examples/hello-world/{id}"], qt.Not(qt.IsNil))
c.Assert(doc.Paths.Len(), qt.Equals, 1)
c.Assert(doc.Paths.Value("/examples/hello-world/{id}"), qt.Not(qt.IsNil))
c.Assert(doc.Components.Schemas["HelloWorld"], qt.Not(qt.IsNil))
c.Assert(doc.Validate(context.TODO()), qt.IsNil)
}
4 changes: 2 additions & 2 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"
"text/template"

"github.com/snyk/vervet/v7/config"
"github.com/snyk/vervet/v7/internal/generator"
"github.com/snyk/vervet/v8/config"
"github.com/snyk/vervet/v8/internal/generator"
)

// GeneratorParams contains the metadata needed to execute code generators.
Expand Down
4 changes: 2 additions & 2 deletions generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

qt "github.com/frankban/quicktest"

"github.com/snyk/vervet/v7/generate"
"github.com/snyk/vervet/v7/testdata"
"github.com/snyk/vervet/v8/generate"
"github.com/snyk/vervet/v8/testdata"
)

func TestGenerateFS(t *testing.T) {
Expand Down
31 changes: 15 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/snyk/vervet/v7
module github.com/snyk/vervet/v8

go 1.22

Expand All @@ -14,14 +14,13 @@ require (
github.com/dop251/goja v0.0.0-20231024180952-594410467bc6
github.com/elgohr/go-localstack v1.0.36
github.com/frankban/quicktest v1.14.6
github.com/getkin/kin-openapi v0.120.0
github.com/getkin/kin-openapi v0.127.0
github.com/ghodss/yaml v1.0.0
github.com/go-chi/chi/v5 v5.0.10
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.4.0
github.com/google/uuid v1.6.0
github.com/gorilla/mux v1.8.0
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/reflectwalk v1.0.2
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
Expand All @@ -34,8 +33,8 @@ require (
github.com/urfave/cli/v2 v2.25.7
github.com/vmware-labs/yaml-jsonpath v0.3.2
go.uber.org/multierr v1.11.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.4.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/sync v0.8.0
google.golang.org/api v0.149.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -80,8 +79,8 @@ require (
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -91,7 +90,7 @@ require (
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
Expand Down Expand Up @@ -121,7 +120,7 @@ require (
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand All @@ -138,13 +137,13 @@ require (
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/text v0.17.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
Expand Down
Loading

0 comments on commit 8c6966e

Please sign in to comment.