If you were to build an API, would you write it from scratch or generate it? Why? What are the pros and cons?

I thought of writing my own REST API generator but the variables are endless. I feel like that I'm trying to re-invent the wheel but it's pointless when there are better ones like Swagger.