Skip to content

sayari-analytics/fern

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Fern is a toolkit that allows you to effortlessly generate SDKs and API documentation.

Overview Diagram

Note: Fern requires Node 18 or higher

🌿 SDKs

The Fern toolkit is available as a command line interface (CLI). 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://petstore.swagger.io/v2/swagger.json

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 ID Latest Version Changelog Entrypoint
fernapi/fern-typescript-node-sdk 0.11.0 CHANGELOG.md cli.ts
fernapi/fern-python-sdk 0.9.0 CHANGELOG.md cli.py
fernapi/fern-java-sdk 0.8.0 CHANGELOG.md Cli.java
fernapi/fern-ruby-sdk 0.0.6 CHANGELOG.md cli.ts
fernapi/fern-go-sdk 0.16.0 CHANGELOG.md main.go

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 geenerate backend code. Watch a demo here.

Generator ID Latest Version Changelog Entrypoint
fernapi/fern-typescript-express 0.9.7 CHANGELOG.md cli.ts
fernapi/fern-fastapi-server 0.7.7 CHANGELOG.md cli.py
fernapi/fern-java-spring 0.7.1 CHANGELOG.md Cli.java

Model Generators

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

Generator ID Latest Version Changelog Entrypoint
fernapi/fern-pydantic-model 0.8.0 CHANGELOG.md cli.py
fernapi/fern-java-model 0.7.1 CHANGELOG.md Cli.java
fernapi/fern-ruby-model 0.0.6 CHANGELOG.md cli.ts

Spec Generators

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

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

Generator ID Latest Version Changelog Entrypoint
fernapi/fern-openapi 0.0.30 CHANGELOG.md cli.ts
fernapi/fern-postman 0.1.0 CHANGELOG.md cli.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:

For a walkthrough, check out the Fern + Express video.

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:

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

About

SDKs and Docs for your API

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 70.0%
  • Python 9.8%
  • Java 9.2%
  • Go 7.4%
  • MDX 2.7%
  • JavaScript 0.7%
  • Other 0.2%