Analytical description of the generation of harmonics of the undulator radiation (UR) in free electron lasers (FELs) is given for various FEL experiments in the X-ray band. The expressions for the spectral line shape and intensity are written explicitly in terms of the generalized Bessel and Airy functions with account for the electron energy spread, beam sizes and emittances, spectral line split and non-periodic magnetic fields. The presented theory describes well the radiation spectral properties and harmonic intensities in all studied FEL experiments: SACLA, LCLS, PAL-XFEL, SwissFEL et al., in various conditions with the radiation in wide range of frequencies, covering hard X-rays.