Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'License' message to the annotation proto. #644

Merged
merged 2 commits into from
Nov 5, 2018

Conversation

ensonic
Copy link
Contributor

@ensonic ensonic commented May 8, 2018

This information is used by the default html doc generator and so it is nice
to be able to provide it.

@ensonic
Copy link
Contributor Author

ensonic commented May 8, 2018

Just realize this is only the first step, we track down, what needs to be done to make this appear in the final json too.

@ensonic
Copy link
Contributor Author

ensonic commented May 8, 2018

Now it should be good to go.

@ensonic
Copy link
Contributor Author

ensonic commented May 8, 2018

Hi, I only get the bazel build to work.
When I try to build with make, I get errors:
https://gist.github.com/ensonic/173b3cfb6032ee730320729d356f8534

@@ -784,6 +784,17 @@ func applyTemplate(p param) (string, error) {
s.Info.Contact.Email = spb.Info.Contact.Email
}
}
if spb.Info.License != nil {
if s.Info.License == nil {
s.Info.License = &swaggerLicenseObject{}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add the License field to the Info object. I'm surprised this isn't a compile time error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be generated from "message Info" define in openapiv2.proto? Also when I build it with bazel it actually works. I am getting the license fields in the generated json.

@ensonic
Copy link
Contributor Author

ensonic commented May 11, 2018

Update when I run 'make test' localy I get:

go test -race github.com/grpc-ecosystem/grpc-gateway/...
warning: ignoring symlink /usr/local/google/home/ensonic/go/src/github.com/grpc-ecosystem/grpc-gateway/bazel-bin
warning: ignoring symlink /usr/local/google/home/ensonic/go/src/github.com/grpc-ecosystem/grpc-gateway/bazel-genfiles
warning: ignoring symlink /usr/local/google/home/ensonic/go/src/github.com/grpc-ecosystem/grpc-gateway/bazel-grpc-gateway
warning: ignoring symlink /usr/local/google/home/ensonic/go/src/github.com/grpc-ecosystem/grpc-gateway/bazel-out
warning: ignoring symlink /usr/local/google/home/ensonic/go/src/github.com/grpc-ecosystem/grpc-gateway/bazel-testlogs
# google.golang.org/grpc/grpclb/grpc_lb_v1/messages
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:59:30: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:112:31: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:160:40: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:302:47: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:358:33: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:441:41: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:590:48: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:639:32: undefined: proto.InternalMessageInfo
../../../google.golang.org/grpc/grpclb/grpc_lb_v1/messages/messages.pb.go:698:28: undefined: proto.InternalMessageInfo
ok  	github.com/grpc-ecosystem/grpc-gateway/codegenerator	0.541s
# github.com/grpc-ecosystem/grpc-gateway/examples/clients/abe
examples/clients/abe/examplepb_a_bit_of_everything.go:47:13: undefined: ExamplepbNumericEnum
examples/clients/abe/examplepb_a_bit_of_everything.go:63:22: undefined: ExamplepbNumericEnum
examples/clients/abe/examplepb_a_bit_of_everything.go:73:22: undefined: ExamplepbNumericEnum
FAIL	github.com/grpc-ecosystem/grpc-gateway/examples/integration [build failed]
ok  	github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor	0.569s
ok  	github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/gengateway	0.590s
ok  	github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule	0.556s
ok  	github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger	0.549s
ok  	github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/genswagger	0.554s
FAIL	github.com/grpc-ecosystem/grpc-gateway/runtime [build failed]
ok  	github.com/grpc-ecosystem/grpc-gateway/utilities	0.549s
Makefile:169: recipe for target 'test' failed
make: *** [test] Error 2
``
Looks like https://github.com/google/protobuf/issues/4582. Will investigate.
In any case those are different than what travis reported and don't seem to be related to my change.

@ensonic
Copy link
Contributor Author

ensonic commented May 16, 2018

Hi, I really need help to understand why the tests fail. What exactly should I run locally to build/run not using bazel. I have the git rooted in my gopath:
/home/ensonic/go/src/github.com/grpc-ecosystem/grpc-gateway

@achew22
Copy link
Collaborator

achew22 commented May 17, 2018

Did you try regenerating the openapiv2.pb.go file that is generated from the proto? It looks like we don't have an entry in the Makefile for it. Would you mind adding a new line in the $(SWAGGER_PLUGIN) section of the makefile to invoke protoc like:

protoc -I $(PROTOC_INC_PATH) -I. --plugin=$(GO_PLUGIN) --go_out=$(PKGMAP),plugins=grpc:$(OUTPUT_DIR) $(PROTOFILE)

@ensonic
Copy link
Contributor Author

ensonic commented May 17, 2018

No, there is the dependent rule
$(OPENAPIV2_GO): $(OPENAPIV2_PROTO) $(GO_PLUGIN)
protoc -I $(PROTOC_INC_PATH) --plugin=$(GO_PLUGIN) -I. --go_out=$(PKGMAP):$(GOPATH)/src $(OPENAPIV2_PROTO)

which builds protoc-gen-swagger/options/openapiv2.proto protoc-gen-swagger/options/annotations.proto and produces the respective '.pb.go' files.

make protoc-gen-swagger/options/openapiv2.pb.go
make: 'protoc-gen-swagger/options/openapiv2.pb.go' is up to date.

I've fixed one test by updating proto-gen-go (go get -u github.com/golang/protobuf/protoc-gen-go).

For the "github.com/grpc-ecosystem/grpc-gateway/examples/integration" you seem to have a mix of using the new "context" and the old "golang.org/x/net/context". I don't know how to resolve that.

https://gist.github.com/ensonic/1ddd754610de01ed99bb55ab52c7579b

FYI: I also get

FAIL	github.com/grpc-ecosystem/grpc-gateway/examples/integration [build failed]

without my change (using go version go1.10.2 linux/amd64). We will just use my fork for now, but I'd love to understand why your Go1.10.X builders would work and mine doesn't (also other PRs seem to have the same problem). Maybe consider adding some docs to make life for contributors easier.

@johanbrandhorst
Copy link
Collaborator

Hi @ensonic, we're made some changes to CI since you first had these problems, want to rebase and give it another go?

@johanbrandhorst
Copy link
Collaborator

Please rebase on master for new CI functionality.

This information is used by the default html doc generator and so it is nice
to be able to provide it.

Add the message to openapiv2.proto and extend template.go to handle it.

Tested via:
bazel build //examples/proto/examplepb:expamplepb_protoc_gen_swagger
more bazel-bin/examples/proto/examplepb/a_bit_of_everything.swagger.json
@ensonic
Copy link
Contributor Author

ensonic commented Nov 5, 2018

Still the same. For using it with bazel I can simply run: bazel test //... and it passes:

INFO: Elapsed time: 55.135s, Critical Path: 25.99s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 515 processes: 515 linux-sandbox.
INFO: Build completed successfully, 558 total actions
//codegenerator:go_default_xtest                                         PASSED in 0.2s
//examples/integration:go_default_xtest                                  PASSED in 0.6s
//protoc-gen-grpc-gateway/descriptor:go_default_test                     PASSED in 0.2s
//protoc-gen-grpc-gateway/gengateway:go_default_test                     PASSED in 0.2s
//protoc-gen-grpc-gateway/httprule:go_default_test                       PASSED in 0.2s
//protoc-gen-swagger:go_default_test                                     PASSED in 0.2s
//protoc-gen-swagger/genswagger:go_default_test                          PASSED in 0.2s
//runtime:go_default_test                                                PASSED in 0.2s
//runtime:go_default_xtest                                               PASSED in 0.2s
//utilities:go_default_xtest                                             PASSED in 0.2s

Executed 10 out of 10 tests: 10 tests pass.
INFO: Build completed successfully, 558 total actions

Running make test still fails for me with some error:

make test
mkdir -p _output
protoc -I /usr/bin//../include -I. --plugin=bin/protoc-gen-go --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mexamples/proto/sub/message.proto=github.com/grpc-ecosystem/grpc-gateway/examples/proto/sub,plugins=grpc:_output examples/proto/sub/message.proto
cp _output/github.com/grpc-ecosystem/grpc-gateway/examples/proto/sub/message.pb.go examples/proto/sub/message.pb.go || cp _output/examples/proto/sub/message.pb.go examples/proto/sub/message.pb.go
cp: cannot stat '_output/github.com/grpc-ecosystem/grpc-gateway/examples/proto/sub/message.pb.go': No such file or directory
mkdir -p _output
protoc -I /usr/bin//../include -I. --plugin=bin/protoc-gen-go --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mexamples/proto/sub/message.proto=github.com/grpc-ecosystem/grpc-gateway/examples/proto/sub,plugins=grpc:_output examples/proto/sub2/message.proto
cp _output/github.com/grpc-ecosystem/grpc-gateway/examples/proto/sub2/message.pb.go examples/proto/sub2/message.pb.go || cp _output/examples/proto/sub2/message.pb.go examples/proto/sub2/message.pb.go
protoc -I /usr/bin//../include -I. -Ithird_party/googleapis --plugin=bin/protoc-gen-go --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor,Mexamples/proto/sub/message.proto=github.com/grpc-ecosystem/grpc-gateway/examples/proto/sub,plugins=grpc:. examples/proto/examplepb/echo_service.proto examples/proto/examplepb/a_bit_of_everything.proto examples/proto/examplepb/stream.proto examples/proto/examplepb/flow_combination.proto examples/proto/examplepb/wrappers.proto examples/proto/examplepb/unannotated_echo_service.proto examples/proto/examplepb/response_body_service.proto
go build -o bin/protoc-gen-grpc-gateway github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
# github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor
protoc-gen-grpc-gateway/descriptor/services.go:146:49: opts.ResponseBody undefined (type *annotations.HttpRule has no field or method ResponseBody)
Makefile:139: recipe for target 'bin/protoc-gen-grpc-gateway' failed

For the CI errors it looks like protoc-gen-swagger/options/openapiv2.pb.go needs to be re-generated, but your non-bazel build setup does not take care of it.

@johanbrandhorst
Copy link
Collaborator

Interesting, is that because of a dependency update or something? Would you be interested in submitting a PR to regenerate the file, or, regenerate it in this PR?

@johanbrandhorst
Copy link
Collaborator

So if you look at our CI tests it's actually saying that you still need to regenerate things. Bazel doesn't use the generated files in the same way (apparently) but we still need them. The License type needs to be added to the generated file.

@johanbrandhorst
Copy link
Collaborator

Don't run just make test locally, please regenerate the files as per the contribution guidelines: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/CONTRIBUTING.md#i-want-to-regenerate-the-files-after-making-changes

@ensonic
Copy link
Contributor Author

ensonic commented Nov 5, 2018

This looks better. The part about regenerating files should be one of the commands in 'how-to-contribute' and should be done before sending a PR :)

@codecov-io
Copy link

Codecov Report

Merging #644 into master will decrease coverage by 0.11%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #644      +/-   ##
==========================================
- Coverage   53.39%   53.27%   -0.12%     
==========================================
  Files          30       30              
  Lines        3362     3369       +7     
==========================================
  Hits         1795     1795              
- Misses       1392     1399       +7     
  Partials      175      175
Impacted Files Coverage Δ
protoc-gen-swagger/genswagger/template.go 38.39% <0%> (-0.3%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dfdde99...6cc7699. Read the comment docs.

@johanbrandhorst johanbrandhorst merged commit 844b78d into grpc-ecosystem:master Nov 5, 2018
@johanbrandhorst
Copy link
Collaborator

Nice one, thanks!

@ensonic
Copy link
Contributor Author

ensonic commented Nov 5, 2018

Sorry for being such a pain to get this in and thanks for merging!

@johanbrandhorst
Copy link
Collaborator

Thanks for the contribution :). Our old CI system was largely to blame, unfortunately there's still lots of good contributions like this laying around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants