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

ConvertTo using struct with Http* name capitalises word and code does not compile. #3605

Closed
markosfount opened this issue Oct 25, 2024 · 2 comments

Comments

@markosfount
Copy link

As the title says, using ConvertTo function with an struct input with a name of Http* is generating the wrong code as it capitalises Http to HTTP. For example:

Define a model as follows:

package design

import (
	. "goa.design/goa/v3/dsl" //nolint:revive
	"goa_poc/pkg"
)

var HttpConfig = Type("HttpConfig", func() {
	ConvertTo(pkg.HttpConfig{})
	Attribute("host", String, "The host")
	Attribute("port", Int, "The port number")
})

having an external struct like so (assuming this is in a different package/project thus naming cannot be changed):

package pkg

type HttpConfig struct {
	Host string
	Port int
}

will result in the following convert.go after running generate:

package poc

import (
	pkg "goa_poc/pkg"
)

// ConvertToHttpConfig creates an instance of HttpConfig initialized from t.
func (t *HTTPConfig) ConvertToHttpConfig() *pkg.HttpConfig {
	v := &pkg.HTTPConfig{}
	if t.Host != nil {
		v.Host = *t.Host
	}
	if t.Port != nil {
		v.Port = *t.Port
	}
	return v
}

Whereas the return value is the correct one, the v value is defined with a nonexisting capitalised struct, which does not compile.
Service code and generate file are omitted. Full example here: https://github.com/markosfount/goa-poc

@raphael
Copy link
Member

raphael commented Oct 29, 2024

Thank you for the report! @tchssk implemented a fix that is now merged. Are you able to validate the fix? You can try the latest version with:

go get goa.design/goa/v3@405ca1c1e52acecef7ab7963f94c58a2a22640a8

@markosfount
Copy link
Author

Thank you for the report! @tchssk implemented a fix that is now merged. Are you able to validate the fix? You can try the latest version with:

go get goa.design/goa/v3@405ca1c1e52acecef7ab7963f94c58a2a22640a8

Thanks @raphael, it appears the generate is working now!

@raphael raphael closed this as completed Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants