Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@markosfount

Description

@markosfount

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions