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
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/dotnet/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ csharp
└─ src/
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/go/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ go
├─ core/
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/java/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ groups:
- name: fernapi/fern-java-sdk
version: <Markdown src="/snippets/version-number.mdx"/>
config:
client_class_name: YourApiClient
client-class-name: YourApiClient
```

## SDK Configuration Options
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/java/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ java
├─ YourOrganizationApiClient.java
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/php/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ php
└─ sdk/
Expand Down
22 changes: 10 additions & 12 deletions fern/products/sdks/overview/python/custom-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ description: Augment your Python SDK with custom utilities

```python title="src/<package>/helper.py"
def my_helper() -> None:
print "Hello World!"
print("Hello World!")
```

### Add your file to `.fernignore`
Expand Down Expand Up @@ -78,17 +78,15 @@ description: Augment your Python SDK with custom utilities

First, import the Fern generated base clients from `.base_client.py` and extend them to create your custom clients. Then, add whatever methods you want.

```python title="src/<package>/client.py"
from .base_client import \
BaseClient

class YourClient(BaseClient):

def my_helper(self) -> None
print("Hello World")

```

```python title="src/<package>/client.py"
from .base_client import BaseClient // import generated client

class YourClient(BaseClient): // extend generated client
def my_helper(self) -> None:
print("Hello World!")
def my_helper(self) -> None:
print("Hello World")
```
<Note>
See an example [client.py](https://github.com/elevenlabs/elevenlabs-python/blob/main/src/elevenlabs/client.py) from ElevenLabs.
</Note>
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/python/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ python
├─ __init__.py
Expand Down
4 changes: 2 additions & 2 deletions fern/products/sdks/overview/ruby/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ default-group: local
groups:
local:
generators:
- name: fernapi/fern-python
- name: fernapi/fern-ruby
version: <Markdown src="/snippets/version-number.mdx"/>
config:
clientName: YourClientName
clientClassName: YourClientName
```

## SDK Configuration Options
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/ruby/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ ruby
├─ YourOrganization_api_client.gemspec
Expand Down
30 changes: 9 additions & 21 deletions fern/products/sdks/overview/typescript/custom-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@ title: Adding custom code
description: Augment your TypeScript SDK with custom utilities
---

Fern-generated SDKs are designed to be extended with custom code. Your custom
code can add additional functionality to the SDK and live in harmony with the
generated code. This page explains how to configure custom logic using a
`.fernignore` file, create custom SDK methods, and add additional dependencies to your SDK.
<Markdown src="/products/sdks/snippets/custom-code-intro.mdx"/>

## Adding custom logic

If you want your SDK to do more than just make basic API calls (like combining
multiple calls, processing data, adding utilities), you can use `.fernignore` to
protect your custom code from being overwritten during regeneration.

Simply add your custom files to the SDK repository and list them out in `.fernignore`. Fern
won't override any files that you add in `.fernignore`.

To get started adding custom code:
<Markdown src="/products/sdks/snippets/custom-logic-intro.mdx"/>

<Steps>

### Create a new file and add your custom logic

```typescript title="src/helper.ts"
export function myHelper(): void {
return console.log("Hello world!");
return console.log("Hello world!");
}
```

Expand All @@ -42,7 +32,7 @@ To get started adding custom code:

### Consume the helper

Now your users can consume the helper function by importing it from the SDK:
<Markdown src="/products/sdks/snippets/consume-method.mdx"/>

```typescript
import { myHelper } from "sdk/helper";
Expand All @@ -53,9 +43,7 @@ To get started adding custom code:

## Custom SDK methods

Fern also allows you to add custom methods to the SDK itself (e.g.
`client.my_method()` ). by inheriting the Fern generated client and then
extending it.
<Markdown src="/products/sdks/snippets/custom-sdk-methods-intro.mdx"/>

<Note>
See an example from Flatfile using this process in their [TypeScript SDK](https://github.com/FlatFilers/flatfile-node)
Expand Down Expand Up @@ -88,11 +76,11 @@ To get started adding custom code:
Update your `index.ts` file to export the **extended client** instead of the generated client.

```typescript title="src/index.ts"
export { MyClient } from src/wrapper/MyClient; // instead of `src/Client`
export { MyClient } from "src/wrapper/MyClient"; // instead of "src/client"
```

<Note>
See an example [index.ts](https://github.com/FlatFilers/flatfile-node/blob/main/src/index.ts) from Flatline
See an example [index.ts](https://github.com/FlatFilers/flatfile-node/blob/main/src/index.ts) from Flatfile
</Note>

### Update `.fernignore`
Expand All @@ -105,13 +93,13 @@ To get started adding custom code:
```

<Note>
See an example [.fernignore](https://github.com/FlatFilers/flatfile-node/blob/main/.fernignore) from Flatline
See an example [.fernignore](https://github.com/FlatFilers/flatfile-node/blob/main/.fernignore) from Flatfile
</Note>


### Consume the method

Now your users can consume the helper function by importing it from the SDK:
<Markdown src="/products/sdks/snippets/consume-method.mdx"/>

```typescript
client.myHelper()
Expand Down
2 changes: 1 addition & 1 deletion fern/products/sdks/overview/typescript/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ This command adds the following to `generators.yml`:
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>

```bash
fern/ # created in step 1
fern/ # created by fern init
sdks/ # created by fern generate --group sdk
├─ typescript
├─ Client.ts
Expand Down