Cut the sausage/salami into thick slices, remove the skin from each slice and cut it into small pieces. If you are using a soft sausage you can save some pieces to be added when layering the dish.
Peel and chop the onion and let it simmer in a frying pan or skillet with extra virgin olive oil. When it becomes transparent, add two thirds of the spicy sausage pieces if they are soft and all if you are using a harder sausage.
Let the sausage brown a little, then add the wine. Increase the heat until the alcohol evaporates, then add the cherry tomatoes (if using) let them cook a little. Then add the peeled tomatoes or passata.
Add salt to taste and then, cover the sauce and let it cook on a medium heat for about 30 minutes, stirring occasionally. When nearly ready add chopped basil.
Put a pot of water on to boil for the pasta. Add salt once it starts to boil and bring to the boil again. Break the pasta into pieces if it's too long for your pot. Cook the pasta very al dente according to the instructions on the packet.
In the meantime, cut the mozzarella and/or scamorza into slices.
Save a cup of the pasta cooking water, then drain the pasta and add it to the prepared sauce. If the sauce seems too dry had some of the pasta cooking water first.
Grease a baking dish with olive oil. Put part of the pasta with sauce in an even layer on the bottom of the dish. ( I used a terracotta dish)
Cover the pasta with some slices of cheese and some of the remaining sausage pieces (if soft sausage). Make a second layer of pasta and continue this way until the ingredients are exhausted, ending with the pasta
Finish the dish with some more pieces of scamorza and mozzarella and a generous sprinkling of grated pecorino.
Bake in a preheated oven at 200 ° for about 20 minutes or until the cheese on top starts to brown. You can also finish it off under the grill for 2 minutes if it isn’t brown enough after 20 minutes in the oven.
Let the baked pasta rest for a few minutes before serving.