File tree Expand file tree Collapse file tree 3 files changed +67
-4
lines changed Expand file tree Collapse file tree 3 files changed +67
-4
lines changed Original file line number Diff line number Diff line change @@ -136,10 +136,18 @@ export default class Response extends React.Component {
136
136
} )
137
137
}
138
138
} else {
139
- sampleResponse = schema ? getSampleSchema ( schema . toJS ( ) , activeContentType , {
140
- includeReadOnly : true ,
141
- includeWriteOnly : true // writeOnly has no filtering effect in swagger 2.0
142
- } ) : null
139
+ if ( response . getIn ( [ "examples" , activeContentType ] ) ) {
140
+ sampleResponse = response . getIn ( [ "examples" , activeContentType ] )
141
+ } else {
142
+ sampleResponse = schema ? getSampleSchema (
143
+ schema . toJS ( ) ,
144
+ activeContentType ,
145
+ {
146
+ includeReadOnly : true ,
147
+ includeWriteOnly : true // writeOnly has no filtering effect in swagger 2.0
148
+ }
149
+ ) : null
150
+ }
143
151
}
144
152
145
153
let example = getExampleComponent ( sampleResponse , HighlightCode )
Original file line number Diff line number Diff line change
1
+ swagger : " 2.0"
2
+ info :
3
+ title : test
4
+ version : 1.0.0
5
+ paths :
6
+ /foo1 :
7
+ get :
8
+ summary : Response without a schema
9
+ produces :
10
+ - application/json
11
+ responses :
12
+ 200 :
13
+ description : Successful response
14
+ examples :
15
+ application/json :
16
+ foo : custom value
17
+ /foo2 :
18
+ get :
19
+ summary : Response with schema
20
+ produces :
21
+ - application/json
22
+ responses :
23
+ 200 :
24
+ description : Successful response
25
+ schema :
26
+ $ref : ' #/definitions/Foo'
27
+ examples :
28
+ application/json :
29
+ foo : custom value
30
+
31
+ definitions :
32
+ Foo :
33
+ type : object
34
+ properties :
35
+ foo :
36
+ type : string
37
+ example : bar
Original file line number Diff line number Diff line change
1
+ // http://github.com/swagger-api/swagger-ui/issues/5458
2
+
3
+ describe ( "#5458: Swagger 2.0 `Response.examples` mappings" , ( ) => {
4
+ it ( "should render a custom example when a schema is not defined" , ( ) => {
5
+ cy . visit ( "/?url=/documents/bugs/5458.yaml" )
6
+ . get ( "#operations-default-get_foo1" )
7
+ . click ( )
8
+ . get ( ".model-example .highlight-code" )
9
+ . contains ( "custom value" )
10
+ } )
11
+ it ( "should render a custom example when a schema is defined" , ( ) => {
12
+ cy . visit ( "/?url=/documents/bugs/5458.yaml" )
13
+ . get ( "#operations-default-get_foo2" )
14
+ . click ( )
15
+ . get ( ".model-example .highlight-code" )
16
+ . contains ( "custom value" )
17
+ } )
18
+ } )
You can’t perform that action at this time.
0 commit comments