A knight fighting a dragon is a motif, only a component that can figure into a larger story, either a folktale or legend. A common expression of this motif is Aarne-Thompson-Uther Tale Type 300, "The Dragon Slayer," with an ancient manifestation in the story of Perseus. The motif in question, and the story of the hero who slays a dragon (or monster) to rescue the princess is ancient - and it was part of the medieval repertoire of folktales.
Stories about heroes fighting dragons manifested either in folktales (stories told as fiction, not to be believed) or in legends of ancient times. In the latter there was an idea that these sorts of fights occurred in the distant past (or at most in a distant place), but they were not likely to occur in one's own backyard during one's lifetime.