# How to generate an OpenAPI/Swagger spec with Fastify
Source: https://speakeasy.com/openapi/frameworks/fastify

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



In this tutorial, we'll show you how to generate an OpenAPI specification using [Fastify](https://fastify.dev/). We will also show how you can use Speakeasy to generate client SDKs for your API based on the specification.

<Callout title="Example code" type="info">
  If you want to follow along with the example code in this tutorial, you can
  clone the [Speakeasy Fastify example
  repo](https://github.com/speakeasy-api/guide-fastify-example).
</Callout>

Here's what we'll cover:

1.  How to add `@fastify/swagger` to a Fastify project.
2.  Generate an OpenAPI specification using the Fastify CLI.
3.  Improve the generated OpenAPI specification for better downstream SDK generation.
4.  Use the Speakeasy CLI to generate a client SDK based on our generated OpenAPI specification.
5.  Use the Speakeasy OpenAPI extensions to improve generated SDKs.
6.  How to automate this process as part of a CI/CD pipeline.

Your Fastify project might not be as simple as our example app, but the steps below should translate well to any Fastify project. We'll also look at how to gradually add routes to OpenAPI so that you have the option to ship an SDK that improves API coverage over time.

## The SDK Generation Pipeline

Fastify ships with the [`@fastify/swagger`](https://github.com/fastify/fastify-swagger) plugin, which provides convenient shortcuts for generating good OpenAPI specifications. We'll start this tutorial by registering `@fastify/swagger` in a Fastify project to generate a spec.

The quality of your OpenAPI specification will ultimately determine the quality of generated SDKs and documentation, so we'll dive into ways you can improve the generated specification.

With our new and improved OpenAPI specification in hand, we'll take a look at how to generate SDKs using Speakeasy.

Finally, we'll add this process to a CI/CD pipeline so that Speakeasy automatically generates fresh SDKs whenever your Fastify API changes in the future.

## Requirements

This guide assumes that you have an existing Fastify app or you'll clone our example application, and that you have a basic familiarity with Fastify.

You'll need [Node.js installed](https://nodejs.org/en/download) (we used Node v20.5.1), and you'll need to install the [Fastify CLI](https://github.com/fastify/fastify-cli/).

Once you have Node.js, you can install the Fastify CLI by running the following in the terminal:

```bash
npm install fastify-cli --global
```

Make sure `fastify` is in your `$PATH`:

```bash
fastify version
```

If you can't run `fastify` using the steps above, you can use `npx` to run `fastify-cli` by replacing `fastify` with `fastify-cli` in our code samples.

For example:

```bash