Skip to content

Commit 7166adc

Browse files
authored
(api definitions) Document headers in examples for Fern Definition and OpenAPI (#882)
1 parent d2e5577 commit 7166adc

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

fern/products/api-def/ferndef-pages/api-yml/global-configuration.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ headers:
1717
```
1818
</CodeBlock>
1919
20+
When you define global headers in your `api.yml`, you must [include them in your endpoint examples](/api-definitions/ferndef/examples#examples-with-headers).
21+
2022
## Global path parameters
2123

2224
You can specify path parameters that are meant to be included on every request:

fern/products/api-def/ferndef-pages/examples.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,38 @@ errors:
315315
type: InsufficientFundsBody
316316
```
317317

318+
### Examples with headers
319+
320+
When you have [global headers defined in your `api.yml`](/api-definitions/ferndef/api-yml/global-headers#global-headers), you must include them in your examples:
321+
322+
```yml {15-16}
323+
service:
324+
auth: true
325+
base-path: ""
326+
endpoints:
327+
CreateShippingLabel:
328+
docs: Create a new shipping label.
329+
method: POST
330+
path: /shipping
331+
request: CreateShippingLabelRequest
332+
response: ShippingLabel
333+
errors:
334+
- NotAuthorized
335+
- InsufficientFunds
336+
examples:
337+
- headers:
338+
X-App-Id: "app_12345"
339+
request:
340+
orderId: "online_789"
341+
weightInOunces: 5
342+
response:
343+
body:
344+
orderId: "online_789"
345+
weightInOunces: 5
346+
trackingNumber: "1Z26W8370303469306"
347+
price: 2.50
348+
```
349+
318350
## Examples for path parameters
319351

320352
```yml

fern/products/api-def/openapi-pages/extensions/examples.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ you want to show more than one example in your documentation.
99

1010
`x-fern-examples` is an array of examples. Each element of the array
1111
can contain `path-parameters`, `query-parameters`, `request` and `response`
12-
examples values that are all associated.
12+
examples values that are all associated. If you [defined global headers via the `x-fern-global-headers` extension](/api-definitions/openapi/extensions/global-headers), you must include the headers in your examples.
1313

14-
```yaml title="openapi.yml" {5-16}
14+
```yaml title="openapi.yml" {5-19}
1515
paths:
1616
/users/{userId}:
1717
get:
1818
x-fern-examples:
19+
- headers:
20+
custom_api_key: "capi_12345" # header defined using x-global-header extension
21+
userpool_id: "pool_67890" # header defined using x-global-header extension
1922
- path-parameters:
2023
userId: user-1234
2124
response:

fern/products/api-def/openapi-pages/extensions/global-headers.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ class Client:
3333

3434
def __init__(self, *, apiKey: str, userpoolId: typing.Optional[str])
3535
```
36+
37+
When you define global headers using `x-fern-global-headers`, you must [include them in your `x-fern-examples`](/api-definitions/openapi/extensions/request-response-examples).

0 commit comments

Comments
 (0)