File tree 4 files changed +45
-0
lines changed
4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ import CollapsingDetails from './CollapsingDetails' ;
2
+ import Details from './Details' ;
3
+ import { Example } from './metamodel' ;
4
+
5
+ type Props = {
6
+ examples : Record < string , Example > ;
7
+ } ;
8
+
9
+ export default function Examples ( { examples } : Props ) {
10
+ return (
11
+ < CollapsingDetails header = "Examples" >
12
+ { Object . keys ( examples ) . map ( example => (
13
+ < CollapsingDetails header = { example } >
14
+ { examples [ example ] . summary && < Details header = "Summary" value = { examples [ example ] . summary } /> }
15
+ { examples [ example ] . description && < Details header = "Description" value = { examples [ example ] . description } /> }
16
+ { examples [ example ] . value && < Details header = "Value" value = { examples [ example ] . value } /> }
17
+ { examples [ example ] . external_value && < Details header = "External Value" value = { examples [ example ] . external_value } /> }
18
+ </ CollapsingDetails >
19
+ ) ) }
20
+ </ CollapsingDetails >
21
+ ) ;
22
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import Properties from './Properties';
5
5
import Body from './Body' ;
6
6
import Behaviors from './Behaviors' ;
7
7
import AttachedBehaviors from './AttachedBehaviors' ;
8
+ import Examples from './Examples' ;
8
9
9
10
import { Request as RequestType } from './metamodel' ;
10
11
@@ -28,6 +29,7 @@ export default function Request({ type }: Props) {
28
29
< Body body = { type . body } />
29
30
{ type . behaviors && < Behaviors behaviors = { type . behaviors } /> }
30
31
{ type . attachedBehaviors && < AttachedBehaviors behaviors = { type . attachedBehaviors } /> }
32
+ { type . examples && < Examples examples = { type . examples } /> }
31
33
</ >
32
34
) ;
33
35
}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import Body from './Body';
4
4
import Behaviors from './Behaviors' ;
5
5
import Description from './Description' ;
6
6
import AttachedBehaviors from './AttachedBehaviors' ;
7
+ import Examples from './Examples' ;
7
8
8
9
import { Response as ResponseType } from './metamodel' ;
9
10
@@ -34,6 +35,7 @@ export default function Response({ type }: Props) {
34
35
) ) }
35
36
</ CollapsingDetails >
36
37
}
38
+ { type . examples && < Examples examples = { type . examples } /> }
37
39
</ >
38
40
) ;
39
41
}
Original file line number Diff line number Diff line change @@ -260,6 +260,23 @@ export class Interface extends BaseType {
260
260
variants ?: Container
261
261
}
262
262
263
+ /**
264
+ * The Example type is used for both requests and responses
265
+ * This type definition is taken from the OpenAPI spec
266
+ * https://spec.openapis.org/oas/v3.1.0#example-object
267
+ * With the exception of using String as the 'value' type
268
+ */
269
+ export class Example {
270
+ /** Short description. */
271
+ summary ?: string
272
+ /** Long description. */
273
+ description ?: string
274
+ /** Embedded literal example. Mutually exclusive with `external_value` */
275
+ value ?: string
276
+ /** A URI that points to the literal example */
277
+ external_value ?: string
278
+ }
279
+
263
280
/**
264
281
* A request type
265
282
*/
@@ -288,6 +305,7 @@ export class Request extends BaseType {
288
305
body : Body
289
306
behaviors ?: Behavior [ ]
290
307
attachedBehaviors ?: string [ ]
308
+ examples ?: Record < string , Example >
291
309
}
292
310
293
311
/**
@@ -300,6 +318,7 @@ export class Response extends BaseType {
300
318
behaviors ?: Behavior [ ]
301
319
attachedBehaviors ?: string [ ]
302
320
exceptions ?: ResponseException [ ]
321
+ examples ?: Record < string , Example >
303
322
}
304
323
305
324
export class ResponseException {
You can’t perform that action at this time.
0 commit comments