Skip to content

Commit b371596

Browse files
committed
condense page
1 parent 6f439c3 commit b371596

File tree

1 file changed

+28
-119
lines changed

1 file changed

+28
-119
lines changed

fern/products/api-def/openapi-pages/extensions/sdk-variables.mdx

Lines changed: 28 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -3,109 +3,15 @@ title: SDK variables
33
description: Use `x-fern-sdk-variables` to set common path parameters across all requests
44
---
55

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.
77

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:
70-
71-
```typescript
72-
// Without x-fern-sdk-variables
73-
const plants = await client.listPlants("garden_123");
74-
```
75-
76-
### Python
77-
78-
In Python SDKs, variables are required constructor parameters:
79-
80-
```python
81-
from acme import PlantClient
82-
83-
client = PlantClient(
84-
garden_id="garden_123",
85-
api_key="your-api-key"
86-
)
87-
88-
# garden_id is automatically included in the request
89-
plants = client.list_plants()
90-
```
91-
92-
### Java
93-
94-
In Java SDKs, variables are set using builder methods:
95-
96-
```java
97-
PlantClient client = PlantClient.builder()
98-
.gardenId("garden_123")
99-
.apiKey("your-api-key")
100-
.build();
101-
102-
// gardenId is automatically included in the request
103-
List<Plant> plants = client.listPlants();
104-
```
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>
10511

106-
## Multiple variables
12+
## Usage
10713

108-
You can define multiple SDK variables for complex path hierarchies:
14+
Define variables at the document level using `x-fern-sdk-variables`, then mark path parameters as variables using `x-fern-sdk-variable`:
10915

11016
```yaml {1-7,17,23} title="openapi.yml"
11117
x-fern-sdk-variables:
@@ -135,9 +41,12 @@ paths:
13541
type: string
13642
```
13743
138-
This generates an SDK where both variables are set during initialization:
44+
### SDK usage
45+
46+
Variables become required constructor parameters instead of being passed to individual method calls:
13947
140-
```typescript
48+
<CodeBlocks>
49+
```typescript {2-3}
14150
const client = new PlantClient({
14251
gardenId: "garden_123",
14352
zoneId: "zone_456",
@@ -147,23 +56,23 @@ const client = new PlantClient({
14756
const plants = await client.listPlantsInZone();
14857
```
14958

150-
## Use cases
151-
152-
SDK variables are ideal for:
153-
154-
- **Multi-tenant APIs**: Set the tenant or organization ID once during client initialization
155-
- **Environment-specific paths**: Configure environment identifiers (production, staging) at the client level
156-
- **Hierarchical resources**: Set parent resource IDs that are used across many child resource endpoints
157-
- **Regional APIs**: Configure region identifiers that appear in all endpoint paths
158-
159-
## Supported languages
59+
```python {2-3}
60+
client = PlantClient(
61+
garden_id="garden_123",
62+
zone_id="zone_456",
63+
api_key="your-api-key"
64+
)
16065

161-
SDK variables are supported in the following Fern SDK generators:
66+
plants = client.list_plants_in_zone()
67+
```
16268

163-
- TypeScript (v2.6.3+)
164-
- Python (v4.24.0+)
165-
- Java (v3.6.3+)
69+
```java {2-3}
70+
PlantClient client = PlantClient.builder()
71+
.gardenId("garden_123")
72+
.zoneId("zone_456")
73+
.apiKey("your-api-key")
74+
.build();
16675

167-
<Note>
168-
SDK variables only support string types.
169-
</Note>
76+
List<Plant> plants = client.listPlantsInZone();
77+
```
78+
</CodeBlocks>

0 commit comments

Comments
 (0)