The Trope Codifiers are the medieval Matters of Arthur and, especially, Charlemagne (especially the innumerable fantasy novels and verse epics of the 15th through 17th centuries which were based on, set in, or vaguely inspired by the older Carolingian myths). The Arthurian myths have a less militantly idealistic style than the Carolingian ones; the Arthurian work most completely of this style is Sir Gawain and the Green Knight.

This pattern is rarer outside of Europe (and before the Middle Ages) than within it. The closest analogue to European chivalry was bushido, the code of the Japanese Samurai, but the Japanese code emphasized loyalty to one's lord, even to the point of doing evil, while the European one emphasized loyalty to one's conscience, even to the point of treachery.

Of course, that doesn't mean that non-European heroes can't act like this -- and it doesn't mean that European heroes always do, either. The Roman-derived tradition of "My Country, Right or Wrong" was always present in Europe...