feat: add support for using package name for external ref imports#2193
Closed
InventivetalentDev wants to merge 6 commits intooapi-codegen:mainfrom
Closed
feat: add support for using package name for external ref imports#2193InventivetalentDev wants to merge 6 commits intooapi-codegen:mainfrom
InventivetalentDev wants to merge 6 commits intooapi-codegen:mainfrom
Conversation
Member
|
How would you feel about doing this differently? I think this approach is more complex than it needs to be, and we can get this in by allowing the specification of an import name in the import mapping. Right now, you have something like: import-mapping:
../common/api.yaml: github.com/oapi-codegen/oapi-codegen/v2/examples/import-mapping/commonWe could accept spaces in there: import-mapping:
../common/api.yaml: common github.com/oapi-codegen/oapi-codegen/v2/examples/import-mapping/commonI think it would be simpler to use. Basically, the entire line would be passed to |
Author
|
@mromaszewicz oh I like it, I'll look into that! |
Author
|
Continued in #2211 with a nicer implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 a new
external-ref-named-importsoption which changes aliases for external imports fromexternalRef0,externalRef1, ... toexternal_ref_<package_name>(e.g.external_ref_packageA,external_ref_packageB).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 named-imports allows me to simply do this instead: