Using Open API Specification To Put Lyft SDK Support in the Fast Lane

We love reducing the time it takes for developers to go from 0 to 60 on Lyft’s platform. While integrating a third-party RESTful API is usually straightforward, having access to an SDK reduces a non-trivial amount of programming friction. To that end, we’ve embarked on a project to bring the Lyft API to a wider spectrum of programming languages.

Manually writing API wrappers involves creating massive amounts of boilerplate code. One of the strategies to automate this process involves the use of tooling that leverages an API Description Language.

The Open API (formerly known as Swagger) specification offers a language-agnostic approach of describing RESTful APIs. It is maintained by the Open API Initiative— a group “focused on creating, evolving, and promoting” the spec in the broader development community. At Lyft, we’re leveraging OAS for describing both our internal and external APIs. As an example, here’s how our /ridetypes endpoint looks like in the OAS YAML file:

Until today, our OAS use has been limited to generating reference documentation. But we knew we could expand its use for the benefit of our developers. One of the more interesting projects created under the OAS umbrella is Swagger Codegen, a template-based engine that parses spec files to generate documentation, server stubs, and API clients.

So we rolled up our sleeves, took off our pink mustaches, and harnessed the power of {{mustache}} templates. We’re excited to announce the release of our official Go SDK, the first in a string of client libraries built using OAS and Swagger Codegen.

Generating client libraries involves customizing the provided language-specific templates. For example, here’s a snippet of the template that defines how Go method signature are generated:

func (a {{{classname}}}Service) {{{nickname}}}({{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals map[string]interface{}{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}} *http.Response, error)

The corresponding Go code looks like so:

func (a PublicApiService) GetCost(startLat float64, startLng float64, localVarOptionals map[string]interface{}) (CostEstimateResponse, *http.Response, error)

The amount of modification each template needs varies by language and we’re looking forward to working with the Swagger Codegen community to share our refinements.

This is a v1.0 release of the Go SDK; we have a number of improvements in the pipeline that we will be releasing over the coming weeks. We hope you enjoy using it and please reach out if you have any issues or feedback via GitHub.

To get updates about the Lyft Developer Platform, follow us on Medium and Twitter.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.