Skip to content
Merged
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
2 changes: 2 additions & 0 deletions fern/products/api-def/api-def.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ navigation:
path: ./openapi/extensions/explorer.mdx
- page: Global headers
path: ./openapi/extensions/global-headers.mdx
- page: Global parameters
path: ./openapi/extensions/global-parameters.mdx
- page: Ignoring elements
path: ./openapi/extensions/ignore.mdx
- page: SDK method names
Expand Down
106 changes: 106 additions & 0 deletions fern/products/api-def/openapi/extensions/global-parameters.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: Global parameters
headline: Global parameters (OpenAPI)
description: Declare parameters set once at the client level and injected into every relevant request using the `x-fern-global-parameters` extension
---

A **global parameter** is a value set once — at the SDK client level or the CLI config level — and injected into every relevant request, instead of being passed on every call. Per-call values always win over the global value.

Global parameters differ from [global headers](/learn/api-definitions/openapi/extensions/global-headers): a global header is always a header, while a global parameter can target a header, query parameter, path parameter, or a field in the request body.

## Declare global parameters

Use the `x-fern-global-parameters` extension at the root of your spec. Each entry declares one parameter:

```yaml title="openapi.yml"
x-fern-global-parameters:
- name: currency
in: body
target: config.currency
env: ACME_CURRENCY
default: USD
optional: true
apply: auto
docs: The currency code used for pricing.
- name: region
in: path
target: regionId
env: ACME_REGION
default: us
apply: explicit
```

### Fields

<ParamField path="name" type="string" required={true}>
The canonical identifier for the parameter. It's the base for the generated flag or constructor argument, and the key operations use to [opt in](#apply-to-specific-operations).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [vale] reported by reviewdog 🐶
[FernStyles.Hyphens] 'in](#apply-to' doesn't need a hyphen.

</ParamField>

<ParamField path="in" type="string" default="body">
Where the value is injected on the wire: `body`, `query`, `header`, or `path`.
</ParamField>

<ParamField path="target" type="string">
The wire-level injection target. For `body`, a dotted path into the request body (for example, `config.currency`). For `query`, `header`, and `path`, the parameter or header name. Defaults to `name`.
</ParamField>

<ParamField path="type" type="string" default="string">
The value type: `string`, `integer`, `double`, or `boolean`.
</ParamField>

<ParamField path="env" type="string">
An environment variable the value falls back to when the caller doesn't provide one.
</ParamField>

<ParamField path="default" type="any">
A client-side default used when neither the caller nor the environment variable supplies a value. [`x-fern-default`](/learn/api-definitions/openapi/extensions/default-values) takes precedence over `default`.
</ParamField>

<ParamField path="optional" type="boolean" default="false">
Whether the parameter can be omitted. A required parameter with no value, default, or environment variable produces an error.
</ParamField>

<ParamField path="apply" type="string" default="explicit">
How the parameter applies to operations. `explicit` applies only to operations that [opt in](#apply-to-specific-operations); `auto` applies to every operation whose request contains the target.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [vale] reported by reviewdog 🐶
[FernStyles.Hyphens] 'in](#apply-to' doesn't need a hyphen.

</ParamField>

<ParamField path="parameter-name" type="string">
An SDK/CLI-facing alias. When set, this name is used for the generated flag or constructor argument instead of `name`.
</ParamField>

## Apply to specific operations

When a parameter uses `apply: explicit` (the default), it applies only to operations that opt in with the per-operation `x-fern-global-parameter` extension. List the parameter names to include. The value accepts a single string or a list:

```yaml title="openapi.yml" {4-6,12}
paths:
/v1/products/{regionId}/search:
post:
x-fern-global-parameter:
- region
- currency
operationId: searchProducts
# ...
/v1/products/{regionId}/{productId}:
get:
x-fern-global-parameter: region
operationId: getProduct
# ...
```

Each name must match a parameter declared in `x-fern-global-parameters`. A parameter with `apply: auto` is injected into every operation whose request contains its target, with no opt-in required.

## Resolution order

At runtime, the value is resolved from the first available source, in order:

1. The per-call value (a per-operation parameter or an explicit request field) — this always wins.
2. The CLI flag or constructor argument.
3. The environment variable (`env`).
4. The client-side default (`x-fern-default`, then `default`).

For a `body` parameter with a nested `target`, a value the caller already supplies at that path is never overwritten.

## Generated CLI behavior

The [CLI generator](/learn/cli-generator/get-started/openapi-extensions#global-parameters) registers each global parameter as a top-level flag (with its `env` fallback and `default`) and injects the resolved value at the declared location for every applicable command.
1 change: 1 addition & 0 deletions fern/products/api-def/openapi/extensions/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The table below shows all available extensions and links to detailed documentati
| [`x-fern-examples`](./request-response-examples) | Associate request and response examples |
| [`x-fern-explorer`](./api-explorer-control) | Control API Explorer (playground) availability globally or per endpoint |
| [`x-fern-global-headers`](./global-headers) | Configure headers used across all endpoints |
| [`x-fern-global-parameters`](./global-parameters) | Configure parameters set once and injected into every relevant request |
| [`x-fern-header`](/api-definitions/openapi/authentication#apikey-security-scheme) | Customize API key header authentication parameter names and environment variables |
| [`x-fern-idempotent`](./idempotency) | Mark an endpoint as idempotent |
| [`x-fern-idempotency-headers`](./idempotency) | Configure idempotency headers for safe request retries |
Expand Down
34 changes: 34 additions & 0 deletions fern/products/cli-generator/openapi-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@ Produces `--api-version` instead of `--x-api-version`.

See [Customize parameter names](/learn/api-definitions/openapi/extensions/parameter-names) for more details.

## Global parameters

### `x-fern-global-parameters`

Registers a value that's configured once and injected into every applicable command, rather than passed on each invocation. Each declared parameter becomes a top-level `--<flag-name>` flag with its environment-variable fallback and client-side default, injected at the declared location (`body`, `query`, `header`, or `path`).

```yaml title="openapi.yml"
x-fern-global-parameters:
- name: currency
in: body
target: config.currency
env: ACME_CURRENCY
default: USD
apply: auto
```

The value resolves from the first available source: the CLI flag, then the environment variable, then the default. A per-operation parameter with the same target overrides the global.

```bash
# CLI flag takes priority
acme products search --currency EUR

# Otherwise falls back to the environment variable
export ACME_CURRENCY=EUR
acme products search

# Otherwise sends the default (USD)
acme products search
```

An `apply: auto` parameter applies to every command whose request contains the target; an `apply: explicit` parameter applies only to operations that opt in with `x-fern-global-parameter`.

See [Global parameters](/learn/api-definitions/openapi/extensions/global-parameters) for the full field reference and resolution order.

## Pagination

### `x-fern-pagination`
Expand Down
Loading