-
Notifications
You must be signed in to change notification settings - Fork 3
Restructure "GitHub Setup" page and rename to "Project Structure" #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,109 +1,154 @@ | ||
| --- | ||
| title: Structure your GitHub repositories | ||
| description: Set up GitHub repositories for your SDKs | ||
| title: Project structure | ||
| description: An overview of the file and folder structure of a Fern SDKs project | ||
| --- | ||
|
|
||
| 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. | ||
| Before generating SDKs with Fern, 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 | ||
| ## Repository architecture | ||
|
|
||
| 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**. | ||
| Fern recommends a parent-child repository structure, where: | ||
|
|
||
| For example, your basic GitHub file structure should look something like this: | ||
| - **Parent repository**: Contains your API definitions and SDK generation configuration | ||
| - **Child repositories**: Separate repositories for each SDK (TypeScript, Python, Go, etc.) | ||
|
|
||
| ```bash | ||
| ├─ company-repo # Parent repository | ||
| │ └─ fern/ | ||
| │ ├─ fern.config.json | ||
| │ ├─ apis/ | ||
| │ │ └─ sdks/ | ||
| │ │ └─ generators.yml # References child repos | ||
| ├─ typescript-sdk-repo # Child repository | ||
| ├─ python-sdk-repo # Child repository | ||
| └─ go-sdk-repo # Child repository | ||
| ``` | ||
| ├─ 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: | ||
| This separation allows you to manage API definitions centrally while keeping each SDK in its own repository for independent versioning and distribution. | ||
|
|
||
| ```yaml title="generators.yml" | ||
| ts-sdk: | ||
| generators: | ||
| - name: fernapi/fern-typescript-sdk | ||
| version: 2.6.3 | ||
| github: | ||
| repository: your-organization/your-typescript-repo | ||
| ## Core configuration files | ||
|
|
||
| [Initializing your `fern` folder](/sdks/overview/quickstart) creates two key configuration files: | ||
|
|
||
| ### `fern.config.json` | ||
|
|
||
| This file stores your organization name and Fern CLI version: | ||
|
|
||
| ```json | ||
| { | ||
| "organization": "your-organization", | ||
| "version": "<Markdown src="/products/sdks/snippets/fern-config-json-version.mdx"/>" | ||
| } | ||
| ``` | ||
|
|
||
| For additional examples, see Cohere's [`generators.yml` | ||
| ### `generators.yml` | ||
|
|
||
| The `generators.yml` file specifies which SDKs to generate and where to publish them. It acts as the bridge between your API definitions and your SDK repositories. | ||
|
|
||
| For 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 | ||
|
|
||
| <Info> | ||
| See the [`generators.yml` reference page](/sdks/reference/generators-yml) for complete configuration options. | ||
| </Info> | ||
|
|
||
| ## Parent repository structure | ||
|
|
||
| The parent repository contains your API definitions and the `generators.yml` file that references your child SDK repositories. | ||
|
|
||
| <CodeBlock title="Parent repository structure"> | ||
| ```bash | ||
| company-repo/ | ||
| ├─ fern/ | ||
| │ ├─ fern.config.json | ||
| │ ├─ apis/ | ||
| │ │ └─ sdks/ | ||
| │ │ └─ generators.yml # SDK generation configuration | ||
| ``` | ||
| </CodeBlock> | ||
|
|
||
| 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. | ||
| Your `generators.yml` file contains a group for each SDK and points to the corresponding child 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). | ||
| ```yaml title="generators.yml" | ||
| groups: | ||
| ts-sdk: | ||
| generators: | ||
| - name: fernapi/fern-typescript-sdk | ||
| version: <Markdown src="/snippets/version-number-ts.mdx"/> | ||
| github: | ||
| repository: your-organization/typescript-sdk-repo | ||
|
|
||
| ## 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> | ||
| python-sdk: | ||
| generators: | ||
| - name: fernapi/fern-python-sdk | ||
| version: <Markdown src="/snippets/version-number-python.mdx"/> | ||
| github: | ||
| repository: your-organization/python-sdk-repo | ||
| ``` | ||
|
|
||
| ## Child repository structure | ||
|
|
||
| Each SDK has its own repository with the following structure: | ||
|
|
||
| <CodeBlock title="Child repository structure"> | ||
| ```bash | ||
| typescript-sdk-repo/ # Individual SDK repository | ||
| ├─ .github/workflows/ # Publishing workflows | ||
| ├─ scripts/ | ||
| ├─ src/ | ||
| ├─ tests/ | ||
| └─ .fernignore # Files Fern shouldn't modify | ||
| ``` | ||
| </CodeBlock> | ||
|
|
||
| Fern generates most of these files automatically, including preserving any custom code you've added. | ||
|
|
||
| ## Setup instructions | ||
|
|
||
| 1. **Create repositories**: Set up your parent repository and one child repository for each SDK | ||
| 2. **Install Fern GitHub App**: Install the [Fern GitHub App](https://github.com/apps/fern-api) on all repositories (parent and children) | ||
| 3. **Configure generators.yml**: Add each child repository to your `generators.yml` file | ||
|
|
||
| ## Multiple API definitions | ||
|
|
||
| For multiple APIs, organize them in separate folders within the `apis` directory: | ||
|
|
||
| <Tabs> | ||
| <Tab title="OpenAPI Definition"> | ||
| ```bash | ||
| fern/ | ||
| ├─ fern.config.json | ||
| ├─ generators.yml | ||
| └─ apis/ | ||
| └─ imdb/ | ||
| ├─ generators.yml | ||
| └─ openapi/ | ||
| ├─ openapi.yml | ||
| └─ disney/ | ||
| ├─ generators.yml | ||
| └─ openapi/ | ||
| ├─ openapi.yml | ||
| ``` | ||
| </Tab> | ||
| <Tab title="Fern Definition"> | ||
| ```bash | ||
| fern/ | ||
| ├─ fern.config.json | ||
| ├─ generators.yml | ||
| └─ apis/ | ||
| └─ imdb/ | ||
| ├─ generators.yml | ||
| └─ definition/ | ||
| ├─ api.yml | ||
| └─ imdb.yml | ||
| └─ disney/ | ||
| ├─ generators.yml | ||
| └─ definition/ | ||
| ├─ api.yml | ||
| └─ disney.yml | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| <Info>This guide assumes that you already have an initialized `fern` folder on | ||
| your local machine. See [Set up the `fern` folder](/sdks/overview/quickstart) for more | ||
| details.</Info> | ||
| <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 [Project Structure](/sdks/overview/github). | ||
| </Info> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.