Skip to content

Commit 95685eb

Browse files
Kapil GowruKapil Gowru
authored andcommitted
feat: merged with master
2 parents bfa8d85 + ca81178 commit 95685eb

20 files changed

+1026
-53
lines changed

fern/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ js:
141141
strategy: beforeInteractive
142142

143143
analytics:
144-
posthog:
145-
api-key: ${POSTHOG_API_KEY}
144+
# posthog:
145+
# api-key: ${POSTHOG_API_KEY}
146146
gtm:
147147
container-id: GTM-55W3VNDW
148148

fern/products/sdks/overview/dotnet/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
7878
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>
7979

8080
```bash
81-
fern/ # created in step 1
81+
fern/ # created by fern init
8282
sdks/ # created by fern generate --group sdk
8383
├─ csharp
8484
└─ src/
Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,102 @@
11
---
22
title: Adding custom code
3-
description: Augment your TypeScript SDK with custom utilities
3+
description: Augment your Go SDK with custom utilities
44
---
55

6-
Learn how to extend your Fern Go SDK with custom code and utilities.
6+
<Markdown src="/products/sdks/snippets/custom-code-intro.mdx"/>
77

8-
<Warning>This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/capabilities/custom-code).</Warning>
8+
## Adding custom logic
9+
10+
<Markdown src="/products/sdks/snippets/custom-logic-intro.mdx"/>
11+
12+
<Steps>
13+
14+
### Create a new file and add your custom logic
15+
16+
```go title="helper.go"
17+
func MyHelper() {
18+
fmt.Println("Hello World!")
19+
}
20+
```
21+
22+
### Add your file to `.fernignore`
23+
24+
<Tip>A `.fernignore` file is automatically created in your SDK repository when you use GitHub publishing.</Tip>
25+
26+
27+
```yaml {3} title=".fernignore"
28+
# Specify files that shouldn't be modified by Fern
29+
30+
helper.go
31+
```
32+
33+
### Consume the helper
34+
35+
<Markdown src="/products/sdks/snippets/consume-method.mdx"/>
36+
37+
```go
38+
import "github.com/package/example"
39+
40+
example.MyHelper();
41+
```
42+
</Steps>
43+
44+
## Adding custom SDK methods
45+
46+
<Markdown src="/products/sdks/snippets/custom-sdk-methods-intro.mdx"/>
47+
48+
<Steps>
49+
### Update `generators.yml` configuration
50+
Name your Fern-generated client something like `BaseClient` to reflect that this client will be extended.
51+
52+
```yml {4} title="generators.yml"
53+
- name: fernapi/fern-java-sdk
54+
version: "..."
55+
config:
56+
client-class-name: BaseClient
57+
```
58+
59+
### Import and extend the generated client
60+
61+
First, import the Fern generated base client and extend it. Then, add whatever methods you want.
62+
63+
```go title="client/my_client.go"
64+
type MyClient struct {
65+
*Client // Embed the Fern generated client.
66+
}
67+
68+
func NewMyClient(opts ...option.RequestOption) *MyClient {
69+
return &MyClient{
70+
Client: NewClient(opts...),
71+
}
72+
}
73+
74+
func (m *MyClient) MyHelper() {
75+
fmt.Println("Hello World!")
76+
}
77+
```
78+
79+
### Update `.fernignore`
80+
81+
Add the `client/my_client.go.` to `.fernignore`.
82+
83+
```diff title=".fernignore"
84+
+ client/my_client.go
85+
```
86+
87+
### Consume the method
88+
89+
Instead of constructing the generated client, your users will want to construct the extended client.
90+
91+
```go title="main.go"
92+
import exampleclient "github.com/package/example/client"
93+
94+
client := exampleclient.NewMyClient():
95+
```
96+
97+
<Markdown src="/products/sdks/snippets/consume-method.mdx"/>
98+
99+
```go
100+
client.MyHelper()
101+
```
102+
</Steps>

fern/products/sdks/overview/go/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
7878
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>
7979

8080
```bash
81-
fern/ # created in step 1
81+
fern/ # created by fern init
8282
sdks/ # created by fern generate --group sdk
8383
├─ go
8484
├─ core/

fern/products/sdks/overview/java/configuration.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ groups:
1212
- name: fernapi/fern-java-sdk
1313
version: <Markdown src="/snippets/version-number.mdx"/>
1414
config:
15-
client_class_name: YourApiClient
15+
client-class-name: YourApiClient
1616
```
1717
1818
## SDK Configuration Options

fern/products/sdks/overview/java/custom-code.mdx

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,117 @@ title: Adding custom code
33
description: Augment your Java SDK with custom utilities
44
---
55

6-
Learn how to extend your Fern Java SDK with custom code and utilities.
6+
<Markdown src="/products/sdks/snippets/custom-code-intro.mdx"/>
77

8-
<Warning>This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/capabilities/custom-code).</Warning>
8+
## Adding custom logic
9+
10+
<Markdown src="/products/sdks/snippets/custom-logic-intro.mdx"/>
11+
12+
<Steps>
13+
14+
### Create a new file and add your custom logic
15+
16+
```java title="src/main/java/<package>/Helper.java"
17+
package com.example.helper;
18+
19+
public class Helper {
20+
21+
public static void myHelper() {
22+
System.out.println("Hello World!");
23+
}
24+
25+
}
26+
```
27+
28+
### Add your file to `.fernignore`
29+
30+
<Tip>A `.fernignore` file is automatically created in your SDK repository when you use GitHub publishing.</Tip>
31+
32+
33+
```yaml {3} title=".fernignore"
34+
# Specify files that shouldn't be modified by Fern
35+
36+
src/main/java/<package>/Helper.java
37+
```
38+
39+
### Consume the helper
40+
41+
<Markdown src="/products/sdks/snippets/consume-method.mdx"/>
42+
43+
```java
44+
import com.example.helper.Helper;
45+
46+
public class Main {
47+
48+
public static void main(String[] args) {
49+
Helper.myHelper();
50+
}
51+
52+
}
53+
```
54+
</Steps>
55+
56+
## Adding custom SDK methods
57+
58+
<Markdown src="/products/sdks/snippets/custom-sdk-methods-intro.mdx"/>
59+
60+
<Steps>
61+
### Update `generators.yml` configuration
62+
Name your Fern-generated client something like `BaseClient` to reflect that this client will be extended.
63+
64+
```yml {4} title="generators.yml"
65+
- name: fernapi/fern-java-sdk
66+
version: "..."
67+
config:
68+
client-class-name: BaseClient
69+
```
70+
71+
### Import and extend the generated client
72+
73+
First, import the Fern generated base client and extend it. Then, add whatever methods you want.
74+
75+
```java title="src/main/java/com/example/MyClient.java"
76+
package com.example;
77+
78+
import com.example.client.BaseClient;
79+
80+
public class MyClient extends BaseClient { // extend the Fern generated client
81+
82+
public void myHelper() {
83+
System.out.println("Hello World!");
84+
}
85+
86+
}
87+
```
88+
89+
### Update `.fernignore`
90+
91+
Add the `MyClient.java` to `.fernignore`.
92+
93+
```diff title=".fernignore"
94+
+ src/main/java/com/example/MyClient.java
95+
```
96+
97+
### Consume the method
98+
99+
<Markdown src="/products/sdks/snippets/consume-method.mdx"/>
100+
101+
```java
102+
client.myHelper();
103+
```
104+
</Steps>
105+
106+
107+
## Adding custom dependencies
108+
109+
To add packages that your custom code requires, update your `generators.yml`.
110+
111+
```yaml {4-7} title="generators.yml"
112+
- name: fernapi/fern-java-sdk
113+
version: "..."
114+
config:
115+
custom-dependencies:
116+
- org.apache.commons:commons-lang3:3.12.0
117+
- org.slf4j:slf4j-api:2.0.7
118+
119+
```

fern/products/sdks/overview/java/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
7878
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>
7979

8080
```bash
81-
fern/ # created in step 1
81+
fern/ # created by fern init
8282
sdks/ # created by fern generate --group sdk
8383
├─ java
8484
├─ YourOrganizationApiClient.java

fern/products/sdks/overview/php/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
7878
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>
7979

8080
```bash
81-
fern/ # created in step 1
81+
fern/ # created by fern init
8282
sdks/ # created by fern generate --group sdk
8383
├─ php
8484
└─ sdk/

fern/products/sdks/overview/python/custom-code.mdx

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@ title: Adding custom code
33
description: Augment your Python SDK with custom utilities
44
---
55

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

118
## Adding custom logic
129

13-
If you want your SDK to do more than just make basic API calls (like combining
14-
multiple calls, processing data, adding utilities), you can use `.fernignore` to
15-
protect your custom code from being overwritten during regeneration.
16-
17-
Simply add your custom files to the SDK repository and list them out in `.fernignore`. Fern
18-
won't override any files that you add in `.fernignore`.
19-
20-
To get started adding custom code:
10+
<Markdown src="/products/sdks/snippets/custom-logic-intro.mdx"/>
2111

2212
<Steps>
2313

@@ -26,7 +16,7 @@ To get started adding custom code:
2616

2717
```python title="src/<package>/helper.py"
2818
def my_helper() -> None:
29-
print "Hello World!"
19+
print("Hello World!")
3020
```
3121

3222
### Add your file to `.fernignore`
@@ -42,7 +32,7 @@ To get started adding custom code:
4232

4333
### Consume the helper
4434

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

4737
```python
4838
from package.helper import my_helper
@@ -53,9 +43,7 @@ To get started adding custom code:
5343

5444
## Adding custom SDK methods
5545

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

6048
<Note>
6149
See an example from ElevenLabs using this process in their [Python SDK](https://github.com/elevenlabs/elevenlabs-python/blob/main/src/elevenlabs/client.py).
@@ -64,9 +52,9 @@ To get started adding custom code:
6452
<Steps>
6553
### Update `generators.yml` configuration
6654

67-
To add a custom method to the Python SDK, you will need to configure the
68-
generator to output the client in a file called `base_client.py`. Then, you can
69-
extend the base client and add whatever methods you want.
55+
Name your Fern-generated client something like `BaseClient` to reflect
56+
that this client will be extended. Configure the generator to output the
57+
client in a file called `base_client.py`.
7058

7159
```yaml {4-8} title="generators.yml"
7260
- name: fernapi/fern-python-sdk
@@ -90,17 +78,15 @@ To get started adding custom code:
9078

9179
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.
9280

93-
```python title="src/<package>/client.py"
94-
from .base_client import \
95-
BaseClient
96-
97-
class YourClient(BaseClient):
98-
99-
def my_helper(self) -> None
100-
print("Hello World")
101-
102-
```
103-
81+
```python title="src/<package>/client.py"
82+
from .base_client import BaseClient // import generated client
83+
84+
class YourClient(BaseClient): // extend generated client
85+
def my_helper(self) -> None:
86+
print("Hello World!")
87+
def my_helper(self) -> None:
88+
print("Hello World")
89+
```
10490
<Note>
10591
See an example [client.py](https://github.com/elevenlabs/elevenlabs-python/blob/main/src/elevenlabs/client.py) from ElevenLabs.
10692
</Note>
@@ -121,7 +107,7 @@ To get started adding custom code:
121107

122108
### Consume the method
123109

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

126112
```python
127113
client.my_helper()

fern/products/sdks/overview/python/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This command adds the following to `generators.yml`:
7878
<Markdown src="/products/sdks/snippets/generate-sdk.mdx"/>
7979

8080
```bash
81-
fern/ # created in step 1
81+
fern/ # created by fern init
8282
sdks/ # created by fern generate --group sdk
8383
├─ python
8484
├─ __init__.py

0 commit comments

Comments
 (0)