Skip to content

Commit 5e42f0e

Browse files
authored
Expand docs on global headers, add readme deep dive (#325)
1 parent fa2ea7f commit 5e42f0e

File tree

4 files changed

+125
-63
lines changed

4 files changed

+125
-63
lines changed

fern/products/sdks/guides/configure-global-headers.mdx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ If you'd like to see this feature, please upvote [this issue](https://github.com
7777
</Accordion>
7878
<Accordion title="OpenAPI">
7979

80-
Use the `x-fern-global-headers` extension to label additional headers as global
81-
or to alias the names of global headers:
80+
For OpenAPI specifications, you can configure global headers in two ways:
81+
82+
#### Method 1: OpenAPI Spec Extension
83+
84+
Add global headers directly to your OpenAPI spec using the `x-fern-global-headers` extension to label additional headers as global or to alias the names of global headers:
8285

8386
```yaml title="openapi.yml"
8487
x-fern-global-headers:
@@ -88,14 +91,37 @@ x-fern-global-headers:
8891
optional: true
8992
```
9093

91-
This configuration yields the following client:
94+
#### Method 2: `generators.yml` Configuration
95+
96+
Alternatively, you can add headers to the `api` block in your `generators.yml` file:
97+
98+
```yaml title="generators.yml"
99+
api:
100+
- openapi: ./path/to/openapi
101+
headers:
102+
custom_api_key:
103+
name: api_key
104+
type: string
105+
userpool_id:
106+
name: userpool_id
107+
type: optional<string>
108+
```
109+
110+
For more information, see the [`generators.yml` reference documentation](/sdks/reference/generators-yml#headers).
111+
112+
#### Client code
113+
114+
Both of the above configurations produce the same client code:
92115

93116
```python
94117
import os
95118
96119
class Client:
97120
98-
def __init__(self, *, apiKey: str, userpoolId: typing.Optional[str])
121+
def __init__(self, *, apiKey: str,
122+
userpoolId: typing.Optional[str])
99123
```
124+
125+
100126
</Accordion>
101127
</AccordionGroup>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: Customize README
3+
description: Guide to configuring the README in your SDK
4+
---
5+
6+
By default, the README for your SDKs is generated programmatically. You can override this by configuring the `readme` section in `generators.yml` to control the content and structure of generated README files across all your SDKs.
7+
You can add custom introductions, showcase key endpoints, and organize your SDK documentation with feature sections.
8+
9+
```yaml title="generators.yml"
10+
readme:
11+
introduction: "Welcome to our API"
12+
apiReferenceLink: "https://docs.example.com"
13+
defaultEndpoint:
14+
method: "POST"
15+
path: "/users"
16+
features:
17+
authentication:
18+
- method: "POST"
19+
path: "/auth/login"
20+
users:
21+
- method: "GET"
22+
path: "/users"
23+
```
24+
25+
For more detailed information on `readme` configuration, see the [`generators.yml` documentation](/sdks/reference/generators-yml#readme)

fern/products/sdks/reference/generators-yml-reference.mdx

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,7 @@ Configures authentication methods for your API.
6464
6565
## api
6666
67-
<ParamField path="api" type="APIConfigurationSchema" toc={true}>
6867
Defines the API specification (OpenAPI, AsyncAPI, etc.) and how to parse it.
69-
</ParamField>
70-
71-
```yaml
72-
api:
73-
specs:
74-
- openapi: "./openapi.yml"
75-
namespace: "v1"
76-
settings:
77-
title-as-schema-name: true
78-
inline-path-parameters: false
79-
```
80-
81-
### General Configuration Options
8268
8369
```yaml
8470
api:
@@ -97,19 +83,41 @@ api:
9783
staging: "https://api.staging.com"
9884
```
9985
100-
<ParamField path="api.specs" type="list<SpecSchema> | ConjureSchema" required={true} toc={true}>
86+
<ParamField path="specs" type="list<SpecSchema> | ConjureSchema" required={true} toc={true}>
10187
List of API specifications or Conjure configuration.
10288
</ParamField>
10389
104-
<ParamField path="api.auth" type="ApiAuthSchema" toc={true}>
90+
<ParamField path="auth" type="ApiAuthSchema" toc={true}>
10591
Authentication configuration for the API.
10692
</ParamField>
10793
108-
<ParamField path="api.headers" type="map<string, string>" toc={true}>
109-
Default headers to include with API requests.
110-
</ParamField>
111-
112-
<ParamField path="api.environments" type="EnvironmentsSchema" toc={true}>
94+
<ParamField path="headers" type="map<string, HeaderValue>" toc={true}>
95+
Global headers to include with all API requests. You can specify headers as simple string values or as objects with additional configuration for code generation.
96+
97+
**Simple string values:**
98+
```yaml
99+
api:
100+
headers:
101+
Authorization: "Bearer ${API_TOKEN}"
102+
X-App-Version: "1.0.0"
103+
```
104+
105+
**Advanced configuration with type information:**
106+
```yaml
107+
api:
108+
- openapi: ./path/to/openapi
109+
headers:
110+
X-Version:
111+
# The variable name to use in generated SDK code.
112+
# If not specified, uses the header name.
113+
name: version
114+
# The type of the header value for code generation
115+
# (e.g., "string", "literal<'value'>", "number").
116+
type: literal<"1234">
117+
```
118+
</ParamField>
119+
120+
<ParamField path="environments" type="EnvironmentsSchema" toc={true}>
113121
Environment configurations for different deployment targets.
114122
</ParamField>
115123
@@ -135,87 +143,87 @@ api:
135143
max-depth: 2
136144
```
137145
138-
<ParamField path="specs[].openapi" type="string" required={true} toc={true}>
146+
<ParamField path="openapi" type="string" required={true} toc={true}>
139147
Path to the OpenAPI specification file.
140148
</ParamField>
141149
142-
<ParamField path="specs[].origin" type="string" toc={true}>
150+
<ParamField path="origin" type="string" toc={true}>
143151
URL of the API definition origin for polling updates.
144152
</ParamField>
145153
146-
<ParamField path="specs[].overrides" type="string" toc={true}>
154+
<ParamField path="overrides" type="string" toc={true}>
147155
Path to OpenAPI overrides file.
148156
</ParamField>
149157
150-
<ParamField path="specs[].namespace" type="string" toc={true}>
158+
<ParamField path="namespace" type="string" toc={true}>
151159
Namespace for the specification.
152160
</ParamField>
153161
154-
<ParamField path="specs[].settings" type="OpenAPISettingsSchema" toc={true}>
162+
<ParamField path="settings" type="OpenAPISettingsSchema" toc={true}>
155163
OpenAPI-specific generation settings.
156164
</ParamField>
157165
158-
<ParamField path="settings.title-as-schema-name" type="boolean" default="true" toc={true}>
166+
<ParamField path="title-as-schema-name" type="boolean" default="true" toc={true}>
159167
Whether to use the titles of schemas within an OpenAPI definition as the names of types within Fern.
160168
</ParamField>
161169
162-
<ParamField path="settings.inline-path-parameters" type="boolean" default="false" toc={true}>
170+
<ParamField path="inline-path-parameters" type="boolean" default="false" toc={true}>
163171
Whether to include path parameters within the generated in-lined request.
164172
</ParamField>
165173
166-
<ParamField path="settings.prefer-undiscriminated-unions-with-literals" type="boolean" default="false" toc={true}>
174+
<ParamField path="prefer-undiscriminated-unions-with-literals" type="boolean" default="false" toc={true}>
167175
Whether to prefer undiscriminated unions with literals.
168176
</ParamField>
169177
170-
<ParamField path="settings.only-include-referenced-schemas" type="boolean" default="false" toc={true}>
178+
<ParamField path="only-include-referenced-schemas" type="boolean" default="false" toc={true}>
171179
Whether to only include schemas referenced by endpoints in the generated SDK (tree-shaking).
172180
</ParamField>
173181
174-
<ParamField path="settings.respect-nullable-schemas" type="boolean" default="false" toc={true}>
182+
<ParamField path="respect-nullable-schemas" type="boolean" default="false" toc={true}>
175183
Preserves nullable schemas in API definition settings. When false, nullable schemas are treated as optional.
176184
</ParamField>
177185
178-
<ParamField path="settings.object-query-parameters" type="boolean" toc={true}>
186+
<ParamField path="object-query-parameters" type="boolean" toc={true}>
179187
Enables parsing deep object query parameters.
180188
</ParamField>
181189
182-
<ParamField path="settings.respect-readonly-schemas" type="boolean" toc={true}>
190+
<ParamField path="respect-readonly-schemas" type="boolean" toc={true}>
183191
Enables exploring readonly schemas in OpenAPI specifications.
184192
</ParamField>
185193
186-
<ParamField path="settings.respect-forward-compatible-enums" type="boolean" default="false" toc={true}>
194+
<ParamField path="respect-forward-compatible-enums" type="boolean" default="false" toc={true}>
187195
Enables respecting forward compatible enums in OpenAPI specifications.
188196
</ParamField>
189197
190-
<ParamField path="settings.use-bytes-for-binary-response" type="boolean" toc={true}>
198+
<ParamField path="use-bytes-for-binary-response" type="boolean" toc={true}>
191199
Enables using the `bytes` type for binary responses. Defaults to file stream.
192200
</ParamField>
193201

194-
<ParamField path="settings.default-form-parameter-encoding" type="FormParameterEncoding" default="json" toc={true}>
202+
<ParamField path="default-form-parameter-encoding" type="FormParameterEncoding" default="json" toc={true}>
195203
The default encoding of form parameters. Options: `form`, `json`.
196204
</ParamField>
197205

198-
<ParamField path="settings.additional-properties-defaults-to" type="boolean" default="false" toc={true}>
206+
<ParamField path="additional-properties-defaults-to" type="boolean" default="false" toc={true}>
199207
Configure what `additionalProperties` should default to when not explicitly defined on a schema.
200208
</ParamField>
201209

202-
<ParamField path="settings.type-dates-as-strings" type="boolean" default="true" toc={true}>
210+
<ParamField path="type-dates-as-strings" type="boolean" default="true" toc={true}>
203211
If true, convert strings with format date to strings. If false, convert to dates.
204212
</ParamField>
205213

206-
<ParamField path="settings.preserve-single-schema-oneof" type="boolean" default="false" toc={true}>
214+
<ParamField path="preserve-single-schema-oneof" type="boolean" default="false" toc={true}>
207215
If true, preserve oneOf structures with a single schema. If false, unwrap them.
208216
</ParamField>
209217

210-
<ParamField path="settings.filter.endpoints" type="list<string>" toc={true}>
218+
<ParamField path="filter.endpoints" type="list<string>" toc={true}>
211219
Endpoints to include in the generated SDK (e.g., "POST /users").
212220
</ParamField>
213221

214-
<ParamField path="settings.example-generation.request.max-depth" type="integer" toc={true}>
222+
<ParamField path="example-generation.request.max-depth" type="integer" toc={true}>
215223
Controls the maximum depth for which optional properties will have examples generated. A depth of 0 means no optional properties will have examples.
216224
</ParamField>
217225

218-
<ParamField path="settings.example-generation.response.max-depth" type="integer" toc={true}>
226+
<ParamField path="example-generation.response.max-depth" type="integer" toc={true}>
219227
Controls the maximum depth for which optional properties will have examples generated in responses.
220228
</ParamField>
221229

@@ -234,35 +242,35 @@ api:
234242
respect-nullable-schemas: true
235243
```
236244

237-
<ParamField path="specs[].asyncapi" type="string" required={true} toc={true}>
245+
<ParamField path="asyncapi" type="string" required={true} toc={true}>
238246
Path to the AsyncAPI specification file.
239247
</ParamField>
240248

241-
<ParamField path="specs[].origin" type="string" toc={true}>
249+
<ParamField path="origin" type="string" toc={true}>
242250
URL of the API definition origin for polling updates.
243251
</ParamField>
244252

245-
<ParamField path="specs[].overrides" type="string" toc={true}>
253+
<ParamField path="overrides" type="string" toc={true}>
246254
Path to AsyncAPI overrides file.
247255
</ParamField>
248256

249-
<ParamField path="specs[].namespace" type="string" toc={true}>
257+
<ParamField path="namespace" type="string" toc={true}>
250258
Namespace for the specification.
251259
</ParamField>
252260

253-
<ParamField path="specs[].settings" type="AsyncAPISettingsSchema" toc={true}>
261+
<ParamField path="settings" type="AsyncAPISettingsSchema" toc={true}>
254262
AsyncAPI-specific generation settings.
255263
</ParamField>
256264

257-
<ParamField path="settings.message-naming" type="MessageNamingSettingsSchema" default="v1" toc={true}>
265+
<ParamField path="message-naming" type="MessageNamingSettingsSchema" default="v1" toc={true}>
258266
What version of message naming to use for AsyncAPI messages. Options: `v1`, `v2`.
259267
</ParamField>
260268

261-
<ParamField path="settings.title-as-schema-name" type="boolean" default="true" toc={true}>
269+
<ParamField path="title-as-schema-name" type="boolean" default="true" toc={true}>
262270
Whether to use the titles of schemas within an AsyncAPI definition as the names of types within Fern.
263271
</ParamField>
264272

265-
<ParamField path="settings.respect-nullable-schemas" type="boolean" default="false" toc={true}>
273+
<ParamField path="respect-nullable-schemas" type="boolean" default="false" toc={true}>
266274
Preserves nullable schemas in API definition settings. When false, nullable schemas are treated as optional.
267275
</ParamField>
268276

@@ -277,37 +285,37 @@ api:
277285
local-generation: true
278286
```
279287

280-
<ParamField path="specs[].proto" type="ProtobufDefinitionSchema" required={true} toc={true}>
288+
<ParamField path="sproto" type="ProtobufDefinitionSchema" required={true} toc={true}>
281289
Protocol Buffers configuration.
282290
</ParamField>
283291

284-
<ParamField path="specs[].proto.target" type="string" toc={true}>
292+
<ParamField path="target" type="string" toc={true}>
285293
Path to the target `.proto` file (e.g., `proto/user/v1/user.proto`).
286294
</ParamField>
287295

288-
<ParamField path="specs[].proto.root" type="string" required={true} toc={true}>
296+
<ParamField path="root" type="string" required={true} toc={true}>
289297
Path to the `.proto` directory root (e.g., `proto`).
290298
</ParamField>
291299

292-
<ParamField path="specs[].proto.overrides" type="string" toc={true}>
300+
<ParamField path="overrides" type="string" toc={true}>
293301
Path to the overrides configuration.
294302
</ParamField>
295303

296-
<ParamField path="specs[].proto.local-generation" type="boolean" toc={true}>
304+
<ParamField path="local-generation" type="boolean" toc={true}>
297305
Whether to compile `.proto` files locally. Defaults to remote generation.
298306
</ParamField>
299307

300308
#### OpenRPC
301309

302-
<ParamField path="specs[].openrpc" type="string" required={true} toc={true}>
310+
<ParamField path=".openrpc" type="string" required={true} toc={true}>
303311
Path to the OpenRPC specification file.
304312
</ParamField>
305313

306-
<ParamField path="specs[].overrides" type="string" toc={true}>
314+
<ParamField path="overrides" type="string" toc={true}>
307315
Path to OpenRPC overrides file.
308316
</ParamField>
309317

310-
<ParamField path="specs[].namespace" type="string" toc={true}>
318+
<ParamField path="namespace" type="string" toc={true}>
311319
Namespace for the specification.
312320
</ParamField>
313321

@@ -319,7 +327,7 @@ api:
319327
conjure: "./conjure-api.yml"
320328
```
321329

322-
<ParamField path="specs.conjure" type="string" toc={true}>
330+
<ParamField path="conjure" type="string" toc={true}>
323331
Path to Conjure specification file.
324332
</ParamField>
325333

fern/products/sdks/sdks.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ navigation:
202202
- page: Filter Your Endpoints (Audiences)
203203
path: ./guides/filter-your-endpoints-audiences.mdx
204204
slug: audiences
205+
- page: Customize the README for your SDKs
206+
path: ./guides/configure-readme.mdx
207+
slug: readme
205208
- page: Self-host Fern's SDK Generators
206209
hidden: true
207210
path: ./guides/self-host-fern-generators.mdx

0 commit comments

Comments
 (0)