Skip to content

Commit 9107bfb

Browse files
mromaszewiczclaude
andauthored
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
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# yaml-language-server: $schema=../../../../configuration-schema.json
2+
package: pathalias
3+
generate:
4+
client: true
5+
output: client.gen.go

internal/test/pathalias/client.gen.go

Lines changed: 336 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/test/pathalias/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package pathalias
2+
3+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=server-config.yaml spec.yaml
4+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=client-config.yaml spec.yaml
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# yaml-language-server: $schema=../../../../configuration-schema.json
2+
package: pathalias
3+
generate:
4+
chi-server: true
5+
models: true
6+
output: server.gen.go

0 commit comments

Comments
 (0)