diff --git a/.travis.yml b/.travis.yml index c294631..eb93a09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,12 @@ sudo: false language: go +go: + - "1.13" + script: + # This statement installs the binary of gnostic and makes it available in $PATH. The binary + # is needed in one of the methods. Therefore, we explicitly need this statement. - go get github.com/googleapis/gnostic - go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic diff --git a/generator/checker_test.go b/generator/checker_test.go index 93a7b7b..1c37e47 100644 --- a/generator/checker_test.go +++ b/generator/checker_test.go @@ -23,7 +23,11 @@ import ( func TestNewFeatureCheckerParameters(t *testing.T) { input := "testfiles/parameters.yaml" - documentv3 := readOpenAPIBinary(input) + documentv3, err := ParseOpenAPIDoc(input) + if err != nil { + t.Errorf("Error while parsing input file: %s", input) + return + } checker := NewGrpcChecker(documentv3) messages := checker.Run() @@ -39,7 +43,11 @@ func TestNewFeatureCheckerParameters(t *testing.T) { func TestFeatureCheckerRequestBodies(t *testing.T) { input := "testfiles/requestBodies.yaml" - documentv3 := readOpenAPIBinary(input) + documentv3, err := ParseOpenAPIDoc(input) + if err != nil { + t.Errorf("Error while parsing input file: %s", input) + return + } checker := NewGrpcChecker(documentv3) messages := checker.Run() @@ -54,7 +62,11 @@ func TestFeatureCheckerRequestBodies(t *testing.T) { func TestFeatureCheckerResponses(t *testing.T) { input := "testfiles/responses.yaml" - documentv3 := readOpenAPIBinary(input) + documentv3, err := ParseOpenAPIDoc(input) + if err != nil { + t.Errorf("Error while parsing input file: %s", input) + return + } checker := NewGrpcChecker(documentv3) messages := checker.Run() @@ -69,7 +81,11 @@ func TestFeatureCheckerResponses(t *testing.T) { func TestFeatureCheckerOther(t *testing.T) { input := "testfiles/other.yaml" - documentv3 := readOpenAPIBinary(input) + documentv3, err := ParseOpenAPIDoc(input) + if err != nil { + t.Errorf("Error while parsing input file: %s", input) + return + } checker := NewGrpcChecker(documentv3) messages := checker.Run() @@ -96,9 +112,12 @@ func validateKeys(t *testing.T, expectedKeys [][]string, messages []*plugins.Mes } } -func readOpenAPIBinary(input string) *openapiv3.Document { +func ParseOpenAPIDoc(input string) (*openapiv3.Document, error) { cmd := exec.Command("gnostic", "--pb-out=-", input) - b, _ := cmd.Output() - documentv3, _ := createOpenAPIDocFromGnosticOutput(b) - return documentv3 + b, err := cmd.Output() + if err != nil { + return nil, err + } + documentv3, err := createOpenAPIDocFromGnosticOutput(b) + return documentv3, err } diff --git a/generator/language.go b/generator/language.go index 13a82a2..0daa38d 100644 --- a/generator/language.go +++ b/generator/language.go @@ -14,10 +14,11 @@ package generator import ( - surface_v1 "github.com/googleapis/gnostic/surface" "regexp" "strconv" "strings" + + surface_v1 "github.com/googleapis/gnostic/surface" ) type ProtoLanguageModel struct{} @@ -60,7 +61,14 @@ func findNativeType(fType string, fFormat string) string { case "boolean": return "bool" case "number": - return "int32" + switch fFormat { + case "float": + return "float" + case "double": + return "double" + default: + return "float" + } case "integer": switch fFormat { case "int32": diff --git a/generator/renderer_test.go b/generator/renderer_test.go index 3ee7e0b..12d35d1 100644 --- a/generator/renderer_test.go +++ b/generator/renderer_test.go @@ -18,7 +18,6 @@ import ( surface "github.com/googleapis/gnostic/surface" "io/ioutil" "os" - "os/exec" "path" "path/filepath" "strings" @@ -112,9 +111,10 @@ func runGeneratorWithoutEnvironment(input string, packageName string) ([]byte, e } func buildSurfaceModel(input string) (*surface.Model, error) { - cmd := exec.Command("gnostic", "--pb-out=-", input) - b, _ := cmd.Output() - documentv3, _ := createOpenAPIDocFromGnosticOutput(b) + documentv3, err := ParseOpenAPIDoc(input) + if err != nil { + return nil, err + } surfaceModel, err := surface.NewModelFromOpenAPI3(documentv3, input) return surfaceModel, err } diff --git a/generator/testfiles/goldstandard/other.proto b/generator/testfiles/goldstandard/other.proto index 9e65e49..cdb3e0b 100644 --- a/generator/testfiles/goldstandard/other.proto +++ b/generator/testfiles/goldstandard/other.proto @@ -20,6 +20,12 @@ message Person { string name = 3; repeated string photo_urls = 4; + + float height = 5; + + double cash = 6; + + float iq = 7; } message TestExernalReference2Parameters { diff --git a/generator/testfiles/other.yaml b/generator/testfiles/other.yaml index 4c0aa15..1595ebe 100644 --- a/generator/testfiles/other.yaml +++ b/generator/testfiles/other.yaml @@ -90,4 +90,12 @@ components: name: photoUrl wrapped: true items: - type: string \ No newline at end of file + type: string + height: + type: number + cash: + type: number + format: double + iq: + type: number + format: float \ No newline at end of file diff --git a/go.mod b/go.mod index 55caa27..7b2886b 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.13 require ( github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/golang/protobuf v1.4.2 - github.com/googleapis/gnostic v0.4.2-0.20200520192801-89741bb7d0e0 + github.com/googleapis/gnostic v0.5.1 github.com/grpc-ecosystem/grpc-gateway v1.12.2 github.com/jhump/protoreflect v1.6.0 golang.org/x/net v0.0.0-20191002035440-2ec189313ef0 diff --git a/go.sum b/go.sum index fb9b874..eaac101 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= @@ -34,6 +35,8 @@ github.com/googleapis/gnostic v0.4.2-0.20200519195951-57a06a8ff3b3 h1:lH+GwKj0oE github.com/googleapis/gnostic v0.4.2-0.20200519195951-57a06a8ff3b3/go.mod h1:66LN4oFEjss7jBuyFHfz9jIXKCPM+TQnz5GybKvhVQI= github.com/googleapis/gnostic v0.4.2-0.20200520192801-89741bb7d0e0 h1:qM69YZMWsPLR3GyzAcQPjwONfVC+eqKtHOLc2hWyJvs= github.com/googleapis/gnostic v0.4.2-0.20200520192801-89741bb7d0e0/go.mod h1:66LN4oFEjss7jBuyFHfz9jIXKCPM+TQnz5GybKvhVQI= +github.com/googleapis/gnostic v0.5.1 h1:A8Yhf6EtqTv9RMsU6MQTyrtV1TjWlR6xU9BsZIwuTCM= +github.com/googleapis/gnostic v0.5.1/go.mod h1:6U4PtQXGIEt/Z3h5MAT7FNofLnw9vXk2cUuW7uA/OeU= github.com/grpc-ecosystem/grpc-gateway v1.12.2 h1:D0EVSTwQoQOyfY35QNSuPJA4jpZRtkoGYWQMB7XNg5o= github.com/grpc-ecosystem/grpc-gateway v1.12.2/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE= @@ -43,8 +46,12 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -107,5 +114,7 @@ gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=