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 +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change
1
+ const getSchema = require ( '../../src/lib/get-schema' ) ;
2
+
3
+ const schema = { type : 'string' } ;
4
+
5
+ test ( 'should return the first type if there is content' , ( ) => {
6
+ expect (
7
+ getSchema ( {
8
+ requestBody : {
9
+ content : {
10
+ 'application/json' : {
11
+ schema,
12
+ } ,
13
+ 'text/xml' : {
14
+ schema : { type : 'number' } ,
15
+ } ,
16
+ } ,
17
+ } ,
18
+ } ) ,
19
+ ) . toBe ( schema ) ;
20
+
21
+ expect (
22
+ getSchema ( {
23
+ requestBody : {
24
+ content : {
25
+ 'text/xml' : {
26
+ schema,
27
+ } ,
28
+ 'application/json' : {
29
+ schema : { type : 'number' } ,
30
+ } ,
31
+ } ,
32
+ } ,
33
+ } ) ,
34
+ ) . toBe ( schema ) ;
35
+ } ) ;
36
+
37
+ test ( 'should return the requestBody' , ( ) => {
38
+ expect ( getSchema ( { requestBody : schema } ) ) . toBe ( schema ) ;
39
+ } ) ;
Original file line number Diff line number Diff line change @@ -3,7 +3,8 @@ module.exports = pathOperation => {
3
3
4
4
try {
5
5
if ( pathOperation . requestBody . content ) {
6
- schema = pathOperation . requestBody . content [ 'application/json' ] . schema ;
6
+ const firstType = Object . keys ( pathOperation . requestBody . content ) [ 0 ]
7
+ schema = pathOperation . requestBody . content [ firstType ] . schema ;
7
8
} else {
8
9
schema = pathOperation . requestBody ;
9
10
}
You can’t perform that action at this time.
0 commit comments