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
93 changes: 82 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,48 @@
---
title: Customize parameter names
description: Use `x-fern-parameter-name` to customize query parameter, header and path parameter naming.
description: Learn how to customize parameter naming in generated SDKs using OpenAPI extensions.
---

<Note>
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.
Fern provides several extensions to customize how API parameters are handled in your generated SDKs.
</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

Use `x-fern-parameter-name` to customize how individual parameters are named in your SDK, making them more readable and intuitive.

```yaml
paths:
"/users":
get:
parameters:
- in: header
name: X-API-Version
x-fern-parameter-name: version
schema:
type: string
```

### x-fern-sdk-variables

Use `x-fern-sdk-variables` to define parameters that should be passed through the SDK client constructor rather than individual method calls.

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

## Usage Examples

### Headers

Rename HTTP headers to be more readable in your SDK:

```yaml {8}
paths:
Expand All @@ -26,10 +58,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.
Make query parameter names more descriptive:

```yaml {8}
paths:
Expand All @@ -45,10 +76,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.
Simplify path parameter names:

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

### Constructor Variables

Define parameters that should be set once in the client constructor:

```yaml
components:
x-fern-sdk-variables:
project_id:
type: string
description: "Project identifier used across all API calls"
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
```

This allows you to initialize the client with the project ID once:

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

Rather than passing it to every method:

```python
# Not needed when using x-fern-sdk-variables
client.get_accounts(project_id="proj_123")
```

<Note>
The `x-fern-sdk-variables` extension is supported in Python SDKs version 4.24.0 and later.
</Note>
52 changes: 34 additions & 18 deletions fern/products/sdks/overview/python/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ groups:
## SDK Configuration Options

<ParamField path="additional_init_exports" type="array" default="null" required={false} toc={true}>
Additional exports to include in the package's __init__.py file.
</ParamField>

<ParamField path="default_bytes_stream_chunk_size" type="number" default="null" required={false} toc={true}>
The chunk size to use (if any) when processing a response bytes stream within `iter_bytes` or `aiter_bytes` results in: `for chunk in response.iter_bytes(chunk_size=<default_bytes_stream_chunk_size>):`
</ParamField>

<ParamField path="exclude_types_from_init_exports" type="bool" default="false" required={false} toc={true}>
When enabled, type definitions will not be exported in the package's __init__.py file.
</ParamField>

<ParamField path="extra_dependencies" type="object" default="{}" required={false} toc={true}>
Expand All @@ -40,58 +42,69 @@ groups:
</ParamField>

<ParamField path="extra_dev_dependencies" type="object" default="{}" required={false} toc={true}>
Additional development dependencies to include in the generated package.
</ParamField>

<ParamField path="extras" type="object" default="{}" required={false} toc={true}>
Define optional feature sets and their dependencies.
</ParamField>

<ParamField path="flat_layout" type="bool" default="false" required={false} toc={true}>
When enabled, generates a flatter directory structure without nested resource folders.
</ParamField>

<ParamField path="follow_redirects_by_default" type="bool" default="true" required={false} toc={true}>
Whether to follow redirects by default in HTTP requests.
</ParamField>

<ParamField path="improved_imports" type="bool" default="true" required={false} toc={true}>
Feature flag that improves imports in the Python SDK by removing nested `resources` directory
Feature flag that improves imports in the Python SDK by removing nested `resources` directory.
</ParamField>

<ParamField path="include_legacy_wire_tests" type="bool" default="false" required={false} toc={true}>
Whether or not to include legacy wire tests in the generated SDK
Whether or not to include legacy wire tests in the generated SDK.
</ParamField>

<ParamField path="include_union_utils" type="bool" default="false" required={false} toc={true}>
When enabled, generates utility methods for working with union types.
</ParamField>

<ParamField path="inline_path_params" type="bool" default="false" required={false} toc={true}>
If true, treats path parameters as named parameters in endpoint functions.
If true, treats path parameters as named parameters in endpoint functions. This allows using common variables like project_id across multiple endpoints:

```yaml
config:
inline_path_params: true
x-fern-sdk-variables:
project_id:
type: string
description: The project ID to use for all requests
```
</ParamField>

<ParamField path="inline_request_params" type="bool" default="true" required={false} toc={true}>
Feature flag that removes the usage of request objects, and instead uses parameters in function signatures where possible.
</ParamField>

<ParamField path="package_name" type="string" default="null" required={false} toc={true}>

Specifies the Python package name that users will import your generated client
from.
Specifies the Python package name that users will import your generated client from.

For example, setting `package_name: "my_custom_package"` enables users to use
`my_custom_package import Client` to import your client:

```yaml {7-10}
default-group: local
groups:
local:
generators:
- name: fernapi/fern-python
For example, setting `package_name: "my_custom_package"` enables users to use `my_custom_package import Client` to import your client:

```yaml {7-10}
default-group: local
groups:
local:
generators:
- name: fernapi/fern-python
version: 0.7.1
config:
package_name: "my_custom_package"
```
```
</ParamField>

<ParamField path="pydantic_config" type="SdkPydanticModelCustomConfig" default="SdkPydanticModelCustomConfig()" required={false} toc={true}>
Customize how Pydantic models are generated.
</ParamField>

<ParamField path="pydantic_config.include_union_utils" type="bool" default="false" required={false} toc={true}>
Expand All @@ -112,8 +125,8 @@ groups:
# Visit every case in the union
shape = get_shape()
shape.visit(
circle: lambda circle: do_something_with_circle(circle),
triangle: lambda triangle: do_something_with_triangle(triangle),
circle=lambda circle: do_something_with_circle(circle),
triangle=lambda triangle: do_something_with_triangle(triangle),
)
```

Expand All @@ -140,20 +153,23 @@ groups:
</ParamField>

<ParamField path="pyproject_toml" type="string" default="null" required={false} toc={true}>
Custom pyproject.toml content to include in the generated package.
</ParamField>

<ParamField path="should_generate_websocket_clients" type="bool" default="false" required={false} toc={true}>
Feature flag that enables generation of Python websocket clients.
</ParamField>

<ParamField path="skip_formatting" type="bool" default="false" required={false} toc={true}>
When true, skips code formatting of generated files.
</ParamField>

<ParamField path="timeout_in_seconds" type="number | 'infinity'" default="60" required={false} toc={true}>
By default, the generator generates a client that times out after 60 seconds. You can customize this value by providing a different number or setting to `infinity` to get rid of timeouts.
</ParamField>

<ParamField path="use_api_name_in_package" type="bool" default="false" required={false} toc={true}>
When enabled, includes the API name in the generated package name.
</ParamField>

<ParamField path="use_inheritance_for_extended_models" type="bool" default="true" required={false} toc={true}>
Expand Down
Loading
Loading