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
77 changes: 77 additions & 0 deletions fern/products/openapi-definition/pages/extensions/others.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: Other Extensions
description: Documentation for various custom OpenAPI extensions used in Fern
---

## X-Fern-SDK-Variables

The `x-fern-sdk-variables` extension allows you to define variables that can be injected into paths across your OpenAPI spec. This enables cleaner path definitions and avoids repetition.

### Example Usage

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

When using a generated SDK, the variable will be set in the client constructor rather than passed to individual methods:

```typescript
const client = new Client({
projectId: "proj_123" // Set once in constructor
});

// projectId automatically injected into path
await client.widgets.list();
```

### Configuration Options

<ParamField query="type" type="string" required>
The type of the variable (string, integer, etc)
</ParamField>

<ParamField query="description" type="string">
Description of what the variable represents
</ParamField>

<ParamField query="pattern" type="string">
Optional regex pattern the variable must match
</ParamField>

### Parameter Setup

To use a defined variable in a path parameter:

1. Define the variable in `x-fern-sdk-variables`
2. Add the path parameter normally in your OpenAPI spec
3. Add `x-fern-sdk-variable: variable_name` to the parameter definition

### Generated SDK Behavior

- Variables are passed via the SDK client constructor
- The SDK injects variable values automatically into paths
- Type checking and validation happen at the SDK level
- Error handling for missing/invalid variables is built in

The SDK will validate the variable values match any defined patterns or constraints before making requests.

### Best Practices

- Use consistent variable names across your API spec
- Add clear descriptions for what each variable represents
- Define patterns when variables must match specific formats
- Consider SDK usability when choosing variable names
59 changes: 56 additions & 3 deletions fern/products/sdks/guides/configure-global-headers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ If you'd like to see this feature, please upvote [this issue](https://github.com
</Accordion>
<Accordion title="OpenAPI">

Use the `x-fern-global-headers` extension to label additional headers as global
or to alias the names of global headers:
Use one of the following extensions to specify global configuration:

### x-fern-global-headers
Use this to label additional headers as global or to alias header names:

```yaml title="openapi.yml"
x-fern-global-headers:
Expand All @@ -97,5 +99,56 @@ class Client:

def __init__(self, *, apiKey: str, userpoolId: typing.Optional[str])
```

### x-fern-sdk-variables
Use this to specify variables that should be part of the SDK client constructor and injected into paths:

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

This will generate a client that accepts the variable in the constructor and automatically injects it into paths:

```python
class Client:
def __init__(self, *, project_id: str):
# Variable will be injected into paths like /v1/connect/{project_id}/accounts
```

</Accordion>
</AccordionGroup>
</AccordionGroup>

## Supported Extension Fields

The following extension fields are supported for configuring global headers and variables:

<ParamField query="x-fern-global-headers" type="array">
Array of header configurations with fields:
- `header`: The original header name
- `name`: Optional alias for the header in the SDK
- `optional`: Whether the header is optional
</ParamField>

<ParamField query="x-fern-sdk-variables" type="object">
Object mapping variable names to their configuration:
- `type`: The variable type (string, integer, etc)
- `description`: Description of the variable
- `pattern`: Optional regex pattern for validation
</ParamField>

## Language Support

Global configuration support varies by language:

- TypeScript/JavaScript: Full support for global headers and variables
- Python: Full support as of version 4.24.0+
- Java: Full support for global headers and variables
- Go: Full support for global headers and variables

<Note>
Make sure you're using the latest generator versions to access all global configuration features. You can update your generator versions in `generators.yml`.
</Note>
Loading