Skip to content

Commit

Permalink
float and double support (#26)
Browse files Browse the repository at this point in the history
* float and double support

* Changing Travis go version to 1.13

* Removing dead code

* - Added comment that explains why we need to go get gnostic explicitly
- Update go.mod to use a tagged version of gnostic

* Adding better error handling in test files and refactoring duplicated code

* Adding properties to test different types

Co-authored-by: LorenzHW <[email protected]>
  • Loading branch information
fideltak and LorenzHW committed Sep 4, 2020
1 parent a3a34ce commit 08a1ff8
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 27 additions & 8 deletions generator/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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
}
12 changes: 10 additions & 2 deletions generator/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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":
Expand Down
8 changes: 4 additions & 4 deletions generator/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
surface "github.com/googleapis/gnostic/surface"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions generator/testfiles/goldstandard/other.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion generator/testfiles/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ components:
name: photoUrl
wrapped: true
items:
type: string
type: string
height:
type: number
cash:
type: number
format: double
iq:
type: number
format: float
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=

0 comments on commit 08a1ff8

Please sign in to comment.