Skip to navigation

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
paths:
/regions/{region}/resources:
get:
operationId: list_resources
parameters:
- name: region
in: path
required: true
x-fern-default: "us-east-1"
schema:
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
paths:
/users:
get:
operationId: list_users
parameters:
- name: X-API-Version
in: header
x-fern-default: "2024-02-08"
schema:
type: string

Query parameters

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

openapi.yml
paths:
/search:
get:
operationId: search
parameters:
- name: verbose
in: query
x-fern-default: false
schema:
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
x-fern-global-headers:
- header: X-API-Version
name: version
x-fern-default: "2024-02-08"