@@ -132,8 +132,11 @@ function OpenAPIResponse(props: {
132
132
} ) ;
133
133
134
134
return (
135
- < OpenAPITabs stateKey = { createStateKey ( 'media-type-examples' ) } items = { tabs } >
136
- < InteractiveSection header = { < OpenAPITabsList /> } className = "openapi-response-example" >
135
+ < OpenAPITabs stateKey = { createStateKey ( 'response-media-types' ) } items = { tabs } >
136
+ < InteractiveSection
137
+ header = { < OpenAPITabsList /> }
138
+ className = "openapi-response-media-types"
139
+ >
137
140
< OpenAPITabsPanels />
138
141
</ InteractiveSection >
139
142
</ OpenAPITabs >
@@ -155,20 +158,35 @@ function OpenAPIResponseMediaType(props: {
155
158
}
156
159
157
160
if ( examples . length === 1 ) {
158
- return < OpenAPIExample example = { firstExample } context = { props . context } syntax = { syntax } /> ;
161
+ return (
162
+ < OpenAPIExample
163
+ example = { firstExample . example }
164
+ context = { props . context }
165
+ syntax = { syntax }
166
+ />
167
+ ) ;
159
168
}
160
169
161
170
const tabs = examples . map ( ( example ) => {
162
171
return {
163
- key : example . summary || 'Example' ,
164
- label : example . summary || 'Example' ,
165
- body : < OpenAPIExample example = { firstExample } context = { props . context } syntax = { syntax } /> ,
172
+ key : example . key ,
173
+ label : example . example . summary || example . key ,
174
+ body : (
175
+ < OpenAPIExample
176
+ example = { firstExample . example }
177
+ context = { props . context }
178
+ syntax = { syntax }
179
+ />
180
+ ) ,
166
181
} ;
167
182
} ) ;
168
183
169
184
return (
170
- < OpenAPITabs stateKey = { createStateKey ( 'media-type-examples' ) } items = { tabs } >
171
- < InteractiveSection header = { < OpenAPITabsList /> } className = "openapi-response-example" >
185
+ < OpenAPITabs stateKey = { createStateKey ( 'response-media-type-examples' ) } items = { tabs } >
186
+ < InteractiveSection
187
+ header = { < OpenAPITabsList /> }
188
+ className = "openapi-response-media-type-examples"
189
+ >
172
190
< OpenAPITabsPanels />
173
191
</ InteractiveSection >
174
192
</ OpenAPITabs >
@@ -232,28 +250,43 @@ function getSyntaxFromMediaType(mediaType: string): string {
232
250
function getExamplesFromMediaTypeObject ( args : {
233
251
mediaType : string ;
234
252
mediaTypeObject : OpenAPIV3 . MediaTypeObject ;
235
- } ) : OpenAPIV3 . ExampleObject [ ] {
253
+ } ) : { key : string ; example : OpenAPIV3 . ExampleObject } [ ] {
236
254
const { mediaTypeObject, mediaType } = args ;
237
255
if ( mediaTypeObject . examples ) {
238
- return Object . values ( mediaTypeObject . examples ) . map ( ( example ) => {
239
- return checkIsReference ( example ) ? getExampleFromReference ( example ) : example ;
256
+ return Object . entries ( mediaTypeObject . examples ) . map ( ( [ key , example ] ) => {
257
+ return {
258
+ key,
259
+ example : checkIsReference ( example ) ? getExampleFromReference ( example ) : example ,
260
+ } ;
240
261
} ) ;
241
262
}
242
263
243
264
if ( mediaTypeObject . example ) {
244
- return [ { value : mediaTypeObject . example } ] ;
265
+ return [ { key : 'default' , example : { value : mediaTypeObject . example } } ] ;
245
266
}
246
267
247
268
if ( mediaTypeObject . schema ) {
248
- // @TODO normally we should use the name of the schema but we don't have it
249
- const root = mediaTypeObject . schema . xml ?. name ?? 'object' ;
269
+ if ( mediaType === 'application/xml' ) {
270
+ // @TODO normally we should use the name of the schema but we don't have it
271
+ // fix it when we got the reference name
272
+ const root = mediaTypeObject . schema . xml ?. name ?? 'object' ;
273
+ return [
274
+ {
275
+ key : 'default' ,
276
+ example : {
277
+ value : {
278
+ [ root ] : generateSchemaExample ( mediaTypeObject . schema , {
279
+ xml : mediaType === 'application/xml' ,
280
+ } ) ,
281
+ } ,
282
+ } ,
283
+ } ,
284
+ ] ;
285
+ }
250
286
return [
251
287
{
252
- value : {
253
- [ root ] : generateSchemaExample ( mediaTypeObject . schema , {
254
- xml : mediaType === 'application/xml' ,
255
- } ) ,
256
- } ,
288
+ key : 'default' ,
289
+ example : { value : generateSchemaExample ( mediaTypeObject . schema ) } ,
257
290
} ,
258
291
] ;
259
292
}
0 commit comments