feat: add gRPC-protoc framework support#14
Conversation
Review Summary by QodoAdd gRPC-protoc framework support with OpenAPI spec generation
WalkthroughsDescription• **gRPC-protoc Framework Support**: Complete implementation of gRPC/protobuf framework support for native protoc projects (non-buf-managed) to generate OpenAPI specs using protoc-gen-connect-openapi • **Core Components**: Implements standard extractor pattern with Detector (project identification and service file discovery), Patcher (tool verification), and Generator (protoc command execution) • **HTTP Annotations Support**: Automatic detection and support for google.api.http annotations enabling gRPC-Gateway style REST mappings • **CLI Enhancement**: Added --proto-import-path flag for specifying additional protoc import paths • **Comprehensive Testing**: 1,600+ lines of unit tests covering Detector, Patcher, Generator components plus end-to-end integration test with demo project • **Demo Project**: Complete gRPC demo project with HTTP annotations, Makefile automation, and generated OpenAPI specification • **Documentation**: Design and implementation plans, updated README and architecture docs with gRPC support details Diagramflowchart LR
A["gRPC Project<br/>with .proto files"] -->|Detector| B["Identify Services<br/>& HTTP Annotations"]
B -->|Patcher| C["Verify protoc<br/>& Plugin Installation"]
C -->|Generator| D["Execute protoc<br/>with Plugin"]
D -->|Output| E["OpenAPI Spec<br/>JSON/YAML"]
F["CLI Flag<br/>--proto-import-path"] -.->|Configure| C
File Changes1. internal/extractor/grpcprotoc/generator_test.go
|
Code Review by Qodo
1. grpcprotoc mis-detects projects
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new gRPC-protoc framework extractor that enables spec-forge to generate OpenAPI specifications from native protoc projects (not buf-managed). It follows the established Detector → Patcher → Generator pattern used by the existing Spring Boot and go-zero extractors.
Changes:
- New
internal/extractor/grpcprotoc/package implementing project detection (.protofiles, buf rejection), tool availability checking (protoc,protoc-gen-connect-openapi), and OpenAPI generation via protoc - CLI flag
--proto-import-pathfor additional protoc import paths, wired throughGenerateOptions.ProtoImportPaths - Integration test demo project and E2E test with HTTP annotation support
Reviewed changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
internal/extractor/grpcprotoc/grpcprotoc.go |
Package types: Info struct, FrameworkName, BuildToolProtoc constants |
internal/extractor/grpcprotoc/detector.go |
Proto file discovery, buf.yaml rejection, google.api.http detection, service file identification |
internal/extractor/grpcprotoc/patcher.go |
Checks protoc and protoc-gen-connect-openapi installation |
internal/extractor/grpcprotoc/generator.go |
Builds and executes protoc command, locates generated output file |
internal/extractor/grpcprotoc/extractor.go |
Extractor interface implementation with lazy-init |
internal/extractor/grpcprotoc/*_test.go |
Unit tests for all components |
internal/extractor/builtin/register.go |
Registers grpcprotoc extractor in builtin registry |
cmd/generate.go |
Adds --proto-import-path CLI flag |
internal/extractor/types.go |
Adds ProtoImportPaths field to GenerateOptions |
integration-tests/grpc_protoc_test.go |
E2E test for gRPC-protoc generation |
integration-tests/grpc-protoc-demo/ |
Demo project with proto files and HTTP annotations |
README.md |
Documents gRPC-protoc support and usage |
CLAUDE.md |
Updates architecture overview |
docs/plans/2026-03-08-*.md |
Design and implementation documentation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add package constants and Info type for gRPC-protoc extractor. Signed-off-by: Claude <claude@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Add detector that: - Rejects buf-managed projects with clear error - Finds all .proto files - Detects import paths - Identifies google.api.http annotations Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Add patcher that verifies: - protoc is installed - protoc-gen-connect-openapi is installed - Returns clear installation hints if missing Signed-off-by: Claude <claude@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Add generator that: - Builds protoc command with import paths - Executes protoc-gen-connect-openapi - Returns path to generated OpenAPI file Signed-off-by: Claude <claude@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Add grpcprotoc to builtin extractor registry. Implements full Extractor interface. Signed-off-by: Claude <claude@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Add flag for specifying additional protoc import paths. Co-Authored-By: Claude <claude@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Document gRPC-protoc extractor usage, requirements, and CLI flags. Signed-off-by: Claude <claude@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
- Add ServiceProtoFiles field to Info struct to identify main entry points - Update Detector to find proto files with service definitions - Update Generator to: - Only compile service proto files (avoids duplicate definition errors) - Handle relative output directories correctly by converting to absolute paths - Search recursively for generated OpenAPI files - Add integration-tests/grpc-protoc-demo with sample UserService proto - Include generated OpenAPI spec for demo project Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
- Add google/api/annotations.proto and http.proto to demo project
- Update user.proto with google.api.http annotations for all RPC methods
- Generator now conditionally adds --connect-openapi_opt=features=google.api.http
when HasGoogleAPI is detected, generating REST endpoints alongside gRPC
The generated OpenAPI spec now includes both gRPC-style paths and REST endpoints:
- GET /v1/users - ListUsers
- POST /v1/users - CreateUser
- GET /v1/users/{id} - GetUser
- PUT /v1/users/{id} - UpdateProfile
- POST /v1/users/{user_id}/files - UploadFile
Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
- Add TestE2E_GrpcProtoc_Generate to verify gRPC-protoc detection and generation - Verify HTTP annotations detection (HasGoogleAPI) - Verify generated spec contains REST paths from google.api.http annotations - Fix existing tests to properly extract FrameworkData for spring.Info Signed-off-by: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
- Add grpc_protoc_test.go with dedicated e2e test for gRPC-protoc - Update integration-tests/README.md with grpc-protoc-demo project - Update grpc-protoc-demo/README.md with: - third_party directory structure - HTTP annotations usage - spec-forge integration notes - Update CLAUDE.md with: - grpcprotoc package in architecture - publisher package - Remove duplicate tests from spring_maven_test.go (now in separate files) Signed-off-by: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
…mplementation - Add ServiceProtoFiles field to Info struct documentation - Document conditional HTTP annotations support (only when HasGoogleAPI is true) - Update demo project structure to include third_party/google/api - Mark both documents as completed - Add implementation summary with key design decisions Signed-off-by: spencercjh <spencercjh@gmail.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
26d09b5 to
12df44e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 28 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The hasGoogleAPIImport method had two identical conditions checking for 'google/api/annotations.proto'. Since protobuf only uses double quotes for imports, the single-quote check is unnecessary and has been removed. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Remove redundant fallback check that could match files with unexpected format. Now the method only looks for files with the expected extension based on the requested format. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Keep only ExtractorName to extractor.go to follow the existing convention (spring, gozero). Remove FrameworkName from grpcprotoc.go and update all references. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
Replace custom contains function with standard library strings.Contains for consistency and clarity. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
The detector now rejects projects that have .proto files but no service definitions. This prevents the grpc-protoc extractor from being selected for non-gRPC projects that leading to confusing errors during generation. - Update detector to return ErrNotProtocProject when no service definitions found - Update test cases to include service definitions in proto files - Use proper proto file formatting with newlines for service definitions Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: spencercjh <spencercjh@gmail.com>
…tputFile - Add output_name option to protoc-gen-connect-openapi when OutputFile is specified - Remove recursive search fallback in findOutputFile to avoid finding unrelated files - Only search output directory and service proto file directories Signed-off-by: spencercjh <spencercjh@gmail.com>
Signed-off-by: spencercjh <spencercjh@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 27 out of 28 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…dundant search in findOutputFile - Add proper comment handling (// and /* */) in hasServiceDefinition - Use set to skip already-searched directories in findOutputFile - Address code review feedback from PR #14 Signed-off-by: spencercjh <spencercjh@gmail.com>
Summary
Add gRPC/protobuf framework support for native protoc projects (not buf-managed) to generate OpenAPI specs using
protoc-gen-connect-openapi.Key Features
.protofilesbuf.yamlis detectedgoogle.api.httpannotations (gRPC-Gateway style REST mappings)Architecture
Implements the standard extractor pattern: Detector → Patcher → Generator
Usage
Requirements
protocinstalledprotoc-gen-connect-openapiinstalled (go install github.com/sudorandom/protoc-gen-connect-openapi@latest)Test Plan
integration-tests/grpc_protoc_test.go)integration-tests/grpc-protoc-demo/)make verifymake lintChanges
internal/extractor/grpcprotoc/internal/extractor/builtin/register.gocmd/generate.go--proto-import-pathflagintegration-tests/grpc-protoc-demo/integration-tests/grpc_protoc_test.godocs/plans/2026-03-08-grpc-protoc-*.mdREADME.md,CLAUDE.md🤖 Generated with Claude Code