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/openapi-def/pages/extensions/parameter-names.mdx
+59-12Lines changed: 59 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,19 @@
1
1
---
2
-
title: Customize parameter names
3
-
description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming.
2
+
title: Customize parameter and variable names
3
+
description: Use `x-fern` extensions to customize parameterand variable naming in your generated SDKs.
4
4
---
5
5
6
6
<Note>
7
-
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.
7
+
Fern provides extensions to customize how parameters and variables are named in your generated SDKs, making them more intuitive for end users.
8
8
</Note>
9
9
10
-
## Headers
10
+
## Parameter Names with x-fern-parameter-name
11
11
12
-
In the example below, the header `X-API-Version` is renamed to `version` in the
13
-
generated SDK. The rename makes the SDK more human readable.
12
+
The `x-fern-parameter-name` extension allows you to customize how parameters appear in your SDK.
13
+
14
+
### Headers
15
+
16
+
In the example below, the header `X-API-Version` is renamed to `version` in the generated SDK for better readability:
14
17
15
18
```yaml {8}
16
19
paths:
@@ -26,10 +29,9 @@ paths:
26
29
required: true
27
30
```
28
31
29
-
## Query parameters
32
+
### Query parameters
30
33
31
-
In the example below, the query parameter `q` is renamed to `search_terms` in the
32
-
generated SDK. The rename makes the parameter more approachable for end users.
34
+
Here, the query parameter `q` is renamed to `search_terms` to be more descriptive:
33
35
34
36
```yaml {8}
35
37
paths:
@@ -45,10 +47,9 @@ paths:
45
47
required: false
46
48
```
47
49
48
-
## Path parameters
50
+
### Path parameters
49
51
50
-
In the example below, the path parameter `userId` is renamed to `id` in the
51
-
generated SDK. The rename makes the SDK less verbose.
52
+
This example renames the path parameter `userId` to `id` for conciseness:
52
53
53
54
```yaml {8}
54
55
paths:
@@ -63,3 +64,49 @@ paths:
63
64
type: string
64
65
required: false
65
66
```
67
+
68
+
## SDK Variables with x-fern-sdk-variables
69
+
70
+
The `x-fern-sdk-variables` extension allows you to define variables that can be set once during SDK initialization and automatically injected into requests. This is useful for values that are common across multiple endpoints.
71
+
72
+
```yaml
73
+
components:
74
+
# Other components...
75
+
76
+
x-fern-sdk-variables:
77
+
project_id:
78
+
type: string
79
+
description: "The ID of the project"
80
+
pattern: "^proj_[a-zA-Z0-9]+$"
81
+
```
82
+
83
+
To use the variable in a path:
84
+
85
+
```yaml
86
+
paths:
87
+
"/v1/connect/{project_id}/accounts":
88
+
parameters:
89
+
- name: project_id
90
+
in: path
91
+
required: true
92
+
schema:
93
+
type: string
94
+
pattern: "^proj_[a-zA-Z0-9]+$"
95
+
x-fern-sdk-variable: project_id
96
+
```
97
+
98
+
Once defined, these variables can be set during SDK initialization:
99
+
100
+
```python
101
+
# Python example
102
+
client = Client(project_id="proj_123")
103
+
```
104
+
105
+
```typescript
106
+
// TypeScript example
107
+
const client = new Client({
108
+
projectId: "proj_123"
109
+
});
110
+
```
111
+
112
+
The SDK will automatically inject the variable value into the appropriate requests, eliminating the need to pass it repeatedly as a parameter.
0 commit comments