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

feat(bazel): Add rule for generating .swagger.json files #613

Merged
merged 10 commits into from
Apr 25, 2018

Conversation

mrmeku
Copy link
Contributor

@mrmeku mrmeku commented Apr 24, 2018

Wraps protoc and protoc-gen-swagger in a bazel rule so that other rules can depend upon the output

@achew22
Copy link
Collaborator

achew22 commented Apr 24, 2018

@f0rmiga I don't think you have to write the swagger rule any more 😉, great work @mrmeku!

@f0rmiga
Copy link
Contributor

f0rmiga commented Apr 24, 2018

That is neat!

Copy link
Contributor

@f0rmiga f0rmiga left a comment

Choose a reason for hiding this comment

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

Could you rename from protoc-gen-swagger.bzl to defs.bzl? Seems repetitive since it is already in the protoc-gen-swagger folder. Naming it defs.bzl is a good practice that folks have been using in other repos.

Copy link
Contributor

@f0rmiga f0rmiga left a comment

Choose a reason for hiding this comment

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

Could you also format the .bzl file to use 4 spaces indentation and , at the end of each line in a list or multi-line parameter set?

@f0rmiga
Copy link
Contributor

f0rmiga commented Apr 24, 2018

@achew22 I sent you a message about that in the Go Slack channel, but I guess you didn't see that.

@achew22
Copy link
Collaborator

achew22 commented Apr 24, 2018

@f0rmiga, I mentioned you on the PR because I saw that message but I only got notified a few hours ago. Sorry if there was any overlapping work here.

@f0rmiga
Copy link
Contributor

f0rmiga commented Apr 24, 2018

@achew22 No worries! No overlapping work here. Nice work @mrmeku!

@mrmeku
Copy link
Contributor Author

mrmeku commented Apr 24, 2018

@f0rmiga I think I'm done! Let me know if you have anything you can see that you'd like cleaned up


filegroup(
name = "googleapis",
srcs = glob(["**/*.proto"])
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Missing ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TY

cfg = "host",
),
"_googleapis": attr.label(
default = Label("@grpc_ecosystem_grpc_gateway//third_party/googleapis:googleapis"),
Copy link
Contributor

Choose a reason for hiding this comment

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

When I added the Bazel support initially I created the repositories.bzl that creates the @com_github_googleapis_googleapis repository target. The purpose of that repository target is to avoid using the .proto files under third_party. Could you try to use that repository target instead?

args.add("--plugin=%s" % protoc_gen_swagger.path)
args.add("--swagger_out=logtostderr=true:%s" % swagger_file.dirname)
args.add("-Iexternal/com_google_protobuf/src")
args.add("-Iexternal/grpc_ecosystem_grpc_gateway/third_party/googleapis/")
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be tricky to get the include directory for the protos from the repository target. Let me know if you have any questions regarding that.


protoc_gen_swagger = rule(
attrs = {
"proto_service": attr.label(
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of taking the .proto file, I think it would be better to take a proto_library so it is consistent on how the go_proto_library works. Take a look at the implementation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Donezo

Copy link
Contributor

Choose a reason for hiding this comment

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

You could rename to proto instead of proto_service.

@@ -19,6 +19,7 @@ go_library(
go_binary(
name = "protoc-gen-swagger",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why you need to set the visibility to be public here.

Copy link
Contributor Author

@mrmeku mrmeku Apr 24, 2018

Choose a reason for hiding this comment

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

This binary is now an implicit dependency of protoc_gen_swagger since it is listed as the default label for the _protoc_gen_swagger attribute of that rule. Since the protoc_gen_swagger rule is intended to be public, the dep itself needs to be publicly exposed

Copy link
Contributor

@f0rmiga f0rmiga left a comment

Choose a reason for hiding this comment

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

You don't need third_party/googleapis/BUILD.bazel anymore.

@mrmeku
Copy link
Contributor Author

mrmeku commented Apr 24, 2018

Good point!


protoc_gen_swagger(
name = "expamplepb_protoc_gen_swagger",
proto_service = "a_bit_of_everything.proto",
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to change to proto = ":examplepb_proto",. If you do, then you will get a bunch of errors, because the output of the proto_library is a list of proto descriptors in .bin files. So you will need to use a Provider to grab the .proto files from the src list in the proto_library.

attrs = {
"proto": attr.label(
mandatory = True,
allow_single_file = True,
Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to remove this to accept a Label instead of files. From that Label you will extract the src files using a Provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Donezo


protoc_gen_swagger = rule(
attrs = {
"deps": attr.label_list(
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think this should be called proto, not deps. You also don't need it to be a label_list.

@codecov-io
Copy link

Codecov Report

Merging #613 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #613   +/-   ##
=======================================
  Coverage   59.28%   59.28%           
=======================================
  Files          28       28           
  Lines        2780     2780           
=======================================
  Hits         1648     1648           
  Misses        971      971           
  Partials      161      161

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 892952a...c5b759c. Read the comment docs.

@achew22 achew22 merged commit 739cd2d into grpc-ecosystem:master Apr 25, 2018
@f0rmiga
Copy link
Contributor

f0rmiga commented Apr 25, 2018

Good job @mrmeku! Thank you for your patience in the review. I appreciate it.

@ensonic
Copy link
Contributor

ensonic commented Apr 27, 2018

Nice, is a support for proto options? E.g. #521 introduced: "grpc_api_configuration=path/to/your_api_config.yaml".

@achew22
Copy link
Collaborator

achew22 commented Apr 27, 2018

No it isn't supported yet but it would be an easy pull request to add the functionality. Give it a go and send in whatever you can get working. I'll help you if you get stuck

@ensonic
Copy link
Contributor

ensonic commented Apr 30, 2018

Sound good, I am on it. See #632

adasari pushed a commit to adasari/grpc-gateway that referenced this pull request Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants