-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
b4553e8
to
83b7a7b
Compare
That is neat! |
There was a problem hiding this 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.
There was a problem hiding this 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?
@achew22 I sent you a message about that in the Go Slack channel, but I guess you didn't see that. |
@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 I think I'm done! Let me know if you have anything you can see that you'd like cleaned up |
third_party/googleapis/BUILD.bazel
Outdated
|
||
filegroup( | ||
name = "googleapis", | ||
srcs = glob(["**/*.proto"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Missing ,
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TY
a20f0df
to
1471505
Compare
protoc-gen-swagger/defs.bzl
Outdated
cfg = "host", | ||
), | ||
"_googleapis": attr.label( | ||
default = Label("@grpc_ecosystem_grpc_gateway//third_party/googleapis:googleapis"), |
There was a problem hiding this comment.
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?
protoc-gen-swagger/defs.bzl
Outdated
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/") |
There was a problem hiding this comment.
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/defs.bzl
Outdated
|
||
protoc_gen_swagger = rule( | ||
attrs = { | ||
"proto_service": attr.label( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Donezo
There was a problem hiding this comment.
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"], |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
Good point! |
examples/examplepb/BUILD.bazel
Outdated
|
||
protoc_gen_swagger( | ||
name = "expamplepb_protoc_gen_swagger", | ||
proto_service = "a_bit_of_everything.proto", |
There was a problem hiding this comment.
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
.
protoc-gen-swagger/defs.bzl
Outdated
attrs = { | ||
"proto": attr.label( | ||
mandatory = True, | ||
allow_single_file = True, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Donezo
c21f729
to
e48a7ae
Compare
protoc-gen-swagger/defs.bzl
Outdated
|
||
protoc_gen_swagger = rule( | ||
attrs = { | ||
"deps": attr.label_list( |
There was a problem hiding this comment.
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
.
caddba1
to
c5b759c
Compare
Codecov Report
@@ 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.
|
Good job @mrmeku! Thank you for your patience in the review. I appreciate it. |
Nice, is a support for proto options? E.g. #521 introduced: "grpc_api_configuration=path/to/your_api_config.yaml". |
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 |
Sound good, I am on it. See #632 |
Wraps protoc and protoc-gen-swagger in a bazel rule so that other rules can depend upon the output