You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: fern/products/api-def/pages/project-structure.mdx
+91-1Lines changed: 91 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ For the other specification formats ([OpenAPI](/api-definitions/openapi/overview
55
55
56
56
## Multiple APIs
57
57
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.
59
59
60
60
<AccordionGroup>
61
61
<Accordiontitle="Separate SDKs for each API">
@@ -124,5 +124,95 @@ api:
124
124
- namespace: payments
125
125
openapi: payments-api/openapi.yml
126
126
```
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
+
<Tabtitle="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:
0 commit comments