Skip to content

Commit

Permalink
Adds grpc_gateway_swagger_compile.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcj committed Sep 14, 2016
1 parent e21c8e3 commit 84f5b46
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 8 deletions.
33 changes: 33 additions & 0 deletions bzl/build_file/com_github_grpc_ecosystem_grpc_gateway.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,36 @@ go_library(
"@com_github_golang_protobuf//:protoc-gen-go/plugin",
],
)

go_binary(
name = "protoc-gen-swagger_bin",
srcs = [
"protoc-gen-swagger/main.go",
],
deps = [
"protoc-gen-grpc-gateway/descriptor",
"protoc-gen-swagger/genswagger",
"@com_github_golang_glog//:go_default_library",
"@com_github_golang_protobuf//:proto",
"@com_github_golang_protobuf//:protoc-gen-go/plugin",
],
)


go_library(
name = "protoc-gen-swagger/genswagger",
srcs = [
"protoc-gen-swagger/genswagger/doc.go",
"protoc-gen-swagger/genswagger/generator.go",
"protoc-gen-swagger/genswagger/template.go",
"protoc-gen-swagger/genswagger/types.go",
],
deps = [
"protoc-gen-grpc-gateway/descriptor",
"protoc-gen-grpc-gateway/generator",
"@com_github_golang_glog//:go_default_library",
"@com_github_golang_protobuf//:proto",
"@com_github_golang_protobuf//:protoc-gen-go/plugin",
"@com_github_golang_protobuf//:protoc-gen-go/descriptor",
],
)
3 changes: 2 additions & 1 deletion bzl/classes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ load("//bzl:ruby/class.bzl", RUBY = "CLASS")
load("//bzl:java/class.bzl", JAVA = "CLASS")
load("//bzl:javanano/class.bzl", JAVANANO = "CLASS")
load("//bzl:js/class.bzl", JS = "CLASS")
load("//bzl:grpc_gateway/class.bzl", GATEWAY = "CLASS")
load("//bzl:grpc_gateway/class.bzl", GATEWAY = "CLASS", "SWAGGER")

CLASSES = {
BASE.name: BASE,
CPP.name: CPP,
CSHARP.name: CSHARP,
GATEWAY.name: GATEWAY,
SWAGGER.name: SWAGGER,
JAVA.name: JAVA,
JAVANANO.name: JAVANANO,
JS.name: JS,
Expand Down
1 change: 1 addition & 0 deletions bzl/grpc_gateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| `grpc_gateway_proto_compile` | Generates protobuf source files. |
| `grpc_gateway_proto_library` | Generates and compiles protobuf source files. |
| `grpc_gateway_binary` | Generates everything into a gateway binary. |
| `grpc_gateway_swagger_compile` | Generates swagger json files. |

## Installation

Expand Down
32 changes: 32 additions & 0 deletions bzl/grpc_gateway/class.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def implement_compile_attributes(lang, self):
)



def build_imports(lang, self):
invokesuper("build_imports", lang, self)
ctx = self["ctx"]
Expand Down Expand Up @@ -105,10 +106,41 @@ CLASS = struct(
],
),

swagger = struct(
name = 'protoc-gen-swagger',
file_extensions = [".pb.gw.json"],
executable = "@com_github_grpc_ecosystem_grpc_gateway//:protoc-gen-swagger",
default_options = GO.grpc.default_options,
requires = [
"com_github_grpc_ecosystem_grpc_gateway",
],
),

implement_compile_attributes = implement_compile_attributes,
build_protobuf_out = build_protobuf_out,
build_grpc_out = build_grpc_out,
build_imports = build_imports,
build_inputs = build_inputs,
library = GO.library,
)

SWAGGER = struct(
parent = BASE,
name = "swagger",

default_go_import_map = CLASS.default_go_import_map,
default_imports = CLASS.default_imports,

protobuf = struct(
name = 'protoc-gen-swagger',
file_extensions = [".swagger.json"],
executable = "@com_github_grpc_ecosystem_grpc_gateway//:protoc-gen-swagger_bin",
requires = [
"com_github_grpc_ecosystem_grpc_gateway",
],
),

implement_compile_attributes = implement_compile_attributes,
build_imports = build_imports,
build_inputs = build_inputs,
)
3 changes: 2 additions & 1 deletion bzl/grpc_gateway/rules.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_binary")
load("//bzl:base/rules.bzl", "proto_library")
load("//bzl:go/class.bzl", GO = "CLASS")
load("//bzl:grpc_gateway/class.bzl", GATEWAY = "CLASS")
load("//bzl:grpc_gateway/class.bzl", GATEWAY = "CLASS", "SWAGGER")
load("//bzl:protoc.bzl", "PROTOC", "implement")

SPEC = [GO, GATEWAY]

grpc_gateway_proto_compile = implement(SPEC)
grpc_gateway_swagger_compile = implement([SWAGGER])

def grpc_gateway_proto_library(
name,
Expand Down
19 changes: 16 additions & 3 deletions examples/helloworld/grpc_gateway/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ load(
"//bzl:go/class.bzl",
GO = "CLASS",
)

load(
"//bzl:grpc_gateway/class.bzl",
GRPC_GATEWAY = "CLASS",
GRPC_SWAGGER = "SWAGGER",
)

load(
"//bzl:grpc_gateway/rules.bzl",
"grpc_gateway_swagger_compile",
"grpc_gateway_proto_library",
"grpc_gateway_binary",
)
load("//bzl:grpc_gateway/rules.bzl", "grpc_gateway_proto_library", "grpc_gateway_binary")

go_test(
name = "greeter_test",
Expand All @@ -26,15 +34,20 @@ go_test(
] + GRPC_GATEWAY.grpc.compile_deps,
)

# Alternate form to grpc_gateway_binary
#
grpc_gateway_proto_library(
name = "gateway",
output_to_workspace = False,
protos = ["helloworld.proto"],
verbose = 1,
)

grpc_gateway_swagger_compile(
name = "swagger",
output_to_workspace = False,
protos = ["helloworld.proto"],
verbose = 1,
)

# grpc_gateway_binary(
# name = "greeter",
# srcs = ["greeter.go"],
Expand Down
3 changes: 1 addition & 2 deletions examples/helloworld/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ java_proto_library(
with_grpc = True,
)


js_proto_compile(
name = "js",
protos = [":protos"],
proto_deps = [
"//examples/proto:js",
],
protos = [":protos"],
verbose = 1,
)
1 change: 0 additions & 1 deletion examples/proto/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ load("//bzl:java/rules.bzl", "java_proto_library")
load("//bzl:ruby/rules.bzl", "ruby_proto_library")
load("//bzl:js/rules.bzl", "js_proto_compile")


filegroup(
name = "protos",
srcs = [
Expand Down

0 comments on commit 84f5b46

Please sign in to comment.