This is called Brachistochrone problem and it is one of the most standard problem using calculus of variational. The solution can be found in standard textbook, but there are some subtle points that worth mention here (see the end). So I will only give the outline of solution.
The first step is to use conservation of energy as $0 = mv^2/2-mgy$, so
$$v=\sqrt{2gy}$$
Also, the displacement is given by $ds=\sqrt{dx^2+dy^2}$, so the total time is
$$t=\int_A^B{dt}=\int_A^B{\frac{ds}{v}}=\int_A^B{\sqrt\frac{dx^2+dy^2}{2gy}}=\int_A^B{\sqrt\frac{1+(\frac{dy}{dx})^2}{2gy}}dx$$
We can then use the Euler-Lagrange equation directly.
Method 1: This is the approach usually taken (example). Let
$$f(y,y',x)=\sqrt\frac{1+(y')^2}{2gy}$$
where $y' = \frac{dy}{dx}$ and treat $x$ as independent variable and use the Euler-Lagrange equation in the form
$$\frac{d}{dx}\frac{\partial f}{\partial y'}-\frac{\partial f}{\partial y}=0$$
Note that $f$ is independent of $x$. The resulting differential equation is
$$2yy''+(y')^2+1=0$$
It is a non-linear differential equation and there is no easy way to solve, but it can be checked that the solution are indeed
$$
\begin{cases}
x=a(\theta-\sin\theta)\\
y=a(1-\cos\theta)
\end{cases}
$$
Method 2: The previous method is a bit tricky. We can solve it because we already know the answer. A better way to solve this problem is to take $y$ as the independent variable and write the function $f$ as
$$h(x,x',y)=\sqrt\frac{1+(x')^2}{2gy}$$
where $x'=\frac{dx}{dy}$ and so the total time is $t=\int_A^B h(x,x',y)dy$. The Euler-Lagrange equation is now:
$$\frac{d}{dy}\frac{\partial h}{\partial x'}-\frac{\partial h}{\partial x}=0$$
Note that $h$ is now independent of $x$, so $\frac{\partial h}{\partial x}=0$ and $\frac{\partial h}{\partial x'}=const$. If we let this constant to be $\frac{1}{\sqrt{2a}}$ and rearrange the equation, we will have the explicit form of $x'$ as
$$x'=\frac{dx}{dy}=\sqrt{\frac{y}{2a-y}}$$
It can be integrated explicitly and we can get a solution of the form $x(y)$ which is certainly the same as the parametric equation in Method 1.
So why the second method leads to direct explicit solution but not the first one? The reason is that we choose the functional form that are independent of the dependent parameter $x(y)$. Hence there is no need to take the extra total derivative $d/dy$ in the Euler-Lagrange equation which ultimately leads to the nonlinearity in the resulting differential equation.
It is rarely mentioned in textbook probably because the $dx/dy$ will create confusion for the beginner, as it is different from their derivation of the Euler-Lagrange equation. Anyway, the examples here does show that one choice of independent parameter is better than the other choice.