Default values

View as Markdown

The x-fern-default extension lets you specify a client-side default value for a path, header, or query parameter, including headers defined under x-fern-global-headers. When present, the generated SDK makes the parameter optional and automatically sends the default value if the caller omits it. x-fern-default supports string and boolean values; other types (such as numbers) are ignored.

This is useful for pinning an API version header or a region path parameter while still allowing callers to override the value. x-fern-default is supported across all SDK languages.

Fern uses x-fern-default instead of the standard OpenAPI default property because they have different semantics. The OpenAPI default on a schema describes the value the server assumes when the parameter is omitted — it’s a documentation hint and doesn’t affect client behavior. x-fern-default instructs the generated SDK to actively send the value in every request when the caller doesn’t provide one, ensuring the parameter is always present on the wire.

Path parameters

In the example below, the SDK sends us-east-1 for region when the caller doesn’t specify one.

openapi.yml
1paths:
2 /regions/{region}/resources:
3 get:
4 operationId: list_resources
5 parameters:
6 - name: region
7 in: path
8 required: true
9 x-fern-default: "us-east-1"
10 schema:
11 type: string

Headers

In the example below, the SDK sends 2024-02-08 for X-API-Version when the caller doesn’t specify one.

openapi.yml
1paths:
2 /users:
3 get:
4 operationId: list_users
5 parameters:
6 - name: X-API-Version
7 in: header
8 x-fern-default: "2024-02-08"
9 schema:
10 type: string

Query parameters

In the example below, the SDK sends false for verbose when the caller doesn’t specify one.

openapi.yml
1paths:
2 /search:
3 get:
4 operationId: search
5 parameters:
6 - name: verbose
7 in: query
8 x-fern-default: false
9 schema:
10 type: boolean

Global headers

In the example below, the SDK sends 2024-02-08 for the X-API-Version global header when the caller doesn’t specify one.

openapi.yml
1x-fern-global-headers:
2 - header: X-API-Version
3 name: version
4 x-fern-default: "2024-02-08"