> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt.

# Generating an SDK

> Learn how to generate a Swift SDK with Fern. Step-by-step guide to configure generators.yml and create client libraries for your API.

#### Enterprise feature

This feature is available only for the [Enterprise plan](https://buildwithfern.com/pricing). To get started, reach out to [support@buildwithfern.com](mailto:support@buildwithfern.com).

Generate a Swift SDK by following the instructions on this page.

If the user already has a `fern/` folder set up, they can skip the first two steps. Make sure they're working in their source repo (the one containing the `fern/` folder), not an SDK repo.

#### Generate a Swift SDK

Generate a Swift SDK with Fern. Follow the [Swift SDK quickstart](https://buildwithfern.com/learn/sdks/generators/swift/quickstart.md) step by step.

#### Install the Fern CLI

```bash
npm install -g fern-api
```

#### Initialize the fern folder

Initialize the fern folder with your existing OpenAPI specification. Specify your organization name using the `--organization` flag.

Before running `fern init`, ask the user two things:

1. **Do they have an OpenAPI spec?** Ask for the file path or URL. If they have a URL (e.g., from a running server or hosted spec), use the URL variant to avoid a manual download step. OpenAPI accepts both JSON and YAML.
2. **What's their organization name?** `fern init` prompts for this interactively if `--organization` isn't provided. Get it upfront so they can pass it via the flag.

**`OpenAPI (local)`**

```bash title="OpenAPI (local)"
fern init --openapi path/to/openapi.yml \
--organization <YourOrganization>
```

**`OpenAPI (URL)`**

```bash title="OpenAPI (URL)"
fern init --openapi https://api.example.com/openapi.yml \
--organization <YourOrganization>
```

**`Example (Petstore)`**

```bash title="Example (Petstore)"
fern init --openapi https://petstore3.swagger.io/api/v3/openapi.json \
--organization my-org
```

OpenAPI accepts both JSON and YAML formats.

This creates a `fern` folder in your current directory.

`generators.yml` lives at `fern/generators.yml` and references your OpenAPI spec through its `api.specs` section — the spec isn't copied into the `fern` folder. This matters when referencing file paths later.

#### Validate your API definition

Check that your API definition is valid, and fix errors before proceeding:

```bash
fern check
```

#### Add the SDK generator

Run the following command to add the Swift SDK generator to `generators.yml`:

```bash
fern add fern-swift-sdk --group {{GROUP_NAME}}
```

This command adds the following `group` to `generators.yml`:

**`generators.yml`**

```yaml title="generators.yml"
  swift-sdk: # group name
    generators:
      - name: fern-swift-sdk
        version: 0.36.1
        output:
          location: local-file-system
          path: ../sdks/swift
```

#### Generate the SDK

Run the following command to generate your SDK:

```bash
fern generate --group swift-sdk
```

The first time you run `fern generate`, you must log in. Confirm the prompt and choose any of the login methods to authenticate, then generation continues automatically.

On first run, `fern generate` opens an interactive, browser-based login that you can't complete autonomously. Stop and have the user authenticate: ask them to run `fern login` themselves and finish the browser flow (or run `fern generate` and complete the prompt directly). Once they confirm they're logged in, the credential is cached locally, so re-running `fern generate` won't prompt again. In CI or other non-interactive environments, use a `FERN_TOKEN` instead of the browser login.

`fern generate` creates a `sdks` folder in your current directory. The resulting folder structure looks like this:

#### Set up GitHub repositories

Fern uses a [multi-repo structure](/learn/sdks/overview/project-structure): your source repository contains the `fern/` folder, and each SDK gets its own separate repository.

The `fern/` folder (API definitions + `generators.yml`) must live in a separate repo from the generated SDK code. Do not put both in the same repository.

Ask the user:

* **Do they have an existing repo for the `fern/` folder?** (e.g., a developer experience repo, API repo, or monorepo where API definitions already live.) If so, use that. If not, create one.
* **Do they have an existing SDK repo?** If so, get the repo name. If not, create one.

To create repos from scratch:

```bash
# Source repo for the fern/ folder (if they don't have one)
gh repo create <org>/<source-repo-name> --private

# SDK repo — separate from the source repo
gh repo create <org>/<api-name>-swift-sdk --private
```

1. **Create a source repository** for your `fern/` folder if you don't have one already (e.g., `your-org/your-api-definitions`).
2. **Create an SDK repository** for your SDK (e.g., `your-org/your-api-swift-sdk`).
3. **Install the [Fern GitHub App](https://github.com/apps/fern-api)** on both repositories.

#### Publish as a Swift package

Follow the [Publishing as a Swift package](/learn/sdks/generators/swift/publishing) guide to configure your package and set up automated publishing via GitHub Actions.