Fixes #4601: Refactor whole API generation

http://www.rudder-project.org/redmine/issues/4601