# Comparison guide: OpenAPI/Swagger Go client generation
Source: https://speakeasy.com/docs/sdks/languages/golang/oss-comparison-go

import { Table } from "@/mdx/components";



Speakeasy generates idiomatic Go SDKs based on OpenAPI specifications.

In this post, we'll take a look at why many of our users choose to switch from OpenAPI Generate and other open-source generators to Speakeasy to generate their Go SDKs.

Open-source SDK generators play an important role in experimentation and smaller custom integrations but teams should publish high-quality SDKs for their APIs that offer the best developer experience. Usable SDKs drive adoption by making it easier for developers to switch to the API.

At Speakeasy, we generate idiomatic client SDKs in a variety of languages. Our generators follow principles that ensure we generate SDKs that offer the best developer experience so that you can focus on building your API, and your developer-users can focus on delighting their users.

## Go SDK generator options

We'll compare four Go SDK generators:

1.  The [Go generator](https://openapi-generator.tech/docs/generators/go/) from the [OpenAPI Generator](https://openapi-generator.tech/) project.
2.  [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen), an open-source OpenAPI Client and Server Code Generator.
3.  [ogen](https://ogen.dev/), an open-source OpenAPI v3 code generator for Go.
4.  The [Speakeasy SDK generator](/docs/speakeasy-reference/cli/getting-started).

Below is the summary of how the four evaluated generators compare. Our recommendation is to use Speakeasy for generating Go SDKs for your APIs (1st SDK free). If you are committed to using an open source generator, we strongly recommend that you use [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen)

<Table
  data={[
    {
      feature: "**Version Support**",
      speakeasy: "✅ Go 1.14+",
      openapiGenerator: "⚠️ Variable support",
      oapiCodegen: "✅ Good compatibility",
      ogen: "⚠️ Newer Go versions",
    },
    {
      feature: "**Dependencies**",
      speakeasy: "✅ 3 deps",
      openapiGenerator: "❌ 1500+ deps, requires Java",
      oapiCodegen: "✅ No external deps",
      ogen: "✅ No external deps",
    },
    {
      feature: "**Go Idiomaticity**",
      speakeasy: "✅ Native Go patterns",
      openapiGenerator: "❌ Non-idiomatic",
      oapiCodegen: "✅ Simple patterns",
      ogen: "⚠️ Custom patterns",
    },
    {
      feature: "**Nil-safe Getters**",
      speakeasy: "✅ Built-in safety",
      openapiGenerator: "❌ No safety",
      oapiCodegen: "❌ No safety",
      ogen: "❌ Custom optionals",
    },
    {
      feature: "**Union Types**",
      speakeasy: "✅ Full support",
      openapiGenerator: "❌ No support",
      oapiCodegen: "⚠️ Limited support",
      ogen: "✅ Full support",
    },
    {
      feature: "**Enums**",
      speakeasy: "✅ Type-safe",
      openapiGenerator: "❌ Strings only",
      oapiCodegen: "✅ Type-safe",
      ogen: "✅ Type-safe",
    },
    {
      feature: "**Complex Numbers**",
      speakeasy: "✅ Big decimal",
      openapiGenerator: "❌ Basic types",
      oapiCodegen: "❌ Basic types",
      ogen: "❌ Basic types",
    },
    {
      feature: "**Error Handling**",
      speakeasy: "✅ Custom types",
      openapiGenerator: "⚠️ Generic errors",
      oapiCodegen: "⚠️ Basic errors",
      ogen: "✅ Good errors",
    },
    {
      feature: "**Retries**",
      speakeasy: "✅ Built-in",
      openapiGenerator: "❌ No support",
      oapiCodegen: "❌ No support",
      ogen: "❌ No support",
    },
    {
      feature: "**Pagination**",
      speakeasy: "✅ Built-in",
      openapiGenerator: "⚠️ Manual only",
      oapiCodegen: "⚠️ Manual only",
      ogen: "⚠️ Manual only",
    },
    {
      feature: "**Documentation**",
      speakeasy: "✅ Complete docs",
      openapiGenerator: "⚠️ Basic docs",
      oapiCodegen: "❌ Minimal docs",
      ogen: "⚠️ Basic docs",
    },
    {
      feature: "**CI/CD Integration**",
      speakeasy: "✅ GitHub Actions",
      openapiGenerator: "❌ Manual only",
      oapiCodegen: "❌ Manual only",
      ogen: "❌ Manual only",
    },
  ]}
  columns={[
    { key: "feature", header: "Feature" },
    { key: "speakeasy", header: "Speakeasy" },
    { key: "openapiGenerator", header: "OpenAPI Generator" },
    { key: "oapiCodegen", header: "oapi-codegen" },
    { key: "ogen", header: "ogen" },
  ]}
/>

If you want the detailed technical breakdown, full of code comparisons, read on!

## Installing SDK generators

To start our comparison, we installed all four generators on a local machine running macOS.

### Installing the OpenAPI Generator CLI

OpenAPI Generator depends on Java, [which we covered at length previously](/post/speakeasy-oss-python-generator#our-experience-installing-the-openapi-generator-cli). We concluded that managing the OpenAPI Generator Java dependencies manually just wasn't worth the effort.

Installing `openapi-generator` using Homebrew installs `openjdk@11` and its many dependencies:

```bash
brew install openapi-generator
```

This adds the `openapi-generator` CLI to our path.

### Installing oapi-codegen

We install oapi-codegen using the Go package manager:

```bash
go install github.com/deepmap/oapi-codegen/cmd/oapi-codegen@latest
```

This command installs the oapi-codegen Go module and [its dependencies](https://github.com/deepmap/oapi-codegen/blob/master/go.mod).

### Installing ogen

We followed the [ogen quick start](https://ogen.dev/docs/intro) to install ogen:

```bash
go install -v github.com/ogen-go/ogen/cmd/ogen@latest
```

This installs the ogen Go module with [its dependencies](https://github.com/ogen-go/ogen/blob/main/go.mod).

### How to install the Speakeasy CLI

To install the Speakeasy CLI, follow the steps in the [Speakeasy Getting Started](/docs/speakeasy-reference/cli/getting-started) guide.

In the terminal, run:

```bash
brew install speakeasy-api/tap/speakeasy
```

Next, authenticate with Speakeasy by running the following:

```bash
speakeasy auth login
```

This installs the Speakeasy CLI as a single binary without any dependencies.

## Downloading the Swagger Petstore specification

Before we run our generators, we'll need an OpenAPI specification to generate a Go SDK for. The standard specification for testing OpenAPI SDK generators and Swagger UI generators is the [Swagger Petstore](https://petstore3.swagger.io/).

We'll download the YAML specification at [https://petstore3.swagger.io/api/v3/openapi.yaml](https://petstore3.swagger.io/api/v3/openapi.yaml) to our working directory and name it `petstore.yaml`:

```bash
curl https://petstore3.swagger.io/api/v3/openapi.yaml --output petstore.yaml
```

## Validating the Spec

Both the OpenAPI Generator and Speakeasy CLI can validate an OpenAPI spec. We'll run both and compare the output.

### Validation using OpenAPI Generator

To validate `petstore.yaml` using OpenAPI Generator, run the following in the terminal:

```bash
openapi-generator validate -i petstore.yaml
```

The OpenAPI Generator returns two warnings:

```
Warnings:
	- Unused model: Address
	- Unused model: Customer

[info] Spec has 2 recommendation(s).
```

### Validation using Speakeasy

We'll validate the spec with Speakeasy by running the following in the terminal:

```bash
speakeasy validate openapi -s petstore.yaml
```

The Speakeasy validator returns ten warnings, seven hints that some methods don't specify any return values and three unused components. Each warning includes a detailed JSON-formatted error with line numbers.

Since both validators validated the spec with only warnings, we can assume that both will generate SDKs without issues.

## Generating an SDK

Now that we know our OpenAPI spec is valid, we can start generating SDKs.

We'll generate each SDK in a unique subdirectory, relative to where we saved the `petstore.yaml` spec file.

### OpenAPI generate

OpenAPI Generator features SDK generators for multiple languages, often with multiple options per language. We'll test the Go generator in this post.

We'll generate an SDK by running the following in the terminal:

```bash