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
+51-5Lines changed: 51 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,15 @@
1
1
---
2
2
title: Customize parameter names
3
-
description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming.
3
+
description: Use extensions to customize parameter naming and behavior in 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
+
These extensions allow you to customize parameter handling and naming in your generated SDKs.
8
8
</Note>
9
9
10
-
## Headers
10
+
## Naming parameters with x-fern-parameter-name
11
+
12
+
### Headers
11
13
12
14
In the example below, the header `X-API-Version` is renamed to `version` in the
13
15
generated SDK. The rename makes the SDK more human readable.
@@ -26,7 +28,7 @@ paths:
26
28
required: true
27
29
```
28
30
29
-
## Query parameters
31
+
### Query parameters
30
32
31
33
In the example below, the query parameter `q` is renamed to `search_terms` in the
32
34
generated SDK. The rename makes the parameter more approachable for end users.
@@ -45,7 +47,7 @@ paths:
45
47
required: false
46
48
```
47
49
48
-
## Path parameters
50
+
### Path parameters
49
51
50
52
In the example below, the path parameter `userId` is renamed to `id` in the
51
53
generated SDK. The rename makes the SDK less verbose.
@@ -63,3 +65,47 @@ paths:
63
65
type: string
64
66
required: false
65
67
```
68
+
69
+
## SDK Variable Injection with x-fern-sdk-variables
70
+
71
+
The `x-fern-sdk-variables` extension allows you to define variables that will be injected automatically into API paths. This is useful when you have common path parameters that you want to provide once during SDK initialization rather than passing them to every method call.
72
+
73
+
For example, if many of your endpoints include a `project_id` parameter in the path:
74
+
75
+
```yaml
76
+
components:
77
+
# Define the variable in your OpenAPI spec
78
+
x-fern-sdk-variables:
79
+
project_id:
80
+
type: string
81
+
description: "The ID of the project"
82
+
pattern: "^proj_[a-zA-Z0-9]+$"
83
+
84
+
paths:
85
+
"/v1/connect/{project_id}/accounts":
86
+
parameters:
87
+
- name: project_id
88
+
in: path
89
+
required: true
90
+
schema:
91
+
type: string
92
+
pattern: "^proj_[a-zA-Z0-9]+$"
93
+
x-fern-sdk-variable: project_id # Reference the variable
94
+
```
95
+
96
+
This allows users to provide the `project_id` once when initializing the SDK client:
97
+
98
+
```python
99
+
client = YourAPIClient(project_id="proj_123")
100
+
```
101
+
102
+
Instead of having to provide it for every API call:
103
+
104
+
```python
105
+
# No need to pass project_id to individual methods
106
+
accounts = client.accounts.list()
107
+
```
108
+
109
+
<Note>
110
+
The SDK variable feature is currently supported in Python SDK generation (version 4.24.0+) and TypeScript.
0 commit comments