Many of the authors that served in various real-life wars (and survived) wrote stories that are at least somewhat based on their own experiences. Some of them are outright memoirs or fictionalized accounts of their exploits.
Albert Prago, volunteer, served in the Abraham Lincoln XV International Brigade on the Republican side (Our fight : writings by veterans of the Abraham Lincoln Brigade, Spain, 1936–1939)
William Golding, participated in the invasion of Normandy on D-Day, commanding a landing ship that fired salvoes of rockets onto the beaches, and was in action at Walcheren at which 23 out of 24 assault craft were sunk. (Lord of the Flies)
.Günter Grass Nobel Prize 1999, Waffen-SS, Germany. Tin Drum
Dashiell Hammett, was assigned to Army Intelligence on the Aleutian Islands. He assisted in writing Battle of the Aleutians... He went on to write a number of detective novels
William Woodruff was a Major in the 24th Guards Brigade of the British 1st Infantry Division at Anzio. Vessel of Sadness[1] is based on his experience of the battle.