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
description: Use `x-fern-sdk-variables` to set common path parameters across all requests
4
4
---
5
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 particularly useful for common path parameters like tenant IDs, organization IDs, or environment identifiers that appear in many endpoint paths.
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
7
8
-
## How it works
9
-
10
-
SDK variables are defined at the document level using `x-fern-sdk-variables` and then referenced in path parameters using `x-fern-sdk-variable`. When a path parameter is marked as a variable, it becomes a required parameter in the SDK client constructor instead of being passed to individual endpoint methods.
11
-
12
-
## Configuration
13
-
14
-
### Define variables
15
-
16
-
At the document level, define your variables with their types:
17
-
18
-
```yaml {6-9} title="openapi.yml"
19
-
openapi: 3.0.0
20
-
info:
21
-
title: Plant API
22
-
version: 1.0.0
23
-
24
-
x-fern-sdk-variables:
25
-
gardenId:
26
-
type: string
27
-
description: The unique identifier for your garden
28
-
```
29
-
30
-
### Reference variables in path parameters
31
-
32
-
Mark path parameters as variables using `x-fern-sdk-variable`:
33
-
34
-
```yaml {9}
35
-
paths:
36
-
/gardens/{gardenId}/plants:
37
-
get:
38
-
operationId: list_plants
39
-
parameters:
40
-
- name: gardenId
41
-
in: path
42
-
required: true
43
-
x-fern-sdk-variable: gardenId
44
-
schema:
45
-
type: string
46
-
responses:
47
-
'200':
48
-
description: List of plants
49
-
```
50
-
51
-
## Generated SDK behavior
52
-
53
-
### TypeScript
54
-
55
-
With SDK variables configured, the TypeScript SDK requires the variable in the client constructor:
56
-
57
-
```typescript
58
-
import { PlantClient } from "@acme/plant-api";
59
-
60
-
const client = new PlantClient({
61
-
gardenId: "garden_123",
62
-
apiKey: "your-api-key"
63
-
});
64
-
65
-
// gardenId is automatically included in the request
66
-
const plants = await client.listPlants();
67
-
```
68
-
69
-
Without SDK variables, the parameter would be required on each method call:
0 commit comments