Use Fern Definition to define your API
An overview of how to define your API using the Fern Definition format, then use Fern to generate SDKs and API reference documentation for your API.
A Fern Definition is a set of YAML files that describe your API.
Each Fern Definition file may define:
- Custom types. Use custom types to build your data model.
- Endpoints. Group related endpoints into services.
- Errors. An error represents a failed (non-200) response from an endpoint.
Alternatively, you can use the OpenAPI specification format.
Fern generates SDKs and API reference documentation from your Fern Def. Create a fern/
project through one of our Quickstarts then update the Fern Def files in fern/definitions/
with your own. You can configure API-wide settings with the api.yml file.
Once you’ve defined and configured your API, you can run fern generate to generate SDKs or fern generate —docs to generate docs.
Converting to and from OpenAPI
- Already have an OpenAPI spec and want to convert it to Fern Definition? Run fern write-definition.
- Need to convert your Fern Definition files to an OpenAPI spec to work with OpenAPI tools? Use our OpenAPI generator from your Fern Def.
An example of a Fern Definition
Shown below is a sample from an API defined using Fern Definition. The endpoints are organized into a group called a service
, which share a base-path
of /store
and a default value for auth
. The defined custom types (such as Order
) are analogous to schemas in OpenAPI.