fix(protoc-gen-openapiv2): prevent panic when generating OpenAPI for multiple files#6275
Merged
johanbrandhorst merged 2 commits intogrpc-ecosystem:mainfrom Jan 28, 2026
Merged
Conversation
…multiple files When multiple proto files are specified as targets, the naming cache (registriesSeen) would retain a filtered mapping from a previous file that excluded method FQNs needed by the current file, causing a panic with "failed to resolve method FQN". This fix: - Clears the naming cache at the start of each file's applyTemplate() so each file builds a fresh mapping with all needed names - Adds a fallback for method FQN lookup that uses FQN naming strategy instead of panicking if the lookup fails Fixes grpc-ecosystem#6274 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
johanbrandhorst
requested changes
Jan 27, 2026
Collaborator
johanbrandhorst
left a comment
There was a problem hiding this comment.
Thanks for this PR, I had a question about one of the comments.
|
|
||
| // TestGenerateMergeWithServiceNotInTargets tests the scenario where a service | ||
| // file is available in the proto file set but not marked for generation. | ||
| // This can happen with Edition 2023 files where dependencies are structured differently. |
Collaborator
There was a problem hiding this comment.
I can't find a reference for this assertion, could you explain what you mean? If this part is AI generated, please back it up with sources or remove it.
Contributor
Author
There was a problem hiding this comment.
You're right to call this out. This test was speculative coverage I added while working on the fix, but I can't point to a specific issue it prevents. I'll remove it to keep the PR focused on the actual fix for #6274.
franchb
added a commit
to franchb/grpc-gateway
that referenced
this pull request
Feb 3, 2026
Properly fixes grpc-ecosystem#6274 (panic) without causing grpc-ecosystem#6308 (naming mismatch). Replaces the reverted approach from PR grpc-ecosystem#6275. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3 tasks
johanbrandhorst
pushed a commit
that referenced
this pull request
Feb 6, 2026
This was referenced Apr 23, 2026
fix(deps): vuln minor upgrades — 11 packages (minor: 7 · patch: 4) [server]
DataDog/temporalio-ui#27
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #6274
When multiple proto files are specified as targets (e.g., via
buforprotoc), the plugin would panic with "failed to resolve method FQN" because the naming cache retained a filtered mapping from a previous file that excluded method FQNs needed by the current file.Changes
applyTemplate()so each file builds a fresh mapping with all needed namesbody:"*"and path parametersRoot Cause
The
registriesSeencache intemplate.gouses*descriptor.Registryas the key. When processing multiple target files, each file'sapplyTemplate()overwrites the cache with its own filtered subset of names (to avoid naming collisions with unused types).When
messages.proto(with no services) is processed first:registriesSeen[p.reg]service.protois processed, lookups inrenderServices()use the cached mappingTest plan
TestGenerateMergeFilesWithBodyAndPathParams- tests merged files withbody:"*"and path parametersTestGenerateMergeWithServiceNotInTargets- tests generating service file with messages in dependency🤖 Generated with Claude Code