Weakly non-Gaussian formula for the Minkowski functionals in general dimensions