Exemple #1
0
// attributeMarshalerR is the recursive implementation of AttributeMarshaler.
func attributeMarshalerR(att *design.AttributeDefinition, context, source, target string, depth int) string {
	var marshaler string
	switch actual := att.Type.(type) {
	case *design.MediaTypeDefinition:
		marshaler = mediaTypeMarshalerR(actual, source, target, att.View, depth)
	case design.Object:
		marshaler = objectMarshalerR(actual, att.AllRequired(), context, source, target, depth)
	default:
		marshaler = typeMarshalerR(att.Type, context, source, target, depth)
	}
	validation := ValidationChecker(att, false, source, context, 1)
	if validation != "" {
		if !strings.HasPrefix(strings.TrimLeft(" \t\n", marshaler), "if err == nil {") {
			return fmt.Sprintf(
				"%s\n%sif err == nil {\n%s\n%s}",
				validation,
				Tabs(depth),
				marshaler,
				Tabs(depth),
			)
		}
		return validation + marshaler
	}
	return marshaler
}