The 18-year-old, who made his full Wales debut in October, has featured three times for the South Wales club this season - including one start in the Premier League
John, who made his Wales debut in a World Cup qualifier against Macedonia in October, has come through the youth system at the South Wales outfit and started the club's first Premier League game of the season at West Ham.
|CARDIFF CITY LATEST
|3/1||Cardiff are 3/1 with Paddy Power to be leading Stoke after 60 minutes|
"Declan has done extremely well and is thoroughly deserving of his new contract at Cardiff City," Mackay told the club's official website.
"In addition, we are delighted to have secured his talent on a long-term basis. He's a fine young man, disciplined and professional, who will continue working hard as part of our Premier League squad.
"I've no doubt that Declan is going to have a big future with us and for his country."
John will hope to be involved in the Cardiff squad that travels to face Stoke City on Wednesday.