File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
packages/docusaurus-theme-openapi-docs/src/theme/SchemaItem Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ export default function SchemaItem(props: Props) {
66
66
let deprecated ;
67
67
let schemaDescription ;
68
68
let defaultValue : string | undefined ;
69
+ let example : string | undefined ;
69
70
let nullable ;
70
71
let enumDescriptions : [ string , string ] [ ] = [ ] ;
71
72
@@ -74,6 +75,7 @@ export default function SchemaItem(props: Props) {
74
75
schemaDescription = schema . description ;
75
76
enumDescriptions = transformEnumDescriptions ( schema [ "x-enumDescriptions" ] ) ;
76
77
defaultValue = schema . default ;
78
+ example = schema . example ;
77
79
nullable = schema . nullable ;
78
80
}
79
81
@@ -157,6 +159,30 @@ export default function SchemaItem(props: Props) {
157
159
return undefined ;
158
160
}
159
161
162
+ function renderExample ( ) {
163
+ if ( example !== undefined ) {
164
+ if ( typeof example === "string" ) {
165
+ return (
166
+ < div >
167
+ < strong > Example: </ strong >
168
+ < span >
169
+ < code > { example } </ code >
170
+ </ span >
171
+ </ div >
172
+ ) ;
173
+ }
174
+ return (
175
+ < div >
176
+ < strong > Example: </ strong >
177
+ < span >
178
+ < code > { JSON . stringify ( example ) } </ code >
179
+ </ span >
180
+ </ div >
181
+ ) ;
182
+ }
183
+ return undefined ;
184
+ }
185
+
160
186
const schemaContent = (
161
187
< div >
162
188
< span className = "openapi-schema__container" >
@@ -179,6 +205,7 @@ export default function SchemaItem(props: Props) {
179
205
{ renderEnumDescriptions }
180
206
{ renderQualifierMessage }
181
207
{ renderDefaultValue ( ) }
208
+ { renderExample ( ) }
182
209
{ collapsibleSchemaContent ?? collapsibleSchemaContent }
183
210
</ div >
184
211
) ;
You can’t perform that action at this time.
0 commit comments