Skip to content

Latest commit

History

History
144 lines (115 loc) 路 3.71 KB

generate-your-first-sdk.mdx

File metadata and controls

144 lines (115 loc) 路 3.71 KB
title description
Generate your first SDK
Use Fern's CLI tool to generate your first SDK.
Generating SDKs often requires understanding the state of your OpenAPI spec as well as your specific requirements. For the ideal experience, we **strongly recommend** scheduling a [demo](https://buildwithfern.com/contact) or [emailing us](mailto:support@buildwithfern.com) to get started.

If you'd rather get started immediately, you can use Fern's CLI tool to generate your first SDK.

### Install the Fern CLI

First, install the CLI tool by running the following command:

npm install -g fern-api

Initialize the Fern Folder

If you have an OpenAPI spec, you can initialize the Fern folder by running the following command:
  ```bash
  fern init --openapi path/to/openapi.yml
  ```
  
  If your OpenAPI spec is hosted on the web, you can use the URL:

  ```bash
  fern init --openapi https://api.example.com/openapi.yml
  ```

  This will create a `fern` folder in your current directory with the OpenAPI spec.

  ```sh
  fern/
    鈹溾攢 fern.config.json # root-level configuration
    鈹斺攢 api/ # your API
      鈹溾攢 generators.yml # generators you're using
      鈹斺攢 openapi/
        鈹溾攢 openapi.yml  # API-level configuration
  ```
</Accordion>
<Accordion title="Fern Definition">
  If you'd like to use the Fern Definition, you can initialize the Fern folder 
  by running the following command:

  ```bash
  fern init
  ```

  This will create a `fern` folder in your current directory with the Fern Definition.

  ```sh
  fern/
    鈹溾攢 fern.config.json # root-level configuration
    鈹斺攢 api/ # your API
      鈹溾攢 generators.yml # generators you're using
      鈹斺攢 definition/
        鈹溾攢 api.yml  # API-level configuration
        鈹斺攢 imdb.yml # endpoints, types, and errors
  ```

</Accordion>

Pass fern check

Run fern check to ensure that your API Definition is valid. If there are any errors, you will need to fix them before proceeding.

If you're using an OpenAPI spec, check out all of our [supported extensions](/learn/api-definition/openapi/extensions).

Add the SDK Generator

By default, none of the pro features will be enabled.

You can now use the SDK in your application. Here's an example of how you can use the SDK:

```sh fern add fern-typescript-node-sdk --group sdk ``` ```sh fern add fern-python-sdk --group sdk ``` ```sh fern add fern-java-sdk --group sdk ``` ```sh fern add fern-go-sdk --group sdk ``` ```sh fern add fern-ruby-sdk --group sdk ```

Run fern generate --group sdk

Next up, run the following command to generate the SDK:

fern generate --group sdk

This will create a fern folder in your current directory with the Fern Definition. For example, if you're generating a TypeScript SDK, the folder structure will look like this:

sdks/
  typescript/
    src/
      鈹溾攢 index.ts
      鈹溾攢 Client.ts
      鈹斺攢 api
      鈹斺攢 errors   
      鈹斺攢 serialization