Not only did Switzerland have a well-trained civilian militia, there’s also the huge problem of invading a mountainous country. By 1940, the Swiss built a very extensive system of fortifications that took full advantage of the mountainous terrain of the country and any land invasion would have resulted in massive casualties on the German side because the Swiss defender held the “high ground” in too many parts of the country.
I recall reading a conversation between Hitler and a subordinate about invading Switzerland. The Subordinate said something to the effect that "surely we can beat their army?"
To which Hitler was said to have responded, "Switzerland doesn't have an army. Switzerland IS an Army. "
The main Swiss battle rifle was also an accurate long range self rotating bolt that was accurate and lethal to a thousand yards. The Germans would have paid a high price in manpower to invade. A price they could afford.