Navigation Menu

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

missing & in generated code #18

Closed
kliko9 opened this issue Apr 26, 2022 · 2 comments
Closed

missing & in generated code #18

kliko9 opened this issue Apr 26, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@kliko9
Copy link

kliko9 commented Apr 26, 2022

Describe the bug
Generation doesn't throw any error and successfully generates invalid code.

To Reproduce

// goverter:converter
type Converter interface {
	// goverter:mapIdentity Address
	ConvertPerson(source Person) (APIPerson, error)

	// goverter:map Name StreetName
	ConvertAddress(source Person) (APIAddress, error)
}

type Person struct {
	Name   string
	Street string
	City   string
}

type APIPerson struct {
	Name    string
	Address *APIAddress
}

type APIAddress struct {
	StreetName string
	City       string
}

Expected behavior
The generated code is missing ampersand sign.

type ConverterImpl struct{}

func (c *ConverterImpl) ConvertAddress(source proto.Person) (proto.APIAddress, error) {
	var protoAPIAddress proto.APIAddress
	protoAPIAddress.StreetName = source.Name
	protoAPIAddress.City = source.City
	return protoAPIAddress, nil
}
func (c *ConverterImpl) ConvertPerson(source proto.Person) (proto.APIPerson, error) {
	var protoAPIPerson proto.APIPerson
	protoAPIPerson.Name = source.Name
	pProtoAPIAddress, err := c.protoPersonToPProtoAPIAddress(source)
	if err != nil {
		return protoAPIPerson, err
	}
	protoAPIPerson.Address = pProtoAPIAddress
	return protoAPIPerson, nil
}
func (c *ConverterImpl) protoPersonToPProtoAPIAddress(source proto.Person) (*proto.APIAddress, error) {
	protoAPIAddress, err := c.ConvertAddress(source)
	if err != nil {
		return protoAPIAddress, err
	}
	return &protoAPIAddress, nil
}

protoPersonToPProtoAPIAddress in case of err != nil in returned value & is missing. Btw. why there's doubled P in method's name.

@jmattheis jmattheis added the bug Something isn't working label Apr 26, 2022
@jmattheis
Copy link
Owner

Good catch, I can reproduce this. The duplicated P is because it is a pointer of proto.APIAddress.

@jmattheis
Copy link
Owner

Fixed in v0.6.2, sadly I'm not satisfied with the solution, because it creates an allocation if the conversion errors, I've created another issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants