I think most of the credit goes to the traders who came from other lands (with whom Somalis and other indeginous peoples from the hinterland traded)...
If you look beyond the Somali coast to the greater Indian Ocean trade, you will see that Mogadishu, Marka, Brava/Barawe, Kismayo etc were part of a chain of city states going all the way to Lamu, Malindi, Mombasa, Dar es Salaam, Kilwa and all the way down to Sofala in Mozambique (and Zanzibar, looping back to Muscat/Oman and Indian ports in present-day India). Literally a ring of city states around the ocean front.
The unique thing about all these city states was they had a unique culture of intense mixing of people, races and languages with an Islamic identity leading to new identities defined by the cities e.g. Reer Xamar, Reer Marka, Reer Zanzibar, Reer City ZZZ and of course Arabic as the language of trade and government.