Zernike polynomials are commonly used to represent the wavefront phase on circular optical apertures, since they form a complete and orthonormal basis on the unit circle. Here, we present a generalization of this Zernike basis for a variety of important optical apertures. On the contrary to ad hoc solutions, most of them based on the Gram-Schmidt orthonormalization method, here we apply the diffeomorphism (mapping that has a differentiable inverse mapping) that transforms the unit circle into an angular sector of an elliptical annulus. In this way, other apertures, such as ellipses, rings, angular sectors, etc. are also included as particular cases. This generalization, based on in-plane warping of the basis functions, provides a unique solution and what is more important, it guarantees a reasonable level of invariance of the mathematical properties and the physical meaning of the initial basis functions. Both, the general form and the explicit expressions for most common, elliptical and annular apertures are provided.