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

Skip to content

ResultType generates wrong view validation code for OneOf Attributes #3747

@nicolo

Description

@nicolo

The code that is generated for a ResultType View with a OneOf Attribute is invalid.

Here is a simple design that will replicate the issue:

var GreetingResult = ResultType("application/vnd.greeting", func() {
	TypeName("Greeting")

	Attributes(func() {
		OneOf("response", func() {
			Attribute("message", String, "Textual greeting")
			Attribute("timestamp", String, func() {
				Format(FormatDateTime)
			})
		})
	})

	View("default", func() {
		Attribute("response")
	})
})

Error shows up in the Validate* functions in gen/greeter/views/views.go

// ValidateGreetingView runs the validations defined on GreetingView using the
// "default" view.
func ValidateGreetingView(result *GreetingView) (err error) {
	switch v := result.Response.(type) {
	case ResponseTimestampView:
		if v != nil {
			err = goa.MergeErrors(err, goa.ValidateFormat("result.response.value", string(*v), goa.FormatDateTime))
		}
	}
	return
}

Error: invalid operation: v != nil (mismatched types ResponseTimestampView and untyped nil)

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