connectrpc / connect-go

The Go implementation of Connect: Protobuf RPC that works.
https://connectrpc.com
Apache License 2.0
2.94k stars 96 forks source link

OpenApi spec generation? #703

Closed lordvidex closed 7 months ago

lordvidex commented 7 months ago

I currently migrated from the default stack ( grpc-go with grpc-gateway ) to connect-go because I get a lot of features out of the box with minimal grpc boilerplate generation.

Connect currently supports grpc requests (which can be reflected easily with clients) and http requests. The problem is that the http part is missing certain features especially if one is using clients that work only with http.

grpc-gateway uses/includes the following binaries:

Currently, there is nothing in the connectrpc ecosystem that provides the features of protoc-gen-openapiv2. This will be especially useful to display http endpoints explicitly since connect doesn't strictly enforce standard http naming conventions and styles.

lordvidex commented 7 months ago

I'll close this issue because I found a solution to this. There is no need for an additional lib to expose the connect-go API. protoc-gen-openapiv2 can be used but there is a need to specify generate_unbound_methods=true option. Additional libs like github.com/swaggo/http-swagger/v2 can be used to host the swagger generated file.

protoc command

$(PROTOC) -I . -I vendor-proto \
    --plugin=protoc-gen-go=$(BINDIR)/protoc-gen-go --go_out=paths=source_relative:./pkg \
    --plugin=protoc-gen-connect-go=$(BINDIR)/protoc-gen-connect-go --connect-go_out=paths=source_relative:./pkg \
    --plugin=protoc-gen-openapiv2=$(BINDIR)/protoc-gen-openapiv2 --openapiv2_out api/openapiv2/ --openapiv2_opt logtostderr=true --openapiv2_opt generate_unbound_methods=true \
    $(PROTO_PATH)/api.proto