Only during their fight between Doffy that Law learned about them being a celestial dragon.
Although initially, the One Piece was thought to be a massive treasure of gold and riches, with time, more information regarding the treasure was revealed to the fans and it was evident that there is much more to it than what fans thought.
Gol D Roger and Oden also heard or the talking about the birthing of their sovereign and another sovereign in a distant land.
That is the God Valley Incident.