Skip to content

Commit 376e712

Browse files
committed
Update parameter-names.mdx based on issue #266
1 parent 407b095 commit 376e712

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

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

Lines changed: 49 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 to customize parameter naming and behavior 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 handled in your generated SDKs. This includes renaming parameters and injecting values via constructors.
88
</Note>
99

10-
## Headers
10+
## Parameter naming 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 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:
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+
Make query parameter names more descriptive and user-friendly:
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+
Simplify verbose path parameter names:
5253
5354
```yaml {8}
5455
paths:
@@ -63,3 +64,40 @@ paths:
6364
type: string
6465
required: false
6566
```
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+).
103+
</Note>

0 commit comments

Comments
 (0)