11$(VERBOSE ) .SILENT :
22# ############################ Main targets #############################
3- ci-build : install proto
3+ ci-build : install proto http-api-docs
44
55# Install dependencies.
66install : grpc-install api-linter-install buf-install
77
88# Run all linters and compile proto files.
9- proto : grpc
9+ proto : grpc http-api-docs
1010# #######################################################################
1111
1212# #### Variables ######
@@ -38,6 +38,9 @@ PROTO_IMPORTS = \
3838 -I=$(PROTO_ROOT )
3939PROTO_PATHS = paths=source_relative:$(PROTO_OUT )
4040
41+ OAPI_OUT := openapi
42+ OAPI3_PATH := .components.schemas.Payload
43+
4144$(PROTO_OUT ) :
4245 mkdir $(PROTO_OUT )
4346
@@ -46,23 +49,44 @@ grpc: buf-lint api-linter buf-breaking clean go-grpc fix-path
4649
4750go-grpc : clean $(PROTO_OUT )
4851 printf $(COLOR ) " Compile for go-gRPC..."
49- $(foreach PROTO_DIR,$(PROTO_DIRS ) ,\
50- protoc --fatal_warnings $(PROTO_IMPORTS ) \
51- --go_out=$(PROTO_PATHS ) \
52- --grpc-gateway_out=allow_patch_feature =false,$(PROTO_PATHS ) \
53- --doc_out=html,index.html,source_relative:$(PROTO_OUT ) \
54- $(PROTO_DIR ) *.proto;)
52+ protogen \
53+ --root=$(PROTO_ROOT ) \
54+ --output=$(PROTO_OUT ) \
55+ --exclude=internal \
56+ --exclude=proto/api/google \
57+ -I $(PROTO_ROOT ) \
58+ -p go-grpc_out=$(PROTO_PATHS ) \
59+ -p grpc-gateway_out=allow_patch_feature=false,$(PROTO_PATHS ) \
60+ -p doc_out=html,index.html,source_relative:$(PROTO_OUT ) \
61+ -p openapi_out=$(OAPI_OUT ) \
62+ -p openapi_opt=enum_type=string \
63+ -p openapiv2_out=openapi \
64+ -p openapiv2_opt=allow_merge=true,merge_file_name=openapiv2
5565
5666fix-path :
5767 mv -f $(PROTO_OUT ) /temporal/api/* $(PROTO_OUT ) && rm -rf $(PROTO_OUT ) /temporal
5868
69+ # We need to rewrite bits of this to support our shorthand payload format
70+ # We use both yq and jq here as they preserve comments and the ordering of the original
71+ # document
72+ http-api-docs : go-grpc
73+ jq --rawfile desc $(OAPI_OUT ) /payload_description.txt < $(OAPI_OUT ) /openapiv2.swagger.json ' .definitions.v1Payload={description: $$desc}' > $(OAPI_OUT ) /v2.tmp
74+ mv -f $(OAPI_OUT ) /v2.tmp $(OAPI_OUT ) /openapiv2.json
75+ rm -f $(OAPI_OUT ) /openapiv2.swagger.json
76+ DESC=$$(cat $(OAPI_OUT ) /payload_description.txt ) yq e -i ' $(OAPIV3_PATH).description = strenv(DESC) | del($(OAPI3_PATH).type) | del($(OAPI3_PATH).properties)' $(OAPI_OUT ) /openapi.yaml
77+ mv $(OAPI_OUT ) /openapi.yaml $(OAPI_OUT ) /openapiv3.yaml
78+
5979# #### Plugins & tools #####
6080grpc-install :
6181 @printf $(COLOR ) " Install/update protoc and plugins..."
82+ @go install go.temporal.io/api/cmd/protogen@latest
6283 @go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
6384 @go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
6485 @go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@latest
6586 @go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
87+ @go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest
88+ @go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
89+ @go install github.com/mikefarah/yq/v4@latest
6690
6791api-linter-install :
6892 printf $(COLOR ) " Install/update api-linter..."
0 commit comments