Skip to content

Commit 73747dd

Browse files
devin-ai-integration[bot]tjb9dcdevalog
authored
docs: add documentation for x-fern-sdk-variables extension (#1748)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]> Co-authored-by: Devin Logan <[email protected]>
1 parent d9a5b23 commit 73747dd

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

fern/products/api-def/api-def.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ navigation:
5858
- page: SDK method names
5959
path: ./openapi-pages/extensions/method-names.mdx
6060
slug: method-names
61+
- page: SDK variables
62+
path: ./openapi-pages/extensions/sdk-variables.mdx
6163
- page: Tag display names
6264
path: ./openapi-pages/extensions/tag-display-name.mdx
6365
- page: Parameter names

fern/products/api-def/openapi-pages/extensions/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The table below shows all available extensions and links to detailed documentati
2626
| [`x-fern-ignore`](./ignoring-elements) | Skip reading specific endpoints or schemas |
2727
| [`x-fern-sdk-method-name`](./method-names) | Customize SDK method names |
2828
| [`x-fern-sdk-group-name`](./method-names) | Organize methods into SDK groups |
29+
| [`x-fern-sdk-variables`](./sdk-variables) | Set common path parameters across all requests |
2930
| [`x-fern-parameter-name`](./parameter-names) | Customize parameter variable names |
3031
| [`x-fern-property-name`](./property-names) | Customize object property variable names |
3132
| [`x-fern-type-name`](./schema-names) | Override auto-generated names for inline schemas |
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: SDK variables
3+
description: Use `x-fern-sdk-variables` to set common path parameters across all requests
4+
---
5+
6+
The `x-fern-sdk-variables` extension allows you to define variables that are set once during SDK client initialization and automatically used in path parameters across all endpoint calls. This is useful for common parameters like tenant IDs, organization IDs, or environment identifiers that appear in many endpoint paths.
7+
8+
<Note>
9+
SDK variables are supported in TypeScript (v2.6.3+), Python (v4.24.0+), and Java (v3.6.3+). Only string types are supported.
10+
</Note>
11+
12+
## Configuration
13+
14+
Define variables at the document level using `x-fern-sdk-variables`, then mark path parameters as variables using `x-fern-sdk-variable`:
15+
16+
```yaml {1-7,17,23} title="openapi.yml"
17+
x-fern-sdk-variables:
18+
gardenId:
19+
type: string
20+
description: The unique identifier for your garden
21+
zoneId:
22+
type: string
23+
description: The zone within the garden
24+
25+
paths:
26+
/gardens/{gardenId}/zones/{zoneId}/plants:
27+
get:
28+
operationId: list_plants_in_zone
29+
parameters:
30+
- name: gardenId
31+
in: path
32+
required: true
33+
x-fern-sdk-variable: gardenId
34+
schema:
35+
type: string
36+
- name: zoneId
37+
in: path
38+
required: true
39+
x-fern-sdk-variable: zoneId
40+
schema:
41+
type: string
42+
```
43+
44+
## SDK usage
45+
46+
Variables become required constructor parameters instead of being passed to individual method calls:
47+
48+
<CodeBlocks>
49+
```typescript {2-3}
50+
const client = new PlantClient({
51+
gardenId: "garden_123",
52+
zoneId: "zone_456",
53+
apiKey: "your-api-key"
54+
});
55+
56+
const plants = await client.listPlantsInZone();
57+
```
58+
59+
```python {2-3}
60+
client = PlantClient(
61+
garden_id="garden_123",
62+
zone_id="zone_456",
63+
api_key="your-api-key"
64+
)
65+
66+
plants = client.list_plants_in_zone()
67+
```
68+
69+
```java {2-3}
70+
PlantClient client = PlantClient.builder()
71+
.gardenId("garden_123")
72+
.zoneId("zone_456")
73+
.apiKey("your-api-key")
74+
.build();
75+
76+
List<Plant> plants = client.listPlantsInZone();
77+
```
78+
</CodeBlocks>

0 commit comments

Comments
 (0)