The PayPal Developer team strives to build SDKs and Tools that make it easy for developers and integrators to work with PayPal APIs. Our SDKs are designed with a shared core component that handles cross cutting concerns and different API specific components that contain model classes and utility wrappers.
When we sat down to write the API specific components, lazy developers that we are, we looked out for code generation tools that we could bootstrap on. We found a few open source code generators such as java2wsdl but none that had support for custom templates or could generate classes in multiple languages. So we sat down to write genio (pronounced ‘genie-oh’), our very own code generator that we are happy to now open source.
genio is a pluggable code generation system that can parse various API specification files into a generic model. The parsed model is pumped through a set of templates to generate full fledged classes with class documentation from the API specification file and custom logic for plugging into our core SDKs. The SDKs that you see on GitHub have all been generated using the tool. genio has helped us upgrade our SDKs and other tools within minutes of a new release. The upgrade is often triggered by a git commit hook on the API repo. When we released the new REST APIs back in February, we wrote a new WADL parser that produced genio compliant model objects and with a few minor tweaks to our templates, we were ready with the first version of our REST SDKs. Subsequently we switched to using the Google discovery format and it was a trivial task for us to start generating the SDKs using the new specification format. In all, the current release has parsers for WSDL, WADL and the Google discovery format. We will follow up this release with API documentation generation features and support for JSON schema version 4.
How genio can be useful to you
What has been useful to us is potentially useful to other developers as well. When we saw other groups in eBay Inc. show interest in genio, we plugged new templates to the genio parser to build API references, testing tools, API explorers and so on. And now, we are open sourcing it, hoping that the developer community can benefit as well and also contribute with enhancements.
Any project that implements or consumes APIs can use genio to generate service stubs, client stubs, testing tools etc. genio is being released as two ruby gems:
- genio-parser that parses service specification files into a generic model and
- genio that provides a set of templates and uses genio-parser to generate code.
The client templates shipped with genio in this release generate client stubs that can be plugged directly into our core SDKs. If you have a preferred service framework, you can write new templates that are specific to your framework. You can contribute new templates to genio or add support for new specification formats in genio-parser. We will be thrilled to accept those that target widely used open frameworks / API specification formats.
Look at the genio samples repository for example code generated using genio. Do look out for our next blog post that will tell you how genio can be extended to suit your needs.