| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…codegen#2466)" This reverts commit a07731d.
Greptile SummaryThis PR fixes the "redeclared in this block" compile error for path-item-level anyOf/oneOf parameters shared across multiple HTTP methods on the same path, and resolves cross-path name collisions for the common REST pattern of a shared {id} parameter on sibling paths.
Confidence Score: 5/5Safe to merge; the fix correctly eliminates the redeclared-in-this-block compile error, preserves historical undecorated names for non-colliding parameters, and the new fixture provides compile-time guards for all four code paths. The core logic — pre-passing to count collisions, assigning FNV hash tokens, emitting shared type definitions once per path item, and skipping shared params in per-operation type collection — is sound. The generated fixture compiles and validates all scenarios. The two observations (potential over-disambiguation when the same path-item pointer appears twice in enumerateSharedParamScopes, and misleading doc comments on non-colliding shared types) are both edge-case quality issues that do not affect correctness or compilation. No files require special attention; pkg/codegen/operations.go has the main algorithmic change but is well-covered by the new test fixture. Important Files Changed
Reviews (2): Last reviewed commit: "Name shared path parameter helper types ..." | Re-trigger Greptile |
Sorry, something went wrong.
…isions Closes: oapi-codegen#2090 A parameter declared at the path-item level is inherited by every method on the path. Its hoisted helper types -- the members of an inline anyOf/oneOf and similar -- were named from the parameter alone and declared once per operation, so a path with more than one method redeclared them ("Id0 redeclared in this block"). The same bare names also collided across different paths that reuse the same parameter, which is the common REST case of an {id} shared by sibling paths. Resolve path-item-level parameters in a single pre-pass (resolveSharedParameters): describe each scope's shared parameters once, count how many scopes hoist a helper type under each name, and emit each scope's helper types once for its path item rather than once per operation. A name produced by two or more scopes is disambiguated by prefixing that scope's parameters with a short, stable FNV hash of the scope, extended to the full hash only if two scopes' short hashes clash. A parameter that does not collide keeps its historical undecorated name, so existing generated code is unaffected -- the only outputs that change are specs that previously failed to compile. Applied uniformly to regular paths, webhooks, and callbacks, which share the one global Go type namespace. Disambiguated types carry a doc comment explaining the hash prefix and pointing back to the source path. Adds internal/test/parameters/shared_collision covering a shared anyOf parameter across multiple methods on a path (bare, emitted once), the same parameter reused across sibling paths (hash-disambiguated), and a non-colliding single-method parameter (unchanged). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
Closes: #2090
A parameter declared at the path-item level is inherited by every method on the path. Its hoisted helper types -- the members of an inline anyOf/oneOf and similar -- were named from the parameter alone and declared once per operation, so a path with more than one method redeclared them ("Id0 redeclared in this block"). The same bare names also collided across different paths that reuse the same parameter, which is the common REST case of an {id} shared by sibling paths. Resolve path-item-level parameters in a single pre-pass (resolveSharedParameters): describe each scope's shared parameters once, count how many scopes hoist a helper type under each name, and emit each scope's helper types once for its path item rather than once per operation. A name produced by two or more scopes is disambiguated by prefixing that scope's parameters with a short, stable FNV hash of the scope, extended to the full hash only if two scopes' short hashes clash. A parameter that does not collide keeps its historical undecorated name, so existing generated code is unaffected -- the only outputs that change are specs that previously failed to compile. Applied uniformly to regular paths, webhooks, and callbacks, which share the one global Go type namespace. Disambiguated types carry a doc comment explaining the hash prefix and pointing back to the source path. Adds internal/test/parameters/shared_collision covering a shared anyOf parameter across multiple methods on a path (bare, emitted once), the same parameter reused across sibling paths (hash-disambiguated), and a non-colliding single-method parameter (unchanged).