Home

Awesome

<br/> <div align="center"> <a href="https://www.buildwithfern.com/?utm_source=github&utm_medium=readme&utm_campaign=fern&utm_content=logo"> <img src="/fern/images/logo-primary.svg" height="80" align="center" alt="header" /> </a> <br/> <br/>

2023 Y Combinator Startup License

Slack Documentation

</div>

Fern is a toolkit that allows you to input your API Definition and output SDKs and API documentation. Fern is compatible with the OpenAPI specification (formerly Swagger).

<div align="center"> <a href="/fern/images/overview-dark.png" target="_blank"> <picture> <source srcset="/fern/images/overview-dark.png" media="(prefers-color-scheme: dark)"> <source srcset="/fern/images/overview-light.png" media="(prefers-color-scheme: light)"> <img src="/fern/images/overview-light.png" width="700" alt="Overview Diagram"> </picture> </a> </div>

šŸŒæ SDKs

The Fern toolkit is available via a command line interface (CLI) and requires Node 18+. To install it, run:

npm install -g fern-api

Initialize Fern with your OpenAPI spec:

fern init --openapi ./path/to/openapi.yml
# or
fern init --openapi https://link.buildwithfern.com/petstore-openapi

Your directory should look like the following:

fern/
ā”œā”€ fern.config.json
ā”œā”€ generators.yml # generators you're using
ā””ā”€ openapi/
  ā””ā”€ openapi.json # your openapi document

Finally, to invoke the generator, run:

fern generate

šŸŽ‰ Once the command completes, you'll see your SDK in /generated/sdks/typescript.

šŸŒæ API Documentation

Fern can also build and host a documentation website with an auto-generated API reference. Write additional pages in markdown and have them versioned with git. Search, SEO, dark mode, and popular components are provided out-of-the-box. Plus, you can customize the colors, font, logo, and domain name.

Check out docs built with Fern:

Get started here.

šŸŒæ Generators

Generators are process that take your API Definition as input and output artifacts (SDKs, Postman Collections, Server boilerplate, etc.). To add a generator run fern add <generator id>

SDK Generators

Generator IDLatest VersionEntrypoint
fernapi/fern-typescript-node-sdkTypescript Generator Versioncli.ts
fernapi/fern-python-sdkPython Generator Versioncli.py
fernapi/fern-java-sdkJava Generator VersionCli.java
fernapi/fern-ruby-sdkRuby Generator Versioncli.ts
fernapi/fern-go-sdkGo Generator Versionmain.go
fernapi/fern-csharp-sdkC# Generator Versioncli.ts

Server-side Generators

Fern's server-side generators output boilerplate application code (models and networking logic). This is intended for spec-first or API-first developers, who write their API definition (as an OpenAPI spec or Fern definition) and want to generate backend code.

Generator IDLatest VersionEntrypoint
fernapi/fern-typescript-expressTypescript Express Server Generator Versioncli.ts
fernapi/fern-fastapi-serverPython FastAPI Server Generator Versioncli.py
fernapi/fern-java-springJava Spring Server Generator VersionCli.java

Model Generators

Fern's model generators will output schemas or types defined in your OpenAPI spec or Fern Definition.

Generator IDLatest VersionEntrypoint
fernapi/fern-pydantic-modelPydantic Model Generator Versioncli.py
fernapi/java-modelJava Model Generator VersionCli.java
fernapi/fern-ruby-modelRuby Model Generator Versioncli.ts
fernapi/fern-go-modelGo Model Generator Versionmain.go

Spec Generators

Fern's spec generators can output an OpenAPI spec or a Postman collection.

Note: The OpenAPI spec generator is primarily intended for Fern Definition users. This prevents lock-in so that one can always export to OpenAPI.

Generator IDLatest VersionEntrypoint
fernapi/fern-openapiOpenAPI Generator Versioncli.ts
fernapi/fern-postmanPostman Generator Versioncli.ts

šŸŒæ CLI Commands

Here's a quick look at the most popular CLI commands. View the documentation for all CLI commands.

fern init: adds a new starter API to your repository.

fern check: validate your API definition and Fern configuration.

fern generate: run the generators specified in generators.yml in the cloud.

fern generate --local: run the generators specified in generators.yml in docker locally.

fern add <generator>: include a new generator in your generators.yml. For example, fern add fern-python-sdk.

Advanced

API First

Fern supports developers and teams that want to be API-first or Spec-first.

Define your API, and use Fern to generate models, networking code and boilerplate application code. The generated code adds type safety to your API implementation - if your backend doesn't implement the API correctly, it won't compile.

Frameworks currently supported:

Fern Definition

While we are big fans of OpenAPI, we know it isn't the easiest format to read and write. If you're looking for an alternative, give the Fern Definition a try.

Install the Fern CLI and initialize a Fern Project.

npm install -g fern-api
fern init

This will create the following folder structure in your project:

fern/
ā”œā”€ fern.config.json # root-level configuration
ā”œā”€ generators.yml # generators you're using
ā””ā”€ definition/
  ā”œā”€ api.yml  # API-level configuration
  ā””ā”€ imdb.yml # endpoints, types, and errors

Here's what the imdb.yml starter file looks like:

types:
  MovieId: string

  Movie:
    properties:
      id: MovieId
      title: string
      rating:
        type: double
        docs: The rating scale is one to five stars

  CreateMovieRequest:
    properties:
      title: string
      rating: double

service:
  auth: false
  base-path: /movies
  endpoints:
    createMovie:
      docs: Add a movie to the database
      method: POST
      path: /create-movie
      request: CreateMovieRequest
      response: MovieId

    getMovie:
      method: GET
      path: /{movieId}
      path-parameters:
        movieId: MovieId
      response: Movie
      errors:
        - MovieDoesNotExistError

errors:
  MovieDoesNotExistError:
    status-code: 404
    type: MovieId

Checkout open source projects that are using Fern Definitions:

Inspiration

Fern is inspired by internal tooling built to enhance the developer experience. We stand on the shoulders of giants. While teams were responsible for building the following tools, we want to give a shout out to Mark Elliot (creator of Conjure at Palantir), Michael Dowling (creator of Smithy at AWS), and Ian McCrystal (creator of Stripe Docs).

Community

Join our Discord! We are here to answer questions and help you get the most out of Fern.

Contributing

We welcome community contributions. For guidelines, refer to our CONTRIBUTING.md.

Fern Contributors