During World War II, the Swiss were neutral and generally speaking maintained that position, meaning that they did not declare war or offer military assistance to either power, and while they traded, even in goods that had military purposes, they did not openly favor one side over the other (which would have given them "non-belligerent" status, such as in the case of Sweden and Finland in 1939-1940, although I would note that isn't so much a proper term as Neutral). But, that isn't to say they did nothing. The Swiss practiced armed neutrality, meaning they mobilized for possible (defensive) war, and in conducting their trade, courted several controversies. Germany certainly loomed as a threat in some respects, and they considered whether or not to invade, but in the end, it there is little evidence to suggest such an action was imminent, and plenty to point to the idea that Germany was better off with a free, but cooperative Switzerland than one they controlled but had suffered the ravages of war. Anyways though...
When war broke out on September 1st, Switzerland mobilized quicker than the Allied powers. Over 400,000 men of the militia-based Swiss Army had reported to their post within 48 hours of Germany crossing the Polish border, quicker than either France or the UK! This meant that roughly 10 percent of the country was now under arms, and an additional 500,000 or so men and women were in auxiliary organizations such as the FHD, or otherwise in a job that gave direct assistance to the military.
The Swiss military is quite famous for how they are organized around mandatory service, and at the time of World War II, the professional core of the military was tiny - made up mostly of border guards, pilots, and a small cadre of staff officers who kept things running. For the general population, marksmanship was encouraged and cultivated for boys, and when they reached the age of 20, they had a three-month basic training course and were issued a uniform and a rifle - A K31 straight-pull rifle by that point, although older reservists would possibly have a Schmidt-Rubin K11. They now were in the active reserve ("Miliz") until the age of 48, which required that they took a three-week refresher course every year, after which they "retired" to the inactive reserve (Meaning they weren't going to be immediately called up, and didn't need to do the refresher, but still expected to in time of great need). Especially talented individuals could be nominated for the advanced course in alpine warfare, which was another three months, and would allow them to join the elite Mountain Brigades. With the mass call up in 1939 though, the retirement age was temporarily pushed back to 60, and new inductees now underwent a four month course, and those who had been called up began training on a full time basis.
Aside from the nation-in-arms model, the Swiss also had built their country to brace for the worst. Bridges, railways, tunnels, and other infrastructure were made for easy mining, and roads had pre-built holes for the placement of anti-tank stakes. In the event of invasion, 100,000 border troops were to fight a delaying action, blowing up everything they could as they fell back, while civilians were evacuated southwards, and the bulk of the Swiss forces moved into the highly defensible National Redoubt high in the Alps, where Swiss planners believed they could hold off German attacks indefinitely. The plan would of course mean turning over much of the country to the invader, and laying waste to it as well - denying use of infrastructure by the occupier, but also crippling the Swiss themselves were they to retake the land - but at least, they hoped, they could cost whoever chose to violate their neutrality dearly.
For the first few months, very little happened, not just in Switzerland, but on the Franco-German frontier as well - a period known as the "Phony War", or the "Sitzkrieg". But that didn't mean that Switzerland was twiddling their collective thumbs. The greatest fear at that point was of a violation of the Swiss border for a southern sweep into France around the Maginot Line. The geography of the Alps might protect the 'heart of Switzerland' from a direct invasion, to a degree, but the "Swiss Plateau" is considerably more usable for military operations, especially if your end goal is entering France. When the Germans in fact launched Fall Gelb through the Low Countries to the North instead, Switzerland hardly breathed a sigh of relief. Intelligence that they had collected pointed to a German plan to launch a complimentary attack just as they had feared, to be initiated on May 15th. Nothing came to pass of this. There had been some build up, but it was just an exercise, although the purpose may have been to make the French think that was the intent so as to divert forces south.
As we all know, France fell quickly. The immediate effect of this was a massive influx of soldiers in flight. About 30,000 Frenchmen crossed the border and laid down their arms. They would be interned by the Swiss for a few months, until an agreement was reached for their repatriation to France in early 1941. 13,000 Polish soldiers also ended up there, having been serving in France, but they were not repatriated during the war, and instead interned for the duration at several camps. They were utilized for various labor projects such as draining swampland for farming, and after the war most either returned to Poland, or left for some other country, but roughly 1,000 chose to settle in Switzerland.
It wasn't just soldiers though. Thousands upon thousands of refugees, including French Jews, also were making their way to the border. Fearful of being overloaded, very strict quotas were set, and entry was refused to many with the infamous explanation that the "lifeboat is full". 7,000 Jews had already been given entry prior to the war, and not many more were initially to be allowed. The sight of several committing suicide when refused entry caused many guards to start turning a blind eye, and eventually there was some liberalization to the refugee policy, but it nevertheless fell very short. While roughly 20,000 Jewish persons were included in the several hundred thousand refugees and internees who found shelter in Switzerland, about an equal number were turned away at the border. While the Swiss plead that their small country could only handle so many refugees, many both at the time and in decades since assert that a significantly higher number could have been reasonably accommodated (As well as criticizing the treatment of those who were allowed in. The Swiss billed them for room and board, which was deducted from any money that had brought into the country - which the Swiss had made them turn over for "safe keeping". If they couldn't pay, the Swiss later sent bills to the governments of France and Belgium and the Netherlands for the cost after the war).
More so though, the completion of the German invasion of France meant that the immediate threat of invasion was lessened. For some, including President Pilet-Golaz, this meant Erneuerung and Anpassung (Renewal and adaptation), or that is to say, coming to terms with the new European order and attempting to find Switzerland's place in it. One of the first steps towards this was to demobilize 2/3 of the Swiss Army on Pilet-Golaz's orders, with little secret that it was in order to not antagonize Germany needlessly. It isn't at all a stretch to call the decision controversial. There wasn't much outright Nazi sympathies in Switzerland, and while many might have understood the pragmatic requirements given Switzerland's location, sympathies were generally with the Allies. As a popular saying went, "we work for the Germans six days a week, and pray for the Allies on the seventh." As such, the move went against the Swiss self-image and hurt Swiss morale, even if they were somewhat in denial.
The worst hit in the morale department were the Army. In reaction, General Guisan brought 650 Swiss officers to Lake Lucerne, where the old Confederacy had been founded, and gave them a stirring speech about absolute resistance to any invasion, and had them all swear oaths to fight to the end if it happened. It was a great piece of political theater if nothing else, and a major boost to restore Swiss confidence. But again, as I note... the Swiss were a bit in denial.
Whatever their sympathies, the Swiss were surrounded by the Axis and her puppets. Trade with Germany quickly increased three-fold simply because other trading partners had dried up. Despite reclaiming swampland, and planting urban gardens on every scrap of parkland or football pitch they could find, the Swiss were not self-sufficient in food, and had to import. As a neutral power, Switzerland was entitled to trade with the Allies, and still did, but only at a trickle. The Swiss actually purchased a small merchant fleet, which would buy food from the Allies (peanuts from India for example) and then send it by rail through Vichy, but it sometimes could take 6 months to arrive! Perhaps strangest though was the trade of goods that were needed for the war effort. The Swiss continued to trade certain things to the Allies with full knowledge of the Germans who agreed not to stop it, since they also needed Swiss goods. The Allies of course put pressure on the Swiss to reduce trade with the Germans, but it wasn't until 1943-1944 that they were in a position to actually see this happen. Prior to that German pressure was of course dominant. In mid-1940 for instance, the Germans withheld coal shipments until the Swiss signed a new, more favorable trade agreement. Anyways though, just what sort of trading are we talking about of course...?
As I said at the beginning, trade in war goods was happening from both sides, even if the Germans got the bulk. Precision instruments, vital to the Allied war effort, were allowed to be sold to the Allies, who in turn sent important material such as copper and rubber to the Swiss. The Germans allowed this since they too needed Swiss goods, which couldn't be made without that raw material! It was a rather bizarre arrangement, since the both sides knew that to a degree, their trade was helping the enemy! The Germans of course got much more of the Swiss trade during the war years, but that is simply a matter of geography than anything else, and with both sides benefiting, and knowing what was going on, it wasn't particularly controversial.
No, the controversy in Swiss conduct comes from three major factors. The trade in gold, Nazi banking, and Jewish banking.
When the war began, Germany had less than 50 million dollars in gold in their national stores. Yet, during the war, the Allies claimed that the Swiss purchased over 300 million in gold from the Germans. Where did the extra gold come from? Well, the obvious answer is that Nazi Germany stole it from the countries they invaded. With most powers unwilling to accept what was obviously stolen gold as payment for goods, the Swiss didn't have the same scruples. They bought the gold for Swiss francs, which Germany than could use to purchase stuff they needed from other neutral powers such as Turkey. When confronted after the war, the Swiss only would admit to 58 million of French and Belgian gold, which they compensated the respective national banks for. Investigations couldn't prove the rest, and when suspiciously new, gold 20-Fr pieces began appearing in the late 1940s, bearing dates from the 1930s, no one seemed able to prove that the Swiss had melted down the gold and was trying to secretly pass it into circulation.
Gold wasn't all they got though. The Allies also believed there to be hundreds of millions in assets from Nazi officials stashed in Swiss bank accounts. As the occupying powers of Germany, the Allies claimed that ownership of these accounts defaulted to them, while the Swiss not only disagreed, but also claimed near total ignorance, as their strict banking laws prevented any disclosure verifying the claims. It took the United States freezing about one billion dollars of Swiss assets in American banks for the Swiss to cave and make an exception. They agreed to look into the matter, but only if they could do the audit themselves. The result was to turn up ~250 million dollars in German assets, which amounted to only 1/3 of what the Allies believed to be there. And even though the Swiss agreed it existed, it too even more negotiations before they turned over any of it, eventually agreeing to turn over half the amount, with the other half going to the Swiss government to settle outstanding debts that Germany had incurred.
As for the Jewish banking, it is a slightly different beast. It only was revealed many decades later that tens of thousands of bank accounts owned by Holocaust victims had been sitting idle for decades, and the Swiss had done nothing to locate the rightful owners, and even refused to help possible heirs trying to locate the assets. It took diplomatic pressure and a high profile lawsuit for the Swiss to finally pay out a 1.25 billion dollar settlement in 2000, with the money going to Holocaust survivors and heirs of the victims.
So as mentioned before, while the Swiss were never invaded, they practiced armed neutrality, and violations of their sovereignty were met with force, not just because of their innate desire to protect their territorial integrity, but the possibility that if they did not do so, and gave into, say, German demands to fly bombers over Swiss territory, it would put their neutrality into question with the other side.
So for the duration of the war, the border remained well-manned. As mentioned before, refugees were sometimes refused entry, and sometimes allowed, and as various powers suffered setbacks, troops retreated over the border, where they were placed into internment camps as required by international law - not just with the French in 1940, but also happening with the Italians in 1943 (a preferable fate to many than German POW camps, or being forced to fight for the Salo Republic), and the Germans beginning in mid-1944. Throughout the war air men also found themselves in Switzerland for various reasons, which I'll cover later. Sometimes the relations between the German and Swiss border guards were amiable, although early on during the tenser period, the Germans were known to heckle the Swiss and shout over at them about how easily the Swiss Army would be crushed.
Shots fired in anger were rare, and the most notable place where the Swiss saw real action was in the air. The Swiss Air Force was tiny, with just over 200 aircraft total. The most important part of their force were 89 Bf 109-Es, and several 109-Ds (The MS 406 was being built in Switzerland under license, but production only began in late 1939, so few were ready, and it was inferior to the Messerschmitt anyways). As would soon be a sore point for the Germans, they had been bought by the Swiss just prior to the war, and the last of the 'Es' was delivered in early 1940, just before Fall Gelb. With the beginning of the Invasion of France, violations of Swiss airspace became a daily occurrence, and initially the Swiss would attack any flight which entered their country. Small but fierce, the Swiss Air Force quickly proved to be a thorn in Germany's side, and after one encounter which saw ten German aircraft go down in flames for the loss of only two Swiss machines, Hitler rather threateningly insisted that the Swiss cease their interceptions or else. The Swiss were thus forced to compromise their policy, leaving a buffer zone near the border where they would not actively intercept German aircraft, instead only doing so once they had entered further into Swiss airspace, after which they would either be shot down or forced to land.
After the invasion of France, the most notable instance of this policy in action occurred during the test flight of a new Bf 110 nightfighter, equipped with Germany's state of the art radar system, and the new "slanted music" system of upward firing cannons. Straying deep into Swiss territory, she was intercepted, and after attempting to flee, had no choice but to land. With the crew unable to destroy everything before being arrested, German officials were fearful that Allied agents might get their hands on the material, going so far as to draw up plans for an attack on the airfield they believed the plane to be at (it had been moved by then anyways). Negotiations prevailed though, and in exchange for a dozen of the new Bf 109-Gs with spare parts and ammunition, as well as a license for manufacture, the Swiss allowed German officials to be in attendance when the aircraft was destroyed.
Later in the war though, it was usually the Allies overflying Switzerland, and at least when possible, the Swiss continued to force errant planes to land. In the case of the USAAF, 150 B-24s and B-17s were forced down, as well as a small number of other aircraft. Some were planes that got lost due to navigation errors, some were too damaged to make it home, and a few might even have just claimed one of the other two reasons to be true. Whatever the reason, over 600 airmen of the USAAF found themselves interned in Switzerland, mostly housed in ski resorts left vacant by the inexplicable drying up of tourists. The planes were mostly stored at Dübendorf airfield, where a small team of Swiss aircraft groundscrew kept them maintained by periodically pre-flighting the engines and doing other basic maintenance. A number were painted in Swiss colors for their ferrying trip to the field, and the Air Force used several for training aircraft. Interestingly, the 8th Air Force was allowed to send a small group of maintenance men to review the planes in mid-1944, as well as give instruction to the Swiss in how to maintain them. At the end of the war, the planes that were in working order were returned to US, and the Swiss sent the American government a bill for $100,000 to cover the maintenance, and the room and board for the crew.
Not all of the 6,501 violations that the Swiss precisely tabulated were so amusing though. The most tragic, perhaps, was the erroneous bombing of Schaffhausen, when 20 American bombers, believing they were 21 miles over and bombing Germany, killed or injured ~150 Swiss people. The United States agreed to pay 62 million dollars after the war, and issued an apology. As demanded by the Swiss, they also paid interest on the settlement for the time it took to reach it. And not even all the raids were accidents. In one occasion, upset about the production rate at a factory supplying ball-bearings to the Germans, the British dropped a load of bombs nearby to send a message.
The position of the Swiss as a perpetual neutral power placed them in a rather interesting position during the war. Although not the same as the Swiss government of course (so this is something of an aside), the International Red Cross was headquartered there, and staffed by Swiss. The IRC was vitally important to the health and well being of millions of civilians and soldiers during the war, and the work done by it really can't be praised enough. Just to highlight one particular duty, the IRC kept a catalog in Geneva of literally hundreds of thousands of POWs being held by the warring powers, and IRC delegates visited POW camps to check on conditions and facilitate communication home. Care parcels (the United States being by far the larger user of this service) were routinely delivered into IRC custody, from which they would then be delivered to the POWs at their camps. Of course, the delegates couldn't force their way in, or force changes to happen (especially true on the Eastern Front where they were not usually given any access), but in spite of this, they were performing a key service, since, if only due to the threat of quid pro quo reprisals, their reports on the conditions of POWs back to the home country were an important part of maintaining the safety of POWs.
The Invasion that Never Happened
While the Swiss might have been a bit paranoid to believe the Germans were only days away from invasion back in May of 1940, it isn't wrong to say the Germans had a plan for how to do it. Operation Tannenbaum was the overall plan for a possible German invasion of Switzerland, and while it was revised several times to keep things up to date, there was never any definite timetable for putting it into practice (aside from a few haphazard plans for small bits of sabotage). Why? Well, good luck finding a consensus. Many people, foremost being the Swiss themselves, will tell you that the Germans were deterred by the threat of Swiss arms, and the knowledge that even if Switzerland was conquered, her people would never be subdued. It sounds all nice and romantic, and the sentiment existed from the very start of the war - see the earlier mention of Guisan's speech - and remained (remains even) an enduring part of the Swiss self-image even today, although in recent decades there has been more self-evaluation of the conduct during the war. The more pessimistic observers will respond that Germany didn't need to invade Switzerland anyways. Why do so, causing massive destruction of the country, when Swiss businesses and banks were making Germany their primary trading partner anyways. Germany also was reliant on several vulnerable rail links through Swiss territory, which would almost certainly be destroyed if an invasion happened. Under this view, the Swiss hedgehog act didn't really matter. As I said, you can find partisans of either position still, and I don't know how to give true finality to the matter. There are merits on both sides but you obviously can't view the arguments in isolation. The Swiss themselves went through some serious reevaluation of their wartime role in the past two decades, with the creation of the Bergier commission in 1996, and the final report, published in 2002, was quite critical of many aspects of Swiss conduct in the period, especially compared to the Swiss-self image in the decades after.
OK, so to make this all neat and tidy: The Swiss policy of armed neutrality certainly held true during the war. It is hard to doubt the conviction of the Swiss Army to defend their country to the bitter end in the event of an invasion, but this ignores the larger question of whether an invasion ever would have happened. This debate continues even to today, with no shortage of ammunition to call into question aspects of Swiss behavior. Swiss business with Nazi Germany is well documented, and at many times quite unsavory, but must of course be tempered in judgement by the reality of their position - not that it excuses many of the things they did. Those actions, while reprehensible at times, don't exactly make Switzerland into not a neutral country either. Neutral countries are entitled to engage in trade with the warring powers of course. So in the end, what all of this ought to tell you is that:
Yes the Swiss were neutral, but they still managed to piss a fair number of people off for many reasons.
The Bergier Commission report is available for free online, in English. Very long, and very dry, but if that isn't a deterant, check it out here.
The Neutrals by Denis J. Fodor - Part of the Time-Life series on World War II, it also covers Sweden, Spain, and other neutral states. A very summary look at things, and being several decades old it obviously isn't engaged with more recent shifts in scholarship, but still quite a good read if you want something on the simple side.
Strangers in a Strange Land Vol. II Escape to Neutrality by Hans-Heiri Stapfer is specifically about the USAAF and the Swiss
Dissonant Memories: National Identity, Political Power, and the Commemoration of World War Two in Switzerland by Christof Dejung looks at the Swiss self-image in recent decades as it relates to the war.
Swiss and the Nazis by Stephen Halbrook is OK. It certainly has a lot of info on the matter, and Holbrook has written multiple books on the topic, but he is terribly biased, and gets accused of underplaying the collaborative aspects of Swiss actions during the war. But there aren't many books on the topic, so still worth looking at, just remain critical and keep in mind he drank Guisan's Kool-Aid.
Never Despair: Sixty Years in the Service of the Jewish People and of Human Rights by Gerhart Riegne isn't really about this, but I used briefly for the information on treatment of Jewish refugees.