gRPC Gateway OpenAPI v2 Protoc Generator
raw JSON → 0.1.0 verified Mon Apr 27 auth: no python
Provides the missing pieces for gRPC Gateway, specifically the protoc-gen-openapiv2 plugin for generating OpenAPI v2 specs from gRPC protobuf definitions. Current version 0.1.0, requires Python >=3.6, early development.
pip install grpc-gateway-protoc-gen-openapiv2 Common errors
error ModuleNotFoundError: No module named 'protoc_gen_openapiv2' ↓
cause Incorrect import path (missing package prefix).
fix
Use: import grpc_gateway_protoc_gen_openapiv2.plugin
error protoc: error: plugin protoc-gen-openapiv2 not found ↓
cause External binary not installed.
fix
Install protoc-gen-openapiv2 from grpc-gateway repository.
Warnings
breaking Package name is under development; import paths may change without major version bump. ↓
fix Monitor repository for updates and pin version.
gotcha The plugin is a Python wrapper; protoc itself and protoc-gen-openapiv2 binary must be installed separately. ↓
fix Ensure protoc and protoc-gen-openapiv2 are in PATH.
Imports
- plugin wrong
import protoc_gen_openapiv2correctimport grpc_gateway_protoc_gen_openapiv2.plugin - generate_openapi wrong
from protoc_gen_openapiv2 import generate_openapicorrectfrom grpc_gateway_protoc_gen_openapiv2.plugin import generate_openapi
Quickstart
import os
from grpc_gateway_protoc_gen_openapiv2.plugin import generate_openapi
# Example usage - replace with actual proto file path
proto_file = "api.proto"
output_dir = "./openapi"
# Generate OpenAPI spec
# generate_openapi(proto_file, output_dir) # uncomment when ready
print("Quickstart placeholder - see README")