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: ./others
- 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
61 changes: 50 additions & 11 deletions fern/products/openapi-def/pages/extensions/parameter-names.mdx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
---
title: Customize parameter names
description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming.
description: Use Fern's parameter extensions to customize naming and behavior of parameters in your OpenAPI definition.
---

<Note>
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.
Fern provides several extensions that let you customize how parameters are handled in your OpenAPI definition and generated SDKs.
</Note>

## Headers
## x-fern-parameter-name

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.
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.

### Headers

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.

```yaml {8}
paths:
Expand All @@ -26,10 +29,9 @@ paths:
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.
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.

```yaml {8}
paths:
Expand All @@ -45,10 +47,9 @@ 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.
In the example below, the path parameter `userId` is renamed to `id` in the generated SDK. The rename makes the SDK less verbose.

```yaml {8}
paths:
Expand All @@ -63,3 +64,41 @@ paths:
type: string
required: false
```

## x-fern-sdk-variables

The `x-fern-sdk-variables` extension allows you to define variables that will be injected into paths when making requests. These variables can be provided once during client initialization rather than passing them with every request.

For example, to automatically inject a project ID into all paths:

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

paths:
"/v1/connect/{project_id}/accounts":
parameters:
- name: project_id
in: path
required: true
schema:
type: string
pattern: "^proj_[a-zA-Z0-9]+$"
x-fern-sdk-variable: project_id
```

When using the generated SDK, the `project_id` can be provided once during client initialization:

```python
client = Client(project_id="proj_123")
```

And it will automatically be injected into all paths that reference it.

<Note>
The `x-fern-sdk-variables` extension is currently supported in Python (version 4.24.0+) and TypeScript SDKs.
</Note>
139 changes: 139 additions & 0 deletions fern/products/openapi-definition/others
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
---
title: "Other OpenAPI Extensions"
description: "Overview of additional OpenAPI extensions supported by Fern"
---

Fern supports several OpenAPI extensions that enable additional functionality beyond the standard OpenAPI specification.

## x-fern-sdk-variables

The `x-fern-sdk-variables` extension allows you to define variables that will be passed to the SDK client constructor and injected into API paths automatically.

```yaml
openapi: 3.0.0
x-fern-sdk-variables:
project_id:
type: string
description: The project ID to use for API requests
pattern: "^proj_[a-zA-Z0-9]+$"
paths:
/v1/projects/{project_id}/resources:
parameters:
- name: project_id
in: path
required: true
schema:
type: string
x-fern-sdk-variable: project_id
```

This allows SDK users to provide the variable once in the client constructor rather than passing it to every method:

```python
client = Client(project_id="proj_123")
# project_id is automatically injected into paths
client.resources.list()
```

## x-fern-include-empty-arrays

The `x-fern-include-empty-arrays` extension can be added to array properties to ensure they are included in the response even when empty:

```yaml
components:
schemas:
User:
type: object
properties:
groups:
type: array
items:
type: string
x-fern-include-empty-arrays: true
```

## x-fern-sdk-group-name

The `x-fern-sdk-group-name` extension allows you to organize API operations into logical groups in generated SDKs:

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

## x-fern-sdk-method-name

The `x-fern-sdk-method-name` extension lets you customize the method name for an operation in generated SDKs:

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

## x-fern-sdk-return-value

The `x-fern-sdk-return-value` extension allows you to specify which part of the response should be returned from SDK methods:

```yaml
paths:
/users:
get:
x-fern-sdk-return-value: data
responses:
200:
content:
application/json:
schema:
type: object
properties:
data:
type: array
items:
$ref: '#/components/schemas/User'
```

## x-fern-ignore

The `x-fern-ignore` extension allows you to exclude specific schemas, operations or properties from generated SDKs:

```yaml
paths:
/internal:
get:
x-fern-ignore: true
operationId: internalOperation
```

## x-fern-paginate

The `x-fern-paginate` extension enables pagination support in generated SDKs:

```yaml
paths:
/users:
get:
x-fern-paginate:
cursor: "$request.after"
next_cursor: "$response.page_info.end_cursor"
results: "$response.data"
```

## x-fern-docs-disable-excerpt

The `x-fern-docs-disable-excerpt` extension disables excerpt generation for a schema in API documentation:

```yaml
components:
schemas:
User:
x-fern-docs-disable-excerpt: true
type: object
```

For more information on working with OpenAPI extensions in Fern, see our [OpenAPI guide](/learn/openapi-definition/overview).
Loading
Loading