Skip to content

Commit 40f9c4b

Browse files
authored
(api definitions) Document branch-based and namespace-based API versioning (#1196)
1 parent cbf7026 commit 40f9c4b

File tree

1 file changed

+91
-1
lines changed

1 file changed

+91
-1
lines changed

fern/products/api-def/pages/project-structure.mdx

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ For the other specification formats ([OpenAPI](/api-definitions/openapi/overview
5555

5656
## Multiple APIs
5757

58-
When working with multiple API definitions, you can organize them in two ways depending on your SDK generation needs.
58+
When working with multiple API definitions, you can organize them in multiple ways depending on your SDK generation needs.
5959

6060
<AccordionGroup>
6161
<Accordion title="Separate SDKs for each API">
@@ -124,5 +124,95 @@ api:
124124
- namespace: payments
125125
openapi: payments-api/openapi.yml
126126
```
127+
</Accordion>
128+
<Accordion title="Versioned APIs in the same SDK">
129+
130+
Use this approach when you need to support multiple API versions simultaneously in your SDK.
131+
132+
#### Option 1: Branch-based versioning
133+
134+
Each API version is maintained as a separate spec that publishes to a different branch of a single SDK repository. This approach allows you to release updates for older API versions independently and manage each as a different major version of your SDK (v1.x.x, v2.x.x).
135+
136+
```bash
137+
fern/
138+
├─ fern.config.json
139+
└─ apis/
140+
├─ v1/
141+
│ ├─ generators.yml # Configures v1 SDK
142+
│ └─ openapi.yml
143+
└─ v2/
144+
├─ generators.yml # Configures v2 SDK
145+
└─ openapi.yml
146+
```
147+
148+
Each API version must have its own `generators.yml` file that targets a [specific branch](/sdks/reference/generators-yml#github):
149+
150+
<Tabs>
151+
<Tab title="apis/v1/generators.yml">
152+
153+
```yaml title="apis/v1/generators.yml" {11}
154+
api:
155+
specs:
156+
- openapi: openapi.yml
157+
groups:
158+
ts-sdk:
159+
generators:
160+
- name: fernapi/fern-typescript-sdk
161+
github:
162+
repository: company/sdk
163+
mode: push
164+
branch: v1 # Targets v1 branch
165+
```
166+
</Tab>
167+
<Tab title="apis/v2/generators.yml">
168+
169+
```yaml title="apis/v2/generators.yml" {11}
170+
api:
171+
specs:
172+
- openapi: openapi.yml
173+
groups:
174+
ts-sdk:
175+
generators:
176+
- name: fernapi/fern-typescript-sdk
177+
github:
178+
repository: company/sdk
179+
mode: pull-request
180+
branch: v2 # Targets v2 branch
181+
```
182+
</Tab>
183+
</Tabs>
184+
185+
#### Option 2: Namespace-based versioning
186+
187+
If you prefer a single package with multiple API versions, use namespaces. This generates clients like `client.v1` and `client.v2` within the same package. Note that this increases package size as all versions are bundled together.
188+
189+
```bash
190+
fern/
191+
├─ fern.config.json
192+
├─ generators.yml # Single config for all versions
193+
└─ apis/
194+
├─ v1/
195+
│ └─ openapi.yml
196+
└─ v2/
197+
└─ openapi.yml
198+
```
199+
200+
List all API versions in a single `generators.yml` with namespaces:
201+
202+
```yaml title="generators.yml"
203+
api:
204+
specs:
205+
- namespace: v1
206+
openapi: apis/v1/openapi.yml
207+
- namespace: v2
208+
openapi: apis/v2/openapi.yml
209+
groups:
210+
ts-sdk:
211+
generators:
212+
- name: fernapi/fern-typescript-sdk
213+
github:
214+
repository: company/sdk
215+
```
216+
127217
</Accordion>
128218
</AccordionGroup>

0 commit comments

Comments
 (0)