From 2a9c3fc8d5107f855fe564920c09e28e86fb0656 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 17 Jul 2024 11:07:59 -0700 Subject: [PATCH] made changes with buf library --- go.mod | 6 ++++-- go.sum | 8 ++++++-- rules/aep0155/request_id_format.go | 6 ++---- rules/aep0155/request_id_format_test.go | 2 +- rules/internal/testutils/parse.go | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index e25d960..8545183 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( bitbucket.org/creachadair/stringset v0.0.12 + buf.build/gen/go/aep/api/protocolbuffers/go v1.34.2-20240329195937-b433450cc52f.2 cloud.google.com/go/longrunning v0.5.6 github.com/bmatcuk/doublestar/v4 v4.6.1 github.com/gertd/go-pluralize v0.2.1 @@ -13,20 +14,21 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/pflag v1.0.5 github.com/stoewer/go-strcase v1.3.0 - golang.org/x/text v0.14.0 google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 google.golang.org/genproto/googleapis/api v0.0.0-20240325203815-454cdb8f5daa - google.golang.org/protobuf v1.33.0 + google.golang.org/protobuf v1.34.2 gopkg.in/yaml.v2 v2.4.0 ) require ( + buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240221180331-f05a6f4403ce.2 // indirect github.com/bufbuild/protocompile v0.8.0 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sync v0.6.0 // indirect golang.org/x/sys v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/grpc v1.62.1 // indirect ) diff --git a/go.sum b/go.sum index ff2844e..7bd0d5a 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,9 @@ bitbucket.org/creachadair/stringset v0.0.12 h1:APD8dIoAzGv70a6p1oasPDjPwkp+ajszdgKyWUcNqo0= bitbucket.org/creachadair/stringset v0.0.12/go.mod h1:KtNk2s0hRO1T0r78lv9Zq/S/Lp0du2zI0Fj5j5Y4LDo= +buf.build/gen/go/aep/api/protocolbuffers/go v1.34.2-20240329195937-b433450cc52f.2 h1:0Ka0tKxAfSnJm9sVa7RVtnkTZ8DeTjuNhfHdk0ruLZ8= +buf.build/gen/go/aep/api/protocolbuffers/go v1.34.2-20240329195937-b433450cc52f.2/go.mod h1:7GnupzUM4BaoyPcUUTZZwrcVZvCBNcyn6iR/kddRTuU= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240221180331-f05a6f4403ce.2 h1:Vs037OPnb+uCAQrDAxeGOM8UWvIBhET3hx+ZePssyrQ= +buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240221180331-f05a6f4403ce.2/go.mod h1:ylS4c28ACSI59oJrOdW4pHS4n0Hw4TgSPHn8rpHl4Yw= cloud.google.com/go/longrunning v0.5.6 h1:xAe8+0YaWoCKr9t1+aWe+OeQgN/iJK1fEgZSXmjuEaE= cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= @@ -52,8 +56,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1: google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= diff --git a/rules/aep0155/request_id_format.go b/rules/aep0155/request_id_format.go index 27ab324..6b6a882 100644 --- a/rules/aep0155/request_id_format.go +++ b/rules/aep0155/request_id_format.go @@ -16,7 +16,6 @@ package aep0155 import ( "github.com/aep-dev/api-linter/lint" - "github.com/aep-dev/api-linter/rules/internal/utils" "github.com/jhump/protoreflect/desc" "google.golang.org/protobuf/types/descriptorpb" ) @@ -25,11 +24,10 @@ var requestIdFormat = &lint.FieldRule{ Name: lint.NewRuleName(155, "request-id-format"), RuleType: lint.NewRuleType(lint.MustRule), OnlyIf: func(fd *desc.FieldDescriptor) bool { - return fd.GetName() == "request_id" && - fd.GetType() != descriptorpb.FieldDescriptorProto_TYPE_MESSAGE; + return fd.GetName() == "request_id" }, LintField: func(fd *desc.FieldDescriptor) []lint.Problem { - if(fd.GetMessageType().GetFullyQualifiedName() != "aep.api.IdempotencyKey") { + if(fd.GetType() != descriptorpb.FieldDescriptorProto_TYPE_MESSAGE || fd.GetMessageType().GetFullyQualifiedName() != "aep.api.IdempotencyKey") { return []lint.Problem{{ Message: "The `request_id` field should have type `aep.api.IdempotencyKey`", Descriptor: fd, diff --git a/rules/aep0155/request_id_format_test.go b/rules/aep0155/request_id_format_test.go index 2a275aa..8ffe22e 100644 --- a/rules/aep0155/request_id_format_test.go +++ b/rules/aep0155/request_id_format_test.go @@ -39,7 +39,7 @@ func TestRequestIdFormat(t *testing.T) { name: "InvalidType", FieldName: "request_id", Type: "string", - problems: testutils.Problems{{Message: "format = UUID4"}}, + problems: testutils.Problems{{Message: "type `aep.api.IdempotencyKey`"}}, }, } { t.Run(test.name, func(t *testing.T) { diff --git a/rules/internal/testutils/parse.go b/rules/internal/testutils/parse.go index bd6dbe7..ae01151 100644 --- a/rules/internal/testutils/parse.go +++ b/rules/internal/testutils/parse.go @@ -28,12 +28,12 @@ import ( // These imports cause the common protos to be registered with // the protocol buffer registry, and therefore make the call to // `proto.FileDescriptor` work for the imported files. + _ "buf.build/gen/go/aep/api/protocolbuffers/go/aep/api" _ "cloud.google.com/go/longrunning/autogen/longrunningpb" _ "google.golang.org/genproto/googleapis/api/annotations" _ "google.golang.org/genproto/googleapis/type/date" _ "google.golang.org/genproto/googleapis/type/datetime" _ "google.golang.org/genproto/googleapis/type/timeofday" - // TODO: Add aep to genproto to make linter tests pass. ) // ParseProtoStrings parses a map representing a proto files, and returns