Search code examples
swiftkotlinsdkide

What is the standard or simplest way to generate an SDK from an API spec?


My API platform product has a solid API reference, available in OpenAPI and Postman formats. This is used to implement apps for iOS and Android, in Swift and Kotlin. I'd like to make that easier by providing SDKs for those platforms.

What is the best practice to generate a Swift, Kotlin, or other SDK from an OpenAPI file?

Options like AWS API Gateway or APImatic would be OK, but they are not great at importing the existing specs, and I can't judge the quality of the result.

I'm wondering if there are IDE features in Xcode or Android Studio for such operations, or maybe extensions?


Solution

  • Typically you can generate client code for a given language from the OpenAPI doc. The tool to use will depend on the language.

    In Swift, you can generate client code using this new repo by Apple. Check out the documentation to get started. This is effectively a build plugin which will generate code on every build, taking in the OpenAPI doc and other config files as input.

    For Kotlin, you can use Fabrikt.

    Alternatively, you can download code directly from the Swagger doc. Take this SwagggerHub page as an example. On the top right there is "Export" where you can export code for the given language. I wouldn't trust it too much though; it'd be better to use a generator which generates client code on each build from the given OpenAPI spec. The library backing that “Export” SDK generator button is on GitHub here.

    Hope that helps.