jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
496 stars 46 forks source link

Self import when output is in same package #10

Closed hshorter closed 2 years ago

hshorter commented 2 years ago

When overriding the package and output the resulting generated code imports it's own package for custom implementations.

See example project: https://github.com/hshorter/goverterissue When the generate stage runs, the resulting code contains a self import error:

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

package converter

import converter "github.com/hshorter/goverterissue/pkg/converter"

type DeviceConverterImpl struct{}

func (c *DeviceConverterImpl) ConvertToOutput(source converter.Input) converter.Output {
    var converterOutput converter.Output
    converterOutput.Name = source.Name
    converterOutput.Time = converter.timeToTime(source.Time)
    return converterOutput
}
jmattheis commented 2 years ago

Good catch, this is currently not supported, and I don't know yet if it can be easily supported as it's not easy to determine if the file will be generated into the package where the converter definition is.

switchupcb commented 2 years ago

@hshorter This is issue does not occur in copygen due to its design.

jmattheis commented 2 years ago

Fixed with https://github.com/jmattheis/goverter/pull/22