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
+49-11Lines changed: 49 additions & 11 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
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 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
+
Extensions allow you to customize how parameters are handled in your generated SDKs. This includes renaming parameters and injecting values via constructors.
8
8
</Note>
9
9
10
-
## Headers
10
+
## Parameter naming 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
+
Use `x-fern-parameter-name` to customize variable names for parameters in your generated SDKs.
13
+
14
+
### Headers
15
+
16
+
Rename header parameters to make them more idiomatic in your SDK:
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
+
Make query parameter names more descriptive and user-friendly:
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
+
Simplify verbose path parameter names:
52
53
53
54
```yaml {8}
54
55
paths:
@@ -63,3 +64,40 @@ paths:
63
64
type: string
64
65
required: false
65
66
```
67
+
68
+
## Constructor Variables with x-fern-sdk-variables
69
+
70
+
Use `x-fern-sdk-variables` to define variables that can be set once in the client constructor and automatically injected into requests.
71
+
72
+
```yaml
73
+
components:
74
+
x-fern-sdk-variables:
75
+
project_id:
76
+
type: string
77
+
description: "The ID of the project"
78
+
pattern: "^proj_[a-zA-Z0-9]+$"
79
+
```
80
+
81
+
This variable can then be referenced in path parameters:
82
+
83
+
```yaml
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
94
+
```
95
+
96
+
The generated SDK will now:
97
+
1. Accept the `project_id` in the client constructor
98
+
2. Automatically inject it into requests that require it
99
+
3. Free users from having to pass it on every request
100
+
101
+
<Note>
102
+
SDK variables are currently supported in TypeScript and Python SDKs (version 4.24.0+).
0 commit comments