The api.yml configuration file
A fern/
folder has a special file called api.yml
, which includes all the API-wide configuration.
API name
This name is used to uniquely identify your API in your organization. If you just have one API, then api
is a sufficient name.
API description
You can define a top level API description. This description will come through in the OpenAPI spec and Postman collection.
API version
You can define your API version scheme, such as a X-API-Version
header. The supported versions and default value are specified like so:
Authentication
You can specify the authentication scheme used by your API.
Out of the box, Fern supports Bearer
and Basic
authentication schemes.
You can also create your own authentication schemes.
And additionally customize the naming conventions used for standard frameworks such as Basic
:
and Bearer
:
Custom authentication schemes include custom OAuth
integrations, too. Simply hook up your OAuth token endpoint and
optionally configure environment variables to read from like so:
If you need further customization, you can specify the request-properties
and response-properties
to bind specific
properties defined on the request
and response
:
If the expires-in
property is set, the generated OAuth token provider will automatically refresh the token when it expires.
Otherwise, it’s assumed that the access token is valid indefinitely.
With this, all of the OAuth logic happens automatically in the generated SDKs. As long as you configure these settings, your client will automatcally retrieve an access token and refresh it as needed.
Global headers
You can specify headers that are meant to be included on every request:
Global path parameters
You can specify path parameters that are meant to be included on every request:
Global query parameters
You cannot yet specify query parameters that are meant to be included on every request. If you’d like to see this feature, please upvote this issue.
Environments
You can specify the environments where your backend is deployed. These are useful in most generated outputs, like SDKs and in Postman Collections.
You can also provide a default environment:
Multiple URLs per environment
You can specify multiple URLs per environment. This is helpful if you have a microservice architecture, and you want a single SDK to interact with multiple servers.
If you choose to use this feature, you must specify a url
for each service you define:
Error discrimination strategy
In order to generate SDKs idiomatically, Fern needs to know how to differentiate between different errors when parsing an endpoint response.
Discriminate by status code
You can specify Fern to discriminate by status code. This means on each endpoint, every error that’s listed must have a different HTTP status code.
Discriminate by error name
You can specify Fern to discriminate by error name. If you select this strategy, then Fern will assume that every error response has an extra property denoting the error name.
If you use Fern to generate server-side code, then this option provides the most flexibility. Otherwise, you’ll probably want to use the status code discrimination strategy.
Global errors
You can import and list errors that will be thrown by every endpoint.