Skip to content

Commit b5108e5

Browse files
committed
Update parameter-names.mdx based on issue #266
1 parent eaf4c6c commit b5108e5

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

fern/products/openapi-def/pages/extensions/parameter-names.mdx

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
---
22
title: Customize parameter names
3-
description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming.
3+
description: Use extensions like x-fern-parameter-name and x-fern-sdk-variables to customize parameter naming and inject variables into generated SDKs.
44
---
55

66
<Note>
7-
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.
7+
The `x-fern-parameter-name` and `x-fern-sdk-variables` extensions allow you to customize how parameters are named and injected in your generated SDKs.
88
</Note>
99

10-
## Headers
10+
## Parameter Renaming with x-fern-parameter-name
1111

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 rename parameters in your generated SDK for improved readability and usability.
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:
1417

1518
```yaml {8}
1619
paths:
@@ -26,10 +29,9 @@ paths:
2629
required: true
2730
```
2831
29-
## Query parameters
32+
### Query parameters
3033
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` for clearer intent:
3335

3436
```yaml {8}
3537
paths:
@@ -45,10 +47,9 @@ paths:
4547
required: false
4648
```
4749

48-
## Path parameters
50+
### Path parameters
4951

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+
The path parameter `userId` is simplified to `id` to reduce verbosity:
5253

5354
```yaml {8}
5455
paths:
@@ -63,3 +64,44 @@ paths:
6364
type: string
6465
required: false
6566
```
67+
68+
## SDK Variables with x-fern-sdk-variables
69+
70+
Use `x-fern-sdk-variables` to define variables that will be injected into your SDK paths. This is especially useful for common path parameters that you want to set once during SDK initialization.
71+
72+
```yaml
73+
components:
74+
# Other components...
75+
x-fern-sdk-variables:
76+
project_id:
77+
type: string
78+
description: "The ID of the project"
79+
pattern: "^proj_[a-zA-Z0-9]+$"
80+
```
81+
82+
Then reference this variable in your paths:
83+
84+
```yaml
85+
paths:
86+
"/v1/connect/{project_id}/accounts":
87+
parameters:
88+
- name: project_id
89+
in: path
90+
required: true
91+
description: "The project ID"
92+
schema:
93+
type: string
94+
pattern: "^proj_[a-zA-Z0-9]+$"
95+
x-fern-sdk-variable: project_id
96+
```
97+
98+
When using the generated SDK, instead of passing the project_id parameter for each API call, you can set it once during client initialization:
99+
100+
```python
101+
# Python example
102+
client = YourSDK(project_id="proj_123")
103+
```
104+
105+
<Note>
106+
The x-fern-sdk-variables feature requires Fern generator version 4.24.0 or higher.
107+
</Note>

0 commit comments

Comments
 (0)