You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Author type has string "name" attribute and string "country" attribute.
The Required validation is set to the Author's "name" attribute.
The Book type has string "title" attribute and refers Author type as "author" attribute.
When I run codegen with this code, I get that compile error.
After investigation, I found two problems.
User type validation should not execute Validate of other types when the other type has only Required validation on primitive type attributes.
Validate method for public type should not be generated when the type has only Required validation on primitive type attributes.
Details are following.
Problem 1: Improper execution of other types' Validate
When the type has only Required validation on primitive type attributes, the type will not have validation code (in design of goa, as mentioned in Validator's recurseAttribute method).
So, the type referring such type (which has only Required validation for primitives) as an attribute should not call Validate method on that type.
However, the code generation procedure produces codes which call Validate on the other types regardless it's validation (having Validate method or not).
I think this problem should be fixed by changing here
This if statement is for decision whether generate codes calling Validate on the attribute or not.
This should consider situations that the referring type does not have Validate method.
Problem 2: Unnecessary generation of Validate
By changing my design code as like this (two String type attributes for Required),
codegen generates empty Validate method (just return) for this type.
// Validate validates the Author type instance.func (ut*Author) Validate() (errerror) {
return
}
I think this is a bug of the code generation, because required String type will be primitive string, and validations for Required of primitive types should not be generated.
This if statement is for adding line breaks between required validation codes.
Current condition (just if i > 0) will append "\n" even if the required attribute is primitive type (which will not produce validation code).
I think adding line breaks in the for loop should be done when the current code is not empty.
Hi,
There is a situation that the generated codes result compile error.
The error goes like:
ut.MyUserType.Validate undefined
.Here is my design code.
The
Author
type has string"name"
attribute and string"country"
attribute.The
Required
validation is set to theAuthor
's"name"
attribute.The
Book
type has string"title"
attribute and refersAuthor
type as"author"
attribute.When I run
codegen
with this code, I get that compile error.After investigation, I found two problems.
Validate
of other types when the other type has onlyRequired
validation on primitive type attributes.Validate
method for public type should not be generated when the type has onlyRequired
validation on primitive type attributes.Details are following.
Problem 1: Improper execution of other types'
Validate
When the type has only
Required
validation on primitive type attributes, the type will not have validation code (in design of goa, as mentioned inValidator
'srecurseAttribute
method).So, the type referring such type (which has only
Required
validation for primitives) as an attribute should not callValidate
method on that type.However, the code generation procedure produces codes which call
Validate
on the other types regardless it's validation (havingValidate
method or not).I think this problem should be fixed by changing here
goa-v1/goagen/codegen/validation.go
Line 255 in 6373905
to this.
This
if
statement is for decision whether generate codes callingValidate
on the attribute or not.This should consider situations that the referring type does not have
Validate
method.Problem 2: Unnecessary generation of
Validate
By changing my design code as like this (two
String
type attributes forRequired
),codegen
generates emptyValidate
method (justreturn
) for this type.I think this is a bug of the code generation, because required
String
type will be primitivestring
, and validations forRequired
of primitive types should not be generated.This problem can be fixed by changing here
goa-v1/goagen/codegen/validation.go
Line 382 in 6373905
to this.
This
if
statement is for adding line breaks between required validation codes.Current condition (just
if i > 0
) will append"\n"
even if the required attribute is primitive type (which will not produce validation code).I think adding line breaks in the
for
loop should be done when the current code is not empty.Codes
Here is my codes for testing
codegen
behavior.https://github.com/KobayashiTakaki/goa-test
Thanks😌
The text was updated successfully, but these errors were encountered: