This question already has an answer here:
I purchased a flight from Brazil to Spain, with stopover in Morocco. My intention is to fly to Morocco and not take the second leg to Spain. I do not need a visa to Morocco but I need a Schengen Visa to enter Spain. Will I be allowed to board the first leg (Brazil->Morocco)?