fix(stdhttp): reject mixed path-parameter segments at codegen#2492
Open
Solaris-star wants to merge 1 commit into
Open
fix(stdhttp): reject mixed path-parameter segments at codegen#2492Solaris-star wants to merge 1 commit into
Solaris-star wants to merge 1 commit into
Conversation
net/http ServeMux requires wildcards to occupy an entire path segment.
Paths like /resources/{resourceId}:apply previously generated patterns
that panic at server registration.
Validate std-http-server paths at codegen time and fail with a clear
error instead of emitting unusable code.
Fixes oapi-codegen#2488
Contributor
Greptile SummaryThis PR adds codegen-time validation for stdhttp ServeMux path patterns. The main changes are:
Confidence Score: 4/5The stdhttp validation path can reject filtered configurations that would not emit the invalid route.
pkg/codegen/codegen.go
|
| Filename | Overview |
|---|---|
| pkg/codegen/codegen.go | Adds the stdhttp validation call, but it validates path keys that may no longer have emitted operations. |
| pkg/codegen/utils.go | Adds path validation helpers that reject mixed wildcard/literal ServeMux segments. |
| pkg/codegen/utils_test.go | Adds tests for the validator and the main generation rejection path. |
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
pkg/codegen/codegen.go:181-185
**Filtered Paths Still Fail**
When `std-http-server` is enabled with tag or operation-id filters, those filters can remove every operation under a mixed segment while leaving the path key in `spec.Paths`. This check still validates that unused path and returns an error, so a route that would never be emitted can block generation.
Reviews (1): Last reviewed commit: "fix(stdhttp): reject mixed path-paramete..." | Re-trigger Greptile
Comment on lines
+181
to
+185
| if opts.Generate.StdHTTPServer { | ||
| if err := ValidateStdHTTPPaths(spec); err != nil { | ||
| return "", err | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
When std-http-server is enabled with tag or operation-id filters, those filters can remove every operation under a mixed segment while leaving the path key in spec.Paths. This check still validates that unused path and returns an error, so a route that would never be emitted can block generation.
Knowledge Base Used: Codegen Pipeline
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/codegen/codegen.go
Line: 181-185
Comment:
**Filtered Paths Still Fail**
When `std-http-server` is enabled with tag or operation-id filters, those filters can remove every operation under a mixed segment while leaving the path key in `spec.Paths`. This check still validates that unused path and returns an error, so a route that would never be emitted can block generation.
**Knowledge Base Used:** [Codegen Pipeline](https://app.greptile.com/oapi-codegen/-/custom-context/knowledge-base/oapi-codegen/oapi-codegen/-/docs/codegen-pipeline.md)
How can I resolve this? If you propose a fix, please make it concise.
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
std-http-serverpreviously generated ServeMux patterns for mixed wildcard+literal segments such as:Registering that with
net/http.ServeMuxpanics:Maintainer guidance on #2488 prefers a codegen-time error over silent rewriting.
Fix
ValidateStdHTTPPath/ValidateStdHTTPPathsGeneratewhenStdHTTPServeris enabled{param}with surrounding literalsTest plan
go test ./pkg/codegen/ -run 'TestValidateStdHTTPPath|TestGenerateRejectsMixedServeMuxPathParam|TestSwaggerUriToStdHttpUriUri'Fixes #2488