Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions fern/products/openapi-def/openapi-def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ navigation:
- page: Authentication
path: ./pages/auth.mdx
- page: Servers
path: ./pages/servers.mdx
path: ./pages/servers.mdx
- section: Endpoints
slug: endpoints
contents:
Expand All @@ -17,6 +17,9 @@ navigation:
- page: Server-Sent Events
path: ./pages/endpoints/sse.mdx
slug: sse
- page: others
title: Other
path: ./pages/extensions/others.mdx
- section: Extensions
slug: extensions
contents:
Expand All @@ -38,7 +41,7 @@ navigation:
- page: Overlay Customizations
path: ./pages/overrides.mdx
- page: Sync your OpenAPI Specification
path: ./pages/automation.mdx
path: ./pages/automation.mdx
- section: Integrate your Server Framework
slug: frameworks
contents:
Expand Down
89 changes: 74 additions & 15 deletions fern/products/openapi-def/pages/extensions/parameter-names.mdx
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
---
title: Customize parameter names
description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming.
description: Use extension headers to customize parameter names and behavior in your generated SDKs.
---

<Note>
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.
Extension headers allow you to customize how parameters are handled in your generated SDKs, including parameter naming and injection behavior.
</Note>

## Headers
## Parameter Naming Extensions

In the example below, the header `X-API-Version` is renamed to `version` in the
generated SDK. The rename makes the SDK more human readable.
### x-fern-parameter-name

```yaml {8}
Customize the variable names of parameters in your generated SDKs.

#### Headers

Rename HTTP headers to be more readable in the SDK:

```yaml
paths:
"/user":
get:
operationId: list_user
parameters:
- in: header
name: X-API-Version
name: X-API-Version
x-fern-parameter-name: version
schema:
type: string
required: true
```

## Query parameters
#### Query Parameters

In the example below, the query parameter `q` is renamed to `search_terms` in the
generated SDK. The rename makes the parameter more approachable for end users.
Make query parameter names more descriptive:

```yaml {8}
```yaml
paths:
"/user/search":
get:
Expand All @@ -45,12 +49,11 @@ paths:
required: false
```

## Path parameters
#### Path Parameters

In the example below, the path parameter `userId` is renamed to `id` in the
generated SDK. The rename makes the SDK less verbose.
Simplify path parameter names:

```yaml {8}
```yaml
paths:
"/user/{userId}":
get:
Expand All @@ -63,3 +66,59 @@ paths:
type: string
required: false
```

### x-fern-sdk-variables

Define variables that can be injected into paths across multiple endpoints:

```yaml
components:
x-fern-sdk-variables:
project_id:
type: string
description: "The project ID to use for all requests"
pattern: "^proj_[a-zA-Z0-9]+$"

paths:
"/v1/connect/{project_id}/accounts":
parameters:
- name: project_id
in: path
required: true
schema:
type: string
x-fern-sdk-variable: project_id
```

This allows the SDK client to accept the variable in its constructor and automatically inject it into all relevant paths, rather than requiring it as a parameter for each individual method call.

<Note>
The variable value provided in the SDK client constructor will be automatically inserted into any path that references that variable name.
</Note>

### x-fern-sdk-return-value

Specify which part of the response should be returned by the SDK method:

```yaml
paths:
"/user/{id}":
get:
operationId: get_user
x-fern-sdk-return-value: data
responses:
200:
content:
application/json:
schema:
type: object
properties:
data:
$ref: "#/components/schemas/User"
```

This extracts just the `data` field from the response before returning it to the SDK user.

<Note>
This is useful when your API wraps response data in a container object but you want the SDK to return just the core data.
</Note>
103 changes: 103 additions & 0 deletions fern/products/openapi-definition/pages/extensions/others.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: Other Extensions
description: Other extensions supported by Fern
---

# Other Extensions

Fern supports several additional OpenAPI extensions that provide enhanced functionality:

## x-fern-sdk-variables

The `x-fern-sdk-variables` extension allows you to define variables that will be injected into the SDK client at runtime. This is useful for values that are reused across multiple endpoints.

```yaml
x-fern-sdk-variables:
project_id:
type: string
description: The project identifier
pattern: ^proj_[a-zA-Z0-9]+$
```

The variable can then be referenced in path parameters:

```yaml
/v1/projects/{project_id}/resources:
parameters:
- name: project_id
in: path
required: true
x-fern-sdk-variable: project_id
```

This allows the SDK client to inject the variable value automatically rather than requiring it as a parameter for each API call.

## x-fern-pagination

The `x-fern-pagination` extension configures pagination behavior for list endpoints:

```yaml
x-fern-pagination:
cursor: $request.after
next_cursor: $response.page_info.end_cursor
results: $response.data
```

This tells Fern how to handle paginated responses by specifying:
- The cursor parameter in the request
- Where to find the next cursor in the response
- Where to find the results array in the response

## x-fern-sdk-return-value

The `x-fern-sdk-return-value` extension specifies which part of the response should be returned by the SDK:

```yaml
x-fern-sdk-return-value: data
```

This is useful when the API wraps responses in a common envelope but you want the SDK to return just the relevant data.

## x-fern-ignore

Add `x-fern-ignore: true` to exclude an endpoint or schema from SDK generation:

```yaml
/internal/endpoint:
x-fern-ignore: true
```

## x-fern-sdk-method-name

Override the default SDK method name:

```yaml
/users:
get:
x-fern-sdk-method-name: listUsers
```

## x-fern-sdk-group-name

Group related endpoints together in the SDK:

```yaml
/users:
get:
x-fern-sdk-group-name: users
```

This organizes the SDK methods into logical groups for better discoverability.

## x-fern-headers

Define headers that should be included with requests:

```yaml
x-fern-headers:
X-Custom-Header:
type: string
required: true
```

These headers will be automatically included in SDK requests.
Loading
Loading