|
| 1 | +--- |
| 2 | +title: Adding custom code |
| 3 | +description: Augment your SDK with custom utilities |
| 4 | +--- |
| 5 | + |
| 6 | +Fern-generated SDKs are designed to be extended with custom logic, methods, and dependencies. If you want your SDK to do more than just make basic API calls (like combining multiple calls, processing data, adding utilities), you can add custom code that lives in harmony with the generated code. |
| 7 | + |
| 8 | +You can also add custom methods by inheriting the Fern generated client and extending it, plus add any dependencies that your custom methods depend on in your `generators.yml` file. |
| 9 | + |
| 10 | +## Using `.fernignore` to preserve your customizations |
| 11 | + |
| 12 | +Once you add files containing custom code, use `.fernignore` to protect your custom code from being overwritten when Fern regenerates your SDK. |
| 13 | + |
| 14 | +Simply add your custom files to the SDK repository and list them in `.fernignore`. Fern won't override any files listed there. A `.fernignore` file is automatically created in your SDK repository when you use GitHub publishing. |
| 15 | + |
| 16 | +Your `.fernignore` file might look something like this: |
| 17 | + |
| 18 | +```gitignore title=".fernignore" |
| 19 | +# Documentation and licensing |
| 20 | +README.md |
| 21 | +LICENSE |
| 22 | +
|
| 23 | +# Custom workflows |
| 24 | +.github/workflows/test.yml |
| 25 | +.github/workflows/ci.yml |
| 26 | +
|
| 27 | +# Custom code |
| 28 | +src/CustomClient.ts |
| 29 | +``` |
| 30 | +<Note>For another example, see Cohere's [`.fernignore` file for their TypeScript SDK](https://github.com/cohere-ai/cohere-typescript/blob/ad583e3003bd51e80a82317f9e16beec85881b86/.fernignore).</Note> |
| 31 | + |
| 32 | +You'll have a separate `.fernignore` file for each of your SDKs: |
| 33 | + |
| 34 | +```text {9, 13} |
| 35 | +├─ company-repo # Top-level repo for all SDKs |
| 36 | + ├─ fern/ |
| 37 | + ├─ apis/ |
| 38 | + ├─ sdks/ |
| 39 | + └── generators.yml # Contains settings for all SDKs |
| 40 | + ├─ typescript-sdk-repo # Repository for a TypeScript SDK |
| 41 | + ├─ .github/workflows/ |
| 42 | + ├─ src/ |
| 43 | + └── .fernignore |
| 44 | + ├─ python-sdk-repo |
| 45 | + ├─ .github/workflows/ |
| 46 | + ├─ src/ |
| 47 | + └── .fernignore |
| 48 | +``` |
| 49 | + |
| 50 | + |
| 51 | + ## Augmenting your SDK with custom code |
| 52 | + |
| 53 | + Get started adding custom code to a specific SDK: |
| 54 | + |
| 55 | + <CardGroup cols={3}> |
| 56 | + <Card title="TypeScript" icon={<img src="./images/icons/ts-light.svg" alt="TypeScript logo" className="h-6 w-6" noZoom />} href="/sdks/generators/typescript/custom-code"> |
| 57 | + </Card> |
| 58 | + <Card title="Python" icon={<img src="./images/icons/python-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/python/custom-code"> |
| 59 | + </Card> |
| 60 | + <Card title="Go" icon={<img src="./images/icons/go-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/go/custom-code"> |
| 61 | + </Card> |
| 62 | + <Card title="Java" icon={<img src="./images/icons/java-light.svg" className="h-6 w-6" noZoom />} href="/sdks/generators/java/custom-code"> |
| 63 | + </Card> |
| 64 | + <Card title=".NET" icon={<img src="./images/icons/csharp-light.svg" className="h-6 w-6" noZoom />}> |
| 65 | + Coming soon |
| 66 | + </Card> |
| 67 | + <Card title="PHP" icon={<img src="./images/icons/php-light.svg" className="h-6 w-6" noZoom />}> |
| 68 | + Coming soon |
| 69 | + </Card> |
| 70 | + <Card title="Ruby" icon={<img src="./images/icons/ruby-light.svg" className="h-6 w-6" noZoom />}> |
| 71 | + Coming soon |
| 72 | + </Card> |
| 73 | + </CardGroup> |
0 commit comments