Skip to content

feat: add support for custom package alias for external ref imports#2211

Merged
mromaszewicz merged 4 commits intooapi-codegen:mainfrom
InventivetalentDev:feat/external-ref-v2
Feb 13, 2026
Merged

feat: add support for custom package alias for external ref imports#2211
mromaszewicz merged 4 commits intooapi-codegen:mainfrom
InventivetalentDev:feat/external-ref-v2

Conversation

@InventivetalentDev
Copy link
Copy Markdown
Contributor

@InventivetalentDev InventivetalentDev commented Feb 10, 2026

Adds support for specifying a package alias for external imports, which allows using custom names instead of auto-generated aliases like externalRef0, externalRef1, ...
This allows for more consistent import names when dealing with large projects and multiple linked specs, where the same externalRef0 import can end up referencing different source packages.

Motivation

I'm using oapi-codegen in a complex project in combination with tygo to generate TS types for my frontend code. tygo also supports external imports, but they need to be explicitly mapped from the Go package to the TS file, so my config for that currently looks something like this:

type_mappings:
  time.Time: "string /* RFC3339 */"
  null.String: "null | string"
  null.Bool: "null | boolean"
  uuid.UUID: "string /* uuid */"

  externalRef0.User: User
  externalRef1.Project: Project
  externalRef1.Repo: Repo
  externalRef2.Identity: Identity
  // same source package but different ref index for a spec that doesn't import User or Project, leading to duplicate type mapping
  externalRef0.Identity: Identity 

needing to map the same package/type multiple times since different files have varying starting indexes for externalRef imports.
Using the custom alias allows me to simply do this instead:

# config.yaml
import-mapping:
  ./common/users.yaml: users example_package/users
  ./common/projects.yaml: projects example_package/projects
  ./common/identities.yaml: identities example_package/identities
# tygo.yaml
  users.User: User
  projects.Project: Project
  projects.Repo: Repo
  identities.Identity: Identity

previous implementation: #2193

@mromaszewicz
Copy link
Copy Markdown
Member

Your CI failure has nothing to do with your code.
#2214

@mromaszewicz
Copy link
Copy Markdown
Member

We will merge this once I get my CI fix approved, and you rebase to run precommit using that fix.

@mromaszewicz mromaszewicz merged commit b7ac5db into oapi-codegen:main Feb 13, 2026
26 checks passed
@mromaszewicz
Copy link
Copy Markdown
Member

Thank you, @InventivetalentDev

@jamietanna jamietanna added the enhancement New feature or request label Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants