Commit 9107bfb
Add support for path aliases (oapi-codegen#2312)
* Add support for path aliases
Closes oapi-codegen#223
When an OpenAPI spec uses $ref to alias one path to another (e.g.
/test2: $ref: '#/paths/~1test'), kin-openapi inlines the referenced
path item into both entries. Previously this produced duplicate
ServerInterface methods, wrapper functions, and type definitions —
generating Go code that never compiled.
Detect internal path aliases via PathItem.Ref (only when it starts
with "#/paths/", to distinguish from external file references). For
alias operations:
- Server: skip interface method, wrapper, and strict handler generation.
Route registration still emits both paths, pointing to the canonical
wrapper via the new HandlerName() method on OperationDefinition.
- Client: generate methods with a suffixed OperationId (e.g.
GetTestAlias0) so each aliased path gets its own request builder
targeting the correct URL.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: skip operationId write-back for alias operations
Alias paths share the same *openapi3.Operation pointer as the canonical
path. Writing the suffixed alias name (e.g. GetTestAlias0) back to
op.OperationID would corrupt the canonical operation's ID in the
embedded spec.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent cd4f5aa commit 9107bfb
40 files changed
Lines changed: 661 additions & 56 deletions
File tree
- internal/test/pathalias
- pkg/codegen
- templates
- chi
- echo
- v5
- fiber
- gin
- gorilla
- iris
- stdhttp
- strict
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
0 commit comments