Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions fern/products/sdks/fern-folder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,9 @@ in different languages and [augmenting them with custom code](/sdks/overview/cus
{/* <Markdown src="/products/sdks/snippets/option-3-asyncapi.mdx"/> */}
</AccordionGroup>

### Generate an SDK in your desired language

<CardGroup cols={3}>
<Card title="TypeScript" icon={<img src="./images/icons/ts-light.svg" alt="TypeScript logo" className="h-6 w-6" noZoom />} href="/sdks/generators/typescript/quickstart">
</Card>
<Card title="Python" icon={<img src="./images/icons/python-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/python/quickstart">
</Card>
<Card title="Go" icon={<img src="./images/icons/go-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/go/quickstart">
</Card>
<Card title="Java" icon={<img src="./images/icons/java-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/java/quickstart">
</Card>
<Card title=".NET" icon={<img src="./images/icons/csharp-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/csharp/quickstart">
</Card>
<Card title="PHP" icon={<img src="./images/icons/php-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/php/quickstart">
</Card>
<Card title="Ruby" icon={<img src="./images/icons/ruby-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/php/quickstart">
</Card>
</CardGroup>
### Set up GitHub

Now, you're ready to [set up your GitHub repositories](/sdks/overview/github).

### Augment your SDK with custom code

Expand Down
109 changes: 109 additions & 0 deletions fern/products/sdks/github-setup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: Structure your GitHub repositories
description: Set up GitHub repositories for your SDKs
---

Before generating SDKs with Fern, you'll need to set up the proper GitHub
repository structure to house your API definitions and SDK code so it's
intuitive for you and your users to access, maintain, and update code.

<Steps>
## Structuring your top-level repository

1. Identify or create a top-level GitHub repository where you want all of your
SDK and API code to live.
1. Install the [Fern GitHub App](https://github.com/apps/fern-api) on the
top-level repository and all SDK repositories. Select **Configure**, then
scroll down to **Repository Access**. Select **Only select repositories** and
in the dropdown select the repository for your SDK. Click **Save**.

For example, your basic GitHub file structure should look something like this:

```
├─ company-repo # Top-level repo for all SDKs
├─ fern/
├─ apis/
├─ sdks/
└── generators.yml # Contains settings for all SDKs
```
Your `generators.yml` file will contain a group for each of your SDKs. Each group points
to the GitHub repository for the relevant SDK.

For example, the `group` for a TypeScript SDK might look like this:

```yaml title="generators.yml"
ts-sdk:
generators:
- name: fernapi/fern-typescript-sdk
version: 2.6.3
github:
repository: your-organization/your-typescript-repo
```

For additional examples, see Cohere's [`generators.yml`
file](https://github.com/cohere-ai/cohere-developer-experience/blob/23d6c541a01eb6b54dd9bb3588c805bb0e307713/fern/apis/sdks/generators.yml)
and Vapi's [`generators.yml`
file](https://github.com/VapiAI/docs/blob/9c674c2b16ba03e864e26673c5290c88048c9a7a/fern/apis/api/generators.yml).

<Info>You can also additionally configure the `github` section to whether Fern
should commit and release, create a pull request, or push code to a branch when
you make changes to your SDK code. See [GitHub
Configuration](/sdks/reference/generators-yml#github-configuration) for more
details. </Info>

## Structuring SDK-specific repositories

1. Create a new GitHub repository called `company-<language>` (or something
similar) for each of your SDKs, if you haven't done so already.
1. Install the [Fern GitHub App](https://github.com/apps/fern-api) on the
top-level repository and all SDK repositories. Select **Configure**, then
scroll down to **Repository Access**. Select **Only select repositories** and
in the dropdown select the repository for your SDK. Click **Save**.


The repository structure for a specific SDK should look similar to this:

```{6-11}
├─ company-repo # Top-level repo for all SDKs
├─ fern/
├─ apis/
├─ sdks/
└── generators.yml # Contains settings for all SDKs
├─ typescript-sdk-repo # Repository for a TypeScript SDK
├─ .github/workflows/ # Contains GitHub Actions for publishing to package repositories, etc.
├─ scripts/
├─ src/
├─ tests/
└── .fernignore # Lists files that Fern shouldn't modify
├─ python-sdk-repo
└── go-sdk-repo
```

Fern generates most of the SDK files listed in this example repository (`scripts/`, `src/`, `tests`,
`.fernignore`, etc.), including any custom code you added. You have to manually set up `.github/workflows` to execute actions, like publishing SDK versions to a package repository.

For additional examples, see Cohere's [Python SDK repository](https://github.com/cohere-ai/cohere-python) and [Vapi's TypeScript SDK repository](https://github.com/VapiAI/server-sdk-typescript).

## Generate an SDK in your desired language

Once you've set up your GitHub repository structure, you can proceed with generating SDKs in your desired languages.

<CardGroup cols={3}>
<Card title="TypeScript" icon={<img src="./images/icons/ts-light.svg" alt="TypeScript logo" className="h-6 w-6" noZoom />} href="/sdks/generators/typescript/quickstart">
</Card>
<Card title="Python" icon={<img src="./images/icons/python-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/python/quickstart">
</Card>
<Card title="Go" icon={<img src="./images/icons/go-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/go/quickstart">
</Card>
<Card title="Java" icon={<img src="./images/icons/java-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/java/quickstart">
</Card>
<Card title=".NET" icon={<img src="./images/icons/csharp-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/csharp/quickstart">
</Card>
<Card title="PHP" icon={<img src="./images/icons/php-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/php/quickstart">
</Card>
<Card title="Ruby" icon={<img src="./images/icons/ruby-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/php/quickstart">
</Card>
</CardGroup>

</Steps>

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
147 changes: 94 additions & 53 deletions fern/products/sdks/overview/typescript/publishing-to-npm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,28 @@ you'll have a versioned package published on npm.
<img src="assets/npm-packages.png" alt="Versioned package published on npm" />
</Frame>

<Markdown src="/products/sdks/snippets/setup-fern-folder-callout.mdx"/>
<Info>
This page assumes that you have:

## Set up your GitHub integration
* An initialized `fern` folder on your local machine. See [Set up the `fern`
folder](/sdks/overview/quickstart).
* A GitHub repository for your TypeScript SDK. See [Set up your GitHub structure](/sdks/overview/github).
* A TypeScript generator group in `generators.yml`. See [TypeScript
Quickstart](quickstart#add-the-sdk-generator).

1. Create a new GitHub repository called `company-typescript` (or something similar) for your SDK, if you haven't done so already.
1. Install the [Fern GitHub App](https://github.com/apps/fern-api): Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**.

</Info>

## Configure `generators.yml`

<Steps>

<Step title="Run `fern add <generator>`">

Navigate to your `generators.yml` on your local machine. Your `generators.yml` lives inside of your `fern` folder and contains all the configuration for your Fern generators.

Add a new generator to `generators.yml`:


```bash
fern add fern-typescript-sdk --group ts-sdk
```

Once the command completes, you'll see a new group created in your `generators.yml`:

```yaml {3-9}
groups:
...
ts-sdk:
generators:
- name: fernapi/fern-typescript-sdk
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
output:
location: local-file-system
path: ../sdks/typescript
```

</Step>

<Step title="Configure `output` location">

Next, change the output location in `generators.yml` from `local-file-system` (the default) to `npm` to indicate that Fern should publish your package directly to the npm registry:
In the `group` for your TypeScript SDK, change the output location in from `local-file-system` (the default) to `npm` to indicate that Fern should publish your package directly to the npm registry:

```yaml {6-7}
groups:
ts-sdk:
ts-sdk: # Group name for your TypeScript SDK
generators:
- name: fernapi/fern-typescript-sdk
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
Expand Down Expand Up @@ -106,7 +82,7 @@ groups:

<Step title="Add repository location">

Add the path to your GitHub repository to `generators.yml`:
Add the path to your GitHub repository to `generators.yml`, if you haven't already:

```yaml {11-12}
groups:
Expand All @@ -118,15 +94,15 @@ groups:
location: npm
package-name: your-package-name
config:
namespaceExport: your-client-name
namespaceExport: YourClientName
github:
repository: your-org/company-typescript
```

</Step>
</Steps>

## Set up npm publishing authentication
## Generate an npm token

<Steps>

Expand Down Expand Up @@ -184,6 +160,79 @@ groups:

</Step>

</Steps>

## Configure npm authentication

<AccordionGroup>
<Accordion title="Option 1: Configure authentication via GitHub Actions">

Use [GitHub Actions](https://docs.github.com/en/actions/get-started/quickstart) to automatically publish new SDK versions to npm when you push code changes.

<Steps>

<Step title="Navigate to Actions in Settings">

Open your Fern repository in GitHub. Click on the **Settings** tab in your repository. Then, under the **Security** section, open **Secrets and variables** > **Actions**.

<Frame>
<img src="assets/github-secret.png" alt="Adding GitHub Repository Secret" />
</Frame>

You can also use the url `https://github.com/<your-repo>/settings/secrets/actions`.

</Step>

<Step title="Add secret for your npm Token">

1. Select **New repository secret**.
1. Name your secret `NPM_TOKEN`.
1. Add the corresponding token you generated above.
1. Click **Add secret**.

<Frame>
<img src="assets/npm-token-secret.png" alt="NPM_TOKEN secret" />
</Frame>

</Step>

<Step title="Allow GitHub to run workflows">

Change your workflow permissions to allow GitHub to run workflows:

1. Click on the **Settings** tab in your repository.
1. Under the **Code and automation** section, navigate to **Actions** > **General**.
1. Under **Actions permissions**, select **Allow all actions and reusable workflows**.
1. **Save** your settings. Now GitHub can run the actions you configure.

</Step>
<Step title="Add token to `generators.yml`">

Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable (which you just configured in your GitHub repo) for authentication when publishing to the npm registry.

```yaml {9}
groups:
ts-sdk:
generators:
- name: fernapi/fern-typescript-sdk
version: <Markdown src="/snippets/typescript-sdk-version.mdx"/>
output:
location: npm
package-name: name-of-your-package
token: ${NPM_TOKEN}
config:
namespaceExport: YourClientName
github:
repository: your-org/your-repository
```

When you regenerate your release, Fern will automatically create a workflow in your repository called `.github/workflows/ci.yml` that will automatically publish your release to npm. For an example, see Vapi's [npm publishing GitHub Action](https://github.com/VapiAI/server-sdk-typescript/blob/main/.github/workflows/ci.yml)
</Step>
</Steps>

</Accordion>
<Accordion title="Option 2: Configure via environment variables">
<Steps>
<Step title="Configure npm authentication token">

Add `token: ${NPM_TOKEN}` to `generators.yml` to tell Fern to use the `NPM_TOKEN` environment variable for authentication when publishing to the npm registry.
Expand All @@ -199,20 +248,11 @@ groups:
package-name: name-of-your-package
token: ${NPM_TOKEN}
config:
namespaceExport: your-client-name
namespaceExport: YourClientName
github:
repository: your-org/your-repository
```
</Step>

</Steps>

## Release your SDK to NPM

At this point, you're ready to generate a release for your SDK.

<Steps>

<Step title="Set npm environment variable">

Set the `NPM_TOKEN` environment variable on your local machine:
Expand All @@ -222,8 +262,13 @@ groups:
```

</Step>
</Steps>
</Accordion>
</AccordionGroup>



<Step title="Generate your release">
## Release your SDK to npm

Regenerate your SDK and publish it on npm:

Expand All @@ -232,8 +277,4 @@ groups:
```
Local machine output will verify that the release is pushed to your
repository and tagged with the version you specified. Log back into npm and
navigate to **Packages** to see your new release.

</Step>

</Steps>
navigate to **Packages** to see your new release.
12 changes: 9 additions & 3 deletions fern/products/sdks/overview/typescript/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ description: Get started quickly with the Fern TypeScript SDK.

Generate a TypeScript SDK by following the instructions on this page.

<Markdown src="/products/sdks/snippets/setup-fern-folder-callout.mdx"/>
<Info>
This page assumes that you have:

* An initialized `fern` folder on your local machine. See [Set up the `fern`
folder](/sdks/overview/quickstart).
* A GitHub repository for your TypeScript SDK. See [Set up your GitHub repositories](/sdks/overview/github).
</Info>

<Steps>

<Markdown src="/products/sdks/snippets/pass-fern-check.mdx"/>

### Add the SDK generator
## Add the SDK generator

Run the following command to add the TypeScript SDK generator to `generators.yml`:

Expand All @@ -37,7 +43,7 @@ This command adds the following `group` to `generators.yml`:
location: local-file-system
path: ../sdks/typescript
```
### Generate the SDK
## Generate the SDK

Run the following command to generate your SDK:

Expand Down
3 changes: 3 additions & 0 deletions fern/products/sdks/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ navigation:
- page: Quickstart
path: ./fern-folder.mdx
slug: quickstart
- page: GitHub Setup
path: ./github-setup.mdx
slug: github
- page: Adding Custom Code
path: ./custom-code.mdx
slug: custom-code
Expand Down