Skip to content

Commit 1be1921

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

File tree

1 file changed

+73
-19
lines changed

1 file changed

+73
-19
lines changed
Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,55 @@
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 in your 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+
Extensions allow you to customize how parameters are named and handled in your generated SDKs to improve readability and usability.
88
</Note>
99

10-
## Headers
10+
## Header Extensions
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+
### x-fern-parameter-name
13+
Renames a header parameter in the generated SDK for better readability.
1414

15-
```yaml {8}
15+
```yaml
1616
paths:
1717
"/user":
1818
get:
19-
operationId: list_user
2019
parameters:
2120
- in: header
22-
name: X-API-Version
21+
name: X-API-Version
2322
x-fern-parameter-name: version
2423
schema:
2524
type: string
2625
required: true
2726
```
2827
29-
## Query parameters
30-
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.
28+
### x-fern-sdk-header
29+
Marks a header to be provided in the SDK client constructor rather than per-request.
3330
3431
```yaml {8}
32+
paths:
33+
"/user":
34+
get:
35+
parameters:
36+
- in: header
37+
name: X-API-Key
38+
schema:
39+
x-fern-sdk-header: api_key
40+
type: string
41+
required: true
42+
```
43+
44+
## Query Parameter Extensions
45+
46+
### x-fern-parameter-name
47+
Renames a query parameter in the generated SDK to be more descriptive.
48+
49+
```yaml
3550
paths:
3651
"/user/search":
3752
get:
38-
operationId: search_user
3953
parameters:
4054
- in: query
4155
name: q
@@ -45,21 +59,61 @@ paths:
4559
required: false
4660
```
4761
48-
## Path parameters
49-
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.
62+
### x-fern-sdk-variable
63+
Marks a query parameter to be provided in the SDK client constructor.
5264
5365
```yaml {8}
66+
paths:
67+
"/user/search":
68+
get:
69+
parameters:
70+
- in: query
71+
name: org_id
72+
schema:
73+
x-fern-sdk-variable: organization_id
74+
type: string
75+
required: true
76+
```
77+
78+
## Path Parameter Extensions
79+
80+
### x-fern-parameter-name
81+
Renames a path parameter in the generated SDK for conciseness.
82+
83+
```yaml
5484
paths:
5585
"/user/{userId}":
5686
get:
57-
operationId: get_user
5887
parameters:
5988
- in: path
6089
name: userId
6190
x-fern-parameter-name: id
6291
schema:
6392
type: string
64-
required: false
93+
required: true
6594
```
95+
96+
### x-fern-sdk-variable
97+
Marks a path parameter to be provided in the SDK client constructor. This is useful for values that are common across many endpoints.
98+
99+
```yaml
100+
paths:
101+
"/projects/{project_id}/users":
102+
get:
103+
parameters:
104+
- in: path
105+
name: project_id
106+
schema:
107+
x-fern-sdk-variable: project_id
108+
type: string
109+
pattern: "^proj_[a-zA-Z0-9]+$"
110+
required: true
111+
```
112+
113+
<Note>
114+
When using `x-fern-sdk-variable` or `x-fern-sdk-header`, the specified value will be provided once in the client constructor rather than needing to be passed to each individual API call.
115+
</Note>
116+
117+
<Tip>
118+
Use these extensions strategically to create a more ergonomic SDK. Consider renaming cryptic parameter names to be more descriptive, and moving commonly used values like API keys or project IDs to the client constructor.
119+
</Tip>

0 commit comments

Comments
 (0)