-
Notifications
You must be signed in to change notification settings - Fork 7
docs: document x-fern-global-parameters extension and CLI generator support #6076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+143
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
fern/products/api-def/openapi/extensions/global-parameters.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). | ||
| </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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 [vale] reported by reviewdog 🐶 |
||
| </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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.