1
1
import type { OpenAPIV3 } from '@gitbook/openapi-parser' ;
2
+ import type { OpenAPIContext , OpenAPIUniversalContext } from './context' ;
2
3
import { generateSchemaExample } from './generateSchemaExample' ;
3
4
import { json2xml } from './json2xml' ;
4
5
import { stringifyOpenAPI } from './stringifyOpenAPI' ;
5
- import type { OpenAPIContext } from './types ' ;
6
+ import { t , tString } from './translate ' ;
6
7
import { checkIsReference } from './utils' ;
7
8
8
9
/**
@@ -17,7 +18,7 @@ export function OpenAPIExample(props: {
17
18
const code = stringifyExample ( { example, xml : syntax === 'xml' } ) ;
18
19
19
20
if ( code === null ) {
20
- return < OpenAPIEmptyExample /> ;
21
+ return < OpenAPIEmptyExample context = { context } /> ;
21
22
}
22
23
23
24
return context . renderCodeBlock ( { code, syntax } ) ;
@@ -44,19 +45,28 @@ function stringifyExample(args: { example: OpenAPIV3.ExampleObject; xml: boolean
44
45
/**
45
46
* Empty response example.
46
47
*/
47
- export function OpenAPIEmptyExample ( ) {
48
+ export function OpenAPIEmptyExample ( props : {
49
+ context : OpenAPIUniversalContext ;
50
+ } ) {
51
+ const { context } = props ;
48
52
return (
49
53
< pre className = "openapi-example-empty" >
50
- < p > No Content </ p >
54
+ < p > { t ( context . translation , 'no_content' ) } </ p >
51
55
</ pre >
52
56
) ;
53
57
}
54
58
55
59
/**
56
60
* Generate an example from a reference object.
57
61
*/
58
- export function getExampleFromReference ( ref : OpenAPIV3 . ReferenceObject ) : OpenAPIV3 . ExampleObject {
59
- return { summary : 'Unresolved reference' , value : { $ref : ref . $ref } } ;
62
+ export function getExampleFromReference (
63
+ ref : OpenAPIV3 . ReferenceObject ,
64
+ context : OpenAPIContext
65
+ ) : OpenAPIV3 . ExampleObject {
66
+ return {
67
+ summary : tString ( context . translation , 'unresolved_reference' ) ,
68
+ value : { $ref : ref . $ref } ,
69
+ } ;
60
70
}
61
71
62
72
/**
@@ -65,13 +75,16 @@ export function getExampleFromReference(ref: OpenAPIV3.ReferenceObject): OpenAPI
65
75
export function getExamplesFromMediaTypeObject ( args : {
66
76
mediaType : string ;
67
77
mediaTypeObject : OpenAPIV3 . MediaTypeObject ;
78
+ context : OpenAPIContext ;
68
79
} ) : { key : string ; example : OpenAPIV3 . ExampleObject } [ ] {
69
- const { mediaTypeObject, mediaType } = args ;
80
+ const { mediaTypeObject, mediaType, context } = args ;
70
81
if ( mediaTypeObject . examples ) {
71
82
return Object . entries ( mediaTypeObject . examples ) . map ( ( [ key , example ] ) => {
72
83
return {
73
84
key,
74
- example : checkIsReference ( example ) ? getExampleFromReference ( example ) : example ,
85
+ example : checkIsReference ( example )
86
+ ? getExampleFromReference ( example , context )
87
+ : example ,
75
88
} ;
76
89
} ) ;
77
90
}
0 commit comments