Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: generating in the same folder results in an invalid import #88

Closed
marmiha opened this issue Sep 13, 2023 · 1 comment
Closed

bug: generating in the same folder results in an invalid import #88

marmiha opened this issue Sep 13, 2023 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@marmiha
Copy link

marmiha commented Sep 13, 2023

Describe the bug
Generating the converter in the same folder as the interface extends results in an invalid package name "commandlinearguments" when used in pair with local converter functions extends functionality.

To Reproduce

Run go generate on this example:

package converter

type (
	Input struct {
		Value int32
	}

	Output struct {
		Value int
	}
)

func IntToInt32(value int32) int {
	return int(value)
}

//go:generate goverter --packageName=converter --packagePath=. --output=./converter.gen.go ./converter.go

// goverter:converter
// goverter:extend IntToInt32
type Converter interface {
	Convert(Input) Output
}

Which produces converter.gen.go with invalid imports:

// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.

package converter

import commandlinearguments "command-line-arguments"

type ConverterImpl struct{}

func (c *ConverterImpl) Convert(source commandlinearguments.Input) commandlinearguments.Output {
	var converterOutput commandlinearguments.Output
	converterOutput.Value = commandlinearguments.IntToInt32(source.Value)
	return converterOutput
}

Expected behavior

It should detect that the conversion methods are in the same package and thus does not import anyhting when accessing the extended methods.

I have also tried this with different combinations of cmd line arguments but nothing worked.

@marmiha
Copy link
Author

marmiha commented Sep 13, 2023

Wrote too quick, duplicate of #35. For anyone else write the full path like this:

//go:generate goverter --packageName=converter  --output=./converter.gen.go --packagePath=github.com/converter github.com/converter

@marmiha marmiha closed this as completed Sep 13, 2023
@jmattheis jmattheis added the duplicate This issue or pull request already exists label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants