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
71 changes: 59 additions & 12 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.
title: Customize parameter and variable names
description: Use `x-fern` extensions to customize parameter and variable naming in your generated SDKs.
---

<Note>
The `x-fern-parameter-name` extension allows you to customize the variable names of parameters in your generated SDKs.
Fern provides extensions to customize how parameters and variables are named in your generated SDKs, making them more intuitive for end users.
</Note>

## Headers
## Parameter Names with 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 how parameters appear in your SDK.

### Headers

In the example below, the header `X-API-Version` is renamed to `version` in the generated SDK for better readability:

```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.
Here, the query parameter `q` is renamed to `search_terms` to be more descriptive:

```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.
This example renames the path parameter `userId` to `id` for conciseness:

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

## SDK Variables with x-fern-sdk-variables

The `x-fern-sdk-variables` extension allows you to define variables that can be set once during SDK initialization and automatically injected into requests. This is useful for values that are common across multiple endpoints.

```yaml
components:
# Other components...

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

To use the variable in a path:

```yaml
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
```

Once defined, these variables can be set during SDK initialization:

```python
# Python example
client = Client(project_id="proj_123")
```

```typescript
// TypeScript example
const client = new Client({
projectId: "proj_123"
});
```

The SDK will automatically inject the variable value into the appropriate requests, eliminating the need to pass it repeatedly as a parameter.
59 changes: 59 additions & 0 deletions fern/products/openapi-definition/pages/extensions/others.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# OpenAPI Extensions and Variables

The Fern OpenAPI parser supports several custom extensions to enhance SDK generation capabilities. These extensions can be specified in your OpenAPI definition using `x-` prefixed fields.

## Core Extensions

### SDK Variables
The `x-fern-sdk-variables` extension allows you to define variables that can be passed through the SDK constructor and injected into paths and parameters.

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

Variables defined here can be referenced in path parameters using `x-fern-sdk-variable`:

```yaml
paths:
/v1/projects/{project_id}/users:
parameters:
- name: project_id
in: path
required: true
schema:
type: string
x-fern-sdk-variable: project_id
```

### SDK Configuration
- `x-fern-sdk-group-name` - Groups related endpoints under a common namespace
- `x-fern-sdk-method-name` - Customizes the generated method name
- `x-fern-ignore` - Excludes an endpoint from SDK generation
- `x-fern-sdk-return-value` - Specifies the response field to return

### Pagination Support
The `x-fern-pagination` extension configures cursor-based pagination:

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

### Response Handling
- `x-fern-error-response` - Defines custom error handling
- `x-fern-sdk-async` - Marks an endpoint as async/non-blocking

## Usage Notes

- Extensions must be placed at the appropriate level (operation, parameter, etc.)
- Variable patterns use standard regex syntax
- Path references use dot notation (e.g. `$response.data`)
- Generator support may vary by language

For language-specific implementation details, refer to the [SDK Generators](../generators/overview) documentation.
57 changes: 34 additions & 23 deletions fern/products/sdks/overview/python/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ groups:
local:
generators:
- name: fernapi/fern-python
version: 0.7.1
version: 4.24.0
config:
client:
class_name: "YourClient"
```

## SDK Configuration Options

<ParamField path="additional_init_exports" type="array" default="null" required={false} toc={true}>
</ParamField>

<ParamField path="client" type="ClientConfiguration" default="ClientConfiguration()" required={false} toc={true}>
Client configuration options including SDK variable support through `x-fern-sdk-variables` in OpenAPI specs.
</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}>
Whether to exclude types from __init__ exports
</ParamField>

<ParamField path="extra_dependencies" type="object" default="{}" required={false} toc={true}>
Expand All @@ -41,13 +40,8 @@ groups:
```
</ParamField>

<ParamField path="extra_dev_dependencies" type="object" default="{}" required={false} toc={true}>
</ParamField>

<ParamField path="extras" type="object" default="{}" required={false} toc={true}>
</ParamField>

<ParamField path="flat_layout" type="bool" default="false" required={false} toc={true}>
Whether to use a flat directory layout for generated code
</ParamField>

<ParamField path="follow_redirects_by_default" type="bool" default="true" required={false} toc={true}>
Expand All @@ -62,9 +56,6 @@ groups:
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}>
</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.
</ParamField>
Expand All @@ -74,9 +65,11 @@ groups:
</ParamField>

<ParamField path="package_name" type="string" default="null" required={false} toc={true}>
Custom package name for the generated SDK
</ParamField>

<ParamField path="pydantic_config" type="SdkPydanticModelCustomConfig" default="SdkPydanticModelCustomConfig()" required={false} toc={true}>
Configuration options for Pydantic model generation
</ParamField>

<ParamField path="pydantic_config.include_union_utils" type="bool" default="false" required={false} toc={true}>
Expand All @@ -101,8 +94,6 @@ groups:
triangle: lambda triangle: do_something_with_triangle(triangle),
)
```

When enabled, the python generator will not run Black formatting in the generated code. Black is slow so this can potentially speed up code generation quite a bit.
</ParamField>

<ParamField path="pydantic_config.version" type="'v1' | 'v2' | 'both' | 'v1_on_v2'" default="both" required={false} toc={true}>
Expand All @@ -124,21 +115,16 @@ groups:
<Warning>This changes your declared python dependency, which is not meant to be done often if at all. This is a last resort if any dependencies force you to change your version requirements.</Warning>
</ParamField>

<ParamField path="pyproject_toml" type="string" default="null" required={false} toc={true}>
</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}>
</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}>
Whether to include 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 All @@ -149,6 +135,31 @@ groups:
Whether or not to generate `TypedDicts` instead of Pydantic Models for request objects.
</ParamField>

<ParamField path="use_typeddict_requests_for_file_upload" type="bool" default="false" required={false} toc={true}>
Whether or not to generate TypedDicts instead of Pydantic Models for file upload request objects. Note that this flag was only introduced due to an oversight in the `use_typeddict_requests` flag implementation; it should be removed in the future.
<ParamField path="x-fern-sdk-variables" type="object" default="{}" required={false} toc={true}>
An extension field in OpenAPI specs that allows you to define variables for your SDK client. These variables will be available in the generated client constructor. Variables must be defined in the components section of your OpenAPI spec:

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

Once defined, you can reference these variables in your path parameters with the `x-fern-sdk-variable` extension:

```yaml
/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
```

The generated SDK will handle injecting these variables into API calls automatically when they are provided to the client constructor.
</ParamField>
Loading
Loading