This repository was archived by the owner on Nov 28, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +48
-11
lines changed Expand file tree Collapse file tree 2 files changed +48
-11
lines changed Original file line number Diff line number Diff line change @@ -149,7 +149,45 @@ test('should contain ResponseSchemaBody element if $ref exist for "application/x
149
149
} ;
150
150
151
151
const responseSchema = shallow ( < ResponseSchema { ...testProps } /> ) ;
152
- expect ( responseSchema . text ( ) ) . toContain ( 'ResponseSchemaBody' ) ;
152
+ expect ( responseSchema . find ( 'ResponseSchemaBody' ) . length ) . toBe ( 1 ) ;
153
+ } ) ;
154
+
155
+ test ( 'should allow $ref lookup at the responses object level' , ( ) => {
156
+ const testOas = new Oas ( {
157
+ components : {
158
+ responses : {
159
+ Response : {
160
+ content : {
161
+ 'application/json' : {
162
+ schema : {
163
+ type : 'string' ,
164
+ } ,
165
+ } ,
166
+ } ,
167
+ } ,
168
+ } ,
169
+ } ,
170
+ paths : {
171
+ '/ref-responses' : {
172
+ get : {
173
+ responses : {
174
+ 200 : {
175
+ $ref : '#/components/responses/Response' ,
176
+ } ,
177
+ } ,
178
+ } ,
179
+ } ,
180
+ } ,
181
+ } ) ;
182
+
183
+ const responseSchema = shallow (
184
+ < ResponseSchema
185
+ { ...props }
186
+ oas = { testOas }
187
+ operation = { testOas . operation ( '/ref-responses' , 'get' ) }
188
+ /> ,
189
+ ) ;
190
+ expect ( responseSchema . find ( 'ResponseSchemaBody' ) . length ) . toBe ( 1 ) ;
153
191
} ) ;
154
192
155
193
test ( 'should change selectedStatus in component' , ( ) => {
Original file line number Diff line number Diff line change @@ -19,12 +19,11 @@ class ResponseSchema extends React.Component {
19
19
}
20
20
21
21
getSchema ( operation ) {
22
- const content = this . getContent ( operation ) ;
22
+ const oas = this . props . oas ;
23
+ const content = this . getContent ( operation , oas ) ;
23
24
24
25
if ( ! content ) return null ;
25
26
26
- const oas = this . props . oas ;
27
-
28
27
const firstContentType = Object . keys ( content ) [ 0 ] ;
29
28
30
29
if (
@@ -42,14 +41,14 @@ class ResponseSchema extends React.Component {
42
41
return null ;
43
42
}
44
43
45
- getContent ( operation ) {
44
+ getContent ( operation , oas ) {
46
45
const status = this . state . selectedStatus ;
47
- return (
48
- operation &&
49
- operation . responses &&
50
- operation . responses [ status ] &&
51
- operation . responses [ status ] . content
52
- ) ;
46
+ const response = operation && operation . responses && operation . responses [ status ] ;
47
+
48
+ if ( ! response ) return false ;
49
+
50
+ if ( response . $ref ) return findSchemaDefinition ( response . $ref , oas ) . content ;
51
+ return response . content ;
53
52
}
54
53
55
54
changeHandler ( e ) {
You can’t perform that action at this time.
0 commit comments