Project structure
Configuring fern starts with the fern
folder, which contains your API definitions,
SDK generators, and your CLI version.
Fern recommends a multi-repository structure with your fern folder in a source repository (containing your API definitions and generation configuration) and each generated SDK in its own separate repository.
Directory structure
When you run fern init
(for the Fern Definition) or fern init --spec-type path/to/spec
(for other specs), your fern folder is initialized with the following files:
Core configuration files
Beyond the core files, you can optionally use an overrides file to customize your API definition without modifying the original spec. See Overrides for instructions.
fern.config.json file
Every fern folder has a single fern.config.json
file. This file stores the organization and
the version of the Fern CLI that you are using.
Every time you run a fern CLI command, the CLI downloads itself at the correct version to ensure determinism.
generators.yml
The generators.yml
file specifies which SDKs to generate. For OpenAPI, it also points to the location of your spec. For Fern Definition, Fern automatically detects your spec when your definition/
folder is at the same level as generators.yml
.
OpenAPI
Fern Definition
API definition file
For Fern Definition, your API configuration is split across two files: api.yml
for API-wide configuration and separate .yml
files for your actual endpoint and type definitions. See What is a Fern Definition? for more information.
For the other specification formats (OpenAPI, AsyncAPI, OpenRPC, and gRPC), you’ll have a single self-contained specification file.
api-name
property in your docs.yml
file.Multiple APIs
When working with multiple API definitions, you can organize them in multiple ways depending on your SDK generation needs.
Separate SDKs for each API
Use this approach when each API should generate its own independent set of SDKs.
Each API must have its own generators.yml
file:
Combined SDKs from multiple APIs
Pro and Enterprise feature
This feature is available only for the Pro and Enterprise plans. You can merge up to five APIs into a single SDK on the Pro plan, and unlimited APIs on the Enterprise plan. To get started, reach out to support@buildwithfern.com.
Use this approach to merge multiple APIs into a single set of SDKs.
List all APIs in a single generators.yml
:
If your APIs have overlapping schema names, add namespaces:
Versioned APIs in the same SDK
Use this approach when you need to support multiple API versions simultaneously in your SDK.
Option 1: Branch-based versioning
Each API version is maintained as a separate spec that publishes to a different branch of a single SDK repository. This approach allows you to release updates for older API versions independently and manage each as a different major version of your SDK (v1.x.x, v2.x.x).
Each API version must have its own generators.yml
file that targets a specific branch:
apis/v1/generators.yml
apis/v2/generators.yml
Option 2: Namespace-based versioning
If you prefer a single package with multiple API versions, use namespaces. This generates clients like client.v1
and client.v2
within the same package. Note that this increases package size as all versions are bundled together.
List all API versions in a single generators.yml
with namespaces: