Closed morganhein closed 1 year ago
You need to define the absolute package path via -packagePath
when calling goverter, then only necessary imports will be done.
Example:
goverter -output=./generated.go -packageName=simple -packagePath=github.com/jmattheis/goverter/example/simple github.com/jmattheis/goverter/example/simple
Jannis, thanks for the quick response!
I tried that and it does not work. Here's some screenshots illustrating:
Am I missing something?
The unionpacific_edi.go
is the goverter input here. That was not clear.
I think I see the issue. The package path is a go path, not a file path....
edit doesn't work still..hmmm
You need to delete the old generated file. Goverter needs type information for generating the converter, but currently there is an import cycle, so it can't compile the code.
Ugh. That's a little embarrassing.
Case closed. Thank you!
No problem, I'll improve the error message. It'll look like this:
could not load package github.com/jmattheis/goverter/execution
/ABSOLUTE/execution/input.go:6:1: expected declaration, found oops
Goverter cannot generate converters when there are compile errors because it
requires the type information from the compiled sources.
Have you read the project readme?
Describe your question I have an situation that is maybe not-idiomatic, but we have some unique constraints.
I need to generate files in the same directory/namespace as the goverter config. The file gets generated, but the generated file tries to import the current namespace, which obviously doesn't work.
Is there some config/flag I can get goverter to detect it's working with a single namespace, and doesn't need to import itself?
I forked goverter and mangled the runner_test.go and added a scenario that generates output in the same package as the imported models/extended methods, and it worked... which leads me to believe something in application bootstrapping is just assuming a namespace must always be imported?
File structure is as follows:
and I want to generate to:
Error is as follows: