Skip to content

Commit 78a8e2e

Browse files
Add x-fern-default extension documentation
1 parent 11dfc41 commit 78a8e2e

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

fern/products/api-def/api-def.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ navigation:
4949
path: ./openapi/extensions/availability.mdx
5050
- page: Base path
5151
path: ./openapi/extensions/base-path.mdx
52+
- page: Default values
53+
path: ./openapi/extensions/default.mdx
5254
- page: Enum descriptions, names, and availability
5355
path: ./openapi/extensions/enums.mdx
5456
slug: enum-descriptions-and-names
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Default values
3+
headline: Default values (OpenAPI)
4+
description: Use `x-fern-default` to set client-side default values for path, header, and query parameters in generated SDKs.
5+
---
6+
7+
8+
The `x-fern-default` extension lets you specify a client-side default value for a path, header, or query parameter. When present, the generated SDK makes the parameter optional and automatically sends the default value if the caller omits it.
9+
10+
This is useful for pinning an API version header or a region path parameter while still allowing callers to override the value.
11+
12+
<Note>
13+
`x-fern-default` supports `string` and `boolean` values. Other types (such as numbers) are ignored.
14+
</Note>
15+
16+
## Path parameters
17+
18+
Use `x-fern-default` on a path parameter to provide a default that the SDK sends automatically. This makes a normally required path parameter optional in the generated SDK.
19+
20+
```yaml {8} title="openapi.yml"
21+
paths:
22+
/regions/{region}/resources:
23+
get:
24+
operationId: list_resources
25+
parameters:
26+
- name: region
27+
in: path
28+
required: true
29+
x-fern-default: "us-east-1"
30+
schema:
31+
type: string
32+
```
33+
34+
## Headers
35+
36+
Use `x-fern-default` on a header parameter to pin a default value, such as an API version:
37+
38+
```yaml {8} title="openapi.yml"
39+
paths:
40+
/users:
41+
get:
42+
operationId: list_users
43+
parameters:
44+
- name: X-API-Version
45+
in: header
46+
x-fern-default: "2024-02-08"
47+
schema:
48+
type: string
49+
```
50+
51+
## Query parameters
52+
53+
Use `x-fern-default` on a query parameter to set a default that the SDK sends when the caller omits it:
54+
55+
```yaml {8} title="openapi.yml"
56+
paths:
57+
/search:
58+
get:
59+
operationId: search
60+
parameters:
61+
- name: sort
62+
in: query
63+
x-fern-default: "relevance"
64+
schema:
65+
type: string
66+
```
67+
68+
## Supported languages
69+
70+
`x-fern-default` is supported in the following SDK generators:
71+
72+
- TypeScript
73+
- Python
74+
- Java
75+
- Go
76+
- C#
77+
- Ruby
78+
- PHP

fern/products/api-def/openapi/extensions/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The table below shows all available extensions and links to detailed documentati
2020
| [`x-fern-bearer`](/api-definitions/openapi/authentication#bearer-security-scheme) | Customize bearer authentication parameter names and environment variables |
2121
| [`x-fern-availability`](./availability) | Mark availability status (beta, generally-available, deprecated) |
2222
| [`x-fern-base-path`](./base-path) | Set base path prepended to all endpoints |
23+
| [`x-fern-default`](./default-values) | Set client-side default values for path, header, and query parameters |
2324
| [`x-displayName`](./tag-display-names) | Specify how tag names display in your API Reference |
2425
| [`x-fern-enum`](./enum-descriptions-and-names) | Add descriptions, custom names, and deprecation status to enum values |
2526
| [`x-fern-examples`](./request-response-examples) | Associate request and response examples |

0 commit comments

Comments
 (0)