Skip to content

Commit 7df5d66

Browse files
committed
Update parameter-names.mdx based on issue #266
1 parent f04d1b2 commit 7df5d66

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

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

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
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 to customize parameter naming and behavior in 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+
These extensions allow you to customize parameter handling and naming in your generated SDKs.
88
</Note>
99

10-
## Headers
10+
## Naming parameters with x-fern-parameter-name
11+
12+
### Headers
1113

1214
In the example below, the header `X-API-Version` is renamed to `version` in the
1315
generated SDK. The rename makes the SDK more human readable.
@@ -26,7 +28,7 @@ paths:
2628
required: true
2729
```
2830
29-
## Query parameters
31+
### Query parameters
3032
3133
In the example below, the query parameter `q` is renamed to `search_terms` in the
3234
generated SDK. The rename makes the parameter more approachable for end users.
@@ -45,7 +47,7 @@ paths:
4547
required: false
4648
```
4749

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

5052
In the example below, the path parameter `userId` is renamed to `id` in the
5153
generated SDK. The rename makes the SDK less verbose.
@@ -63,3 +65,47 @@ paths:
6365
type: string
6466
required: false
6567
```
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.
111+
</Note>

0 commit comments

Comments
 (0)