@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
3
3
import { CodeSampleInput , codeSampleGenerators } from './code-samples' ;
4
4
import { OpenAPIOperationData , toJSON } from './fetchOpenAPIOperation' ;
5
- import { generateMediaTypeExample } from './generateSchemaExample' ;
5
+ import { generateMediaTypeExample , generateSchemaExample } from './generateSchemaExample' ;
6
6
import { InteractiveSection } from './InteractiveSection' ;
7
7
import { getServersURL } from './OpenAPIServerURL' ;
8
8
import { ScalarApiButton } from './ScalarApiButton' ;
@@ -19,6 +19,21 @@ export function OpenAPICodeSample(props: {
19
19
} ) {
20
20
const { data, context } = props ;
21
21
22
+ const requiredHeaders = data . operation . parameters
23
+ ?. map ( noReference )
24
+ . filter ( ( param ) => param . in === 'header' && param . required ) ;
25
+
26
+ const headersObject : { [ k : string ] : string } = { } ;
27
+ requiredHeaders ?. forEach ( ( header ) => {
28
+ const example = header . schema
29
+ ? generateSchemaExample ( noReference ( header . schema ) )
30
+ : undefined ;
31
+ if ( example !== undefined ) {
32
+ headersObject [ header . name ] =
33
+ typeof example !== 'string' ? JSON . stringify ( example ) : example ;
34
+ }
35
+ } ) ;
36
+
22
37
const requestBody = noReference ( data . operation . requestBody ) ;
23
38
const requestBodyContent = requestBody ? Object . entries ( requestBody . content ) [ 0 ] : undefined ;
24
39
@@ -30,6 +45,7 @@ export function OpenAPICodeSample(props: {
30
45
: undefined ,
31
46
headers : {
32
47
...getSecurityHeaders ( data . securities ) ,
48
+ ...headersObject ,
33
49
...( requestBodyContent
34
50
? {
35
51
'Content-Type' : requestBodyContent [ 0 ] ,
0 commit comments