diff --git a/fern/products/sdks/overview/java/custom-code.mdx b/fern/products/sdks/overview/java/custom-code.mdx index f197ac3f8..0f73c95de 100644 --- a/fern/products/sdks/overview/java/custom-code.mdx +++ b/fern/products/sdks/overview/java/custom-code.mdx @@ -3,6 +3,117 @@ title: Adding custom code description: Augment your Java SDK with custom utilities --- -Learn how to extend your Fern Java SDK with custom code and utilities. + -This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/capabilities/custom-code). +## Adding custom logic + + + + + + ### Create a new file and add your custom logic + + ```java title="src/main/java//Helper.java" + package com.example.helper; + + public class Helper { + + public static void myHelper() { + System.out.println("Hello World!"); + } + + } + ``` + + ### Add your file to `.fernignore` + + A `.fernignore` file is automatically created in your SDK repository when you use GitHub publishing. + + + ```yaml {3} title=".fernignore" + # Specify files that shouldn't be modified by Fern + + src/main/java//Helper.java + ``` + + ### Consume the helper + + + + ```java + import com.example.helper.Helper; + + public class Main { + + public static void main(String[] args) { + Helper.myHelper(); + } + + } + ``` + + + ## Adding custom SDK methods + + + + + ### Update `generators.yml` configuration + Name your Fern-generated client something like `BaseClient` to reflect that this client will be extended. + + ```yml {4} title="generators.yml" + - name: fernapi/fern-java-sdk + version: "..." + config: + client-class-name: BaseClient + ``` + + ### Import and extend the generated client + + First, import the Fern generated base client and extend it. Then, add whatever methods you want. + + ```java title="src/main/java/com/example/MyClient.java" + package com.example; + + import com.example.client.BaseClient; + + public class MyClient extends BaseClient { // extend the Fern generated client + + public void myHelper() { + System.out.println("Hello World!"); + } + + } + ``` + + ### Update `.fernignore` + + Add the `MyClient.java` to `.fernignore`. + + ```diff title=".fernignore" + + src/main/java/com/example/MyClient.java + ``` + + ### Consume the method + + + + ```java + client.myHelper(); + ``` + + + +## Adding custom dependencies + +To add packages that your custom code requires, update your `generators.yml`. + + ```yaml {4-7} title="generators.yml" + - name: fernapi/fern-java-sdk + version: "..." + config: + custom-dependencies: + - org.apache.commons:commons-lang3:3.12.0 + - org.slf4j:slf4j-api:2.0.7 + + ``` \ No newline at end of file diff --git a/fern/products/sdks/overview/python/custom-code.mdx b/fern/products/sdks/overview/python/custom-code.mdx index b24dc83c7..946e3df8d 100644 --- a/fern/products/sdks/overview/python/custom-code.mdx +++ b/fern/products/sdks/overview/python/custom-code.mdx @@ -3,21 +3,11 @@ title: Adding custom code description: Augment your Python 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 Python SDK. + ## 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: + @@ -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: + ```python from package.helper import my_helper @@ -53,9 +43,7 @@ To get started adding custom code: ## Adding 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. + 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: ### Update `generators.yml` configuration - To add a custom method to the Python SDK, you will need to configure the - generator to output the client in a file called `base_client.py`. Then, you can - extend the base client and add whatever methods you want. + Name your Fern-generated client something like `BaseClient` to reflect + that this client will be extended. Configure the generator to output the + client in a file called `base_client.py`. ```yaml {4-8} title="generators.yml" - name: fernapi/fern-python-sdk @@ -121,7 +109,7 @@ To get started adding custom code: ### Consume the method - Now your users can consume the helper function by importing it from the SDK: + ```python client.my_helper() diff --git a/fern/products/sdks/snippets/consume-method.mdx b/fern/products/sdks/snippets/consume-method.mdx new file mode 100644 index 000000000..95801a417 --- /dev/null +++ b/fern/products/sdks/snippets/consume-method.mdx @@ -0,0 +1 @@ + Now your users can consume the helper function by importing it from the SDK. \ No newline at end of file diff --git a/fern/products/sdks/snippets/custom-code-intro.mdx b/fern/products/sdks/snippets/custom-code-intro.mdx new file mode 100644 index 000000000..c51cbea6a --- /dev/null +++ b/fern/products/sdks/snippets/custom-code-intro.mdx @@ -0,0 +1,6 @@ +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. \ No newline at end of file diff --git a/fern/products/sdks/snippets/custom-logic-intro.mdx b/fern/products/sdks/snippets/custom-logic-intro.mdx new file mode 100644 index 000000000..772a441be --- /dev/null +++ b/fern/products/sdks/snippets/custom-logic-intro.mdx @@ -0,0 +1,8 @@ +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: \ No newline at end of file diff --git a/fern/products/sdks/snippets/custom-sdk-methods-intro.mdx b/fern/products/sdks/snippets/custom-sdk-methods-intro.mdx new file mode 100644 index 000000000..2d962309a --- /dev/null +++ b/fern/products/sdks/snippets/custom-sdk-methods-intro.mdx @@ -0,0 +1,3 @@ +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. \ No newline at end of file