feat: add support for custom package alias for external ref imports #2211
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.
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
externalRef0import can end up referencing different source packages.Motivation
I'm using
oapi-codegenin a complex project in combination withtygoto generate TS types for my frontend code.tygoalso 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: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:
previous implementation: #2193