grpc-ecosystem / grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec
https://grpc-ecosystem.github.io/grpc-gateway/
BSD 3-Clause "New" or "Revised" License
18.24k stars 2.24k forks source link

OpenAPI-gateway - provide an ability to register OpenAPI handler #2482

Closed eldad87 closed 2 years ago

eldad87 commented 2 years ago

🚀 Feature

As a SaaS provider, I would like to serve my APIs using a single endpoint. Unfortunately, using grpc-gateway is not an option as some of our legacy microservies are "documented" using OpenAPI (Swagger).

Please provide an ability to register OpenAPI based handlers. As a workaround, I result using an additional API-GW (AWS, WSO2, Kong, etc) that consolidate my Restfull APIs (OpenAPI) and grpc-gateway(s).

johanbrandhorst commented 2 years ago

Hi! Thanks for your issue. There are a few ways to do this already: The ServeMux implements http.Handler, so you can register it on a http.ServeMux, and then manually register your own routes on the serve mux too. Alternatively, you can also call ServeMux.Handle to register custom routes on the serve mux. In either case, it's going to be manual, and risk getting out of date with your definitions. If you require something generated from your definitions, I recommend looking at a tool like https://github.com/OpenAPITools/openapi-generator and seeing if you can somehow merge such a server with our ServeMux. Does that make sense?

eldad87 commented 2 years ago

Hi @johanbrandhorst, Thank you for your answer. Instead of generating the custom routes, I would try to utilize something like kusk-gateway.

johanbrandhorst commented 2 years ago

kusk-gateway appears to be an external application. I don't know what you mean by "register" open API routes in the context of using an external application. What exactly are you wanting our gateway to do?

eldad87 commented 2 years ago

Hi @johanbrandhorst , Assuming that my eco-system is composed of 2 micro-services & a gRPC-gateway service:

Currently, the gRPC-gateway can expose the APIs of micro-service A, while I would like it to expose both A & B.

johanbrandhorst commented 2 years ago

You have to manually add those routes to the same mux that the gRPC gateway serves. The gRPC gateway can't automate this process.