File tree Expand file tree Collapse file tree 4 files changed +172
-2
lines changed Expand file tree Collapse file tree 4 files changed +172
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,10 @@ const spec = state => {
46
46
47
47
export const definitions = onlyOAS3 ( createSelector (
48
48
spec ,
49
- spec => spec . getIn ( [ "components" , "schemas" ] ) || Map ( )
49
+ spec => {
50
+ const res = spec . getIn ( [ "components" , "schemas" ] )
51
+ return Map . isMap ( res ) ? res : Map ( )
52
+ }
50
53
) )
51
54
52
55
export const hasHost = onlyOAS3 ( ( state ) => {
Original file line number Diff line number Diff line change @@ -175,7 +175,10 @@ export const findDefinition = ( state, name ) => {
175
175
176
176
export const definitions = createSelector (
177
177
spec ,
178
- spec => spec . get ( "definitions" ) || Map ( )
178
+ spec => {
179
+ const res = spec . get ( "definitions" )
180
+ return Map . isMap ( res ) ? res : Map ( )
181
+ }
179
182
)
180
183
181
184
export const basePath = createSelector (
Original file line number Diff line number Diff line change
1
+ /* eslint-env mocha */
2
+ import expect , { createSpy } from "expect"
3
+ import { Map , fromJS } from "immutable"
4
+ import {
5
+ definitions
6
+ } from "corePlugins/oas3/spec-extensions/wrap-selectors"
7
+
8
+ describe ( "oas3 plugin - spec extensions - wrapSelectors" , function ( ) {
9
+
10
+ describe ( "definitions" , function ( ) {
11
+ it ( "should return definitions by default" , function ( ) {
12
+
13
+ // Given
14
+ const spec = fromJS ( {
15
+ openapi : "3.0.0" ,
16
+ components : {
17
+ schemas : {
18
+ a : {
19
+ type : "string"
20
+ } ,
21
+ b : {
22
+ type : "string"
23
+ }
24
+ }
25
+ }
26
+ } )
27
+
28
+ const system = {
29
+ getSystem : ( ) => system ,
30
+ specSelectors : {
31
+ specJson : ( ) => spec ,
32
+ }
33
+ }
34
+
35
+ // When
36
+ let res = definitions ( ( ) => null , system ) ( fromJS ( {
37
+ json : spec
38
+ } ) )
39
+
40
+ // Then
41
+ expect ( res . toJS ( ) ) . toEqual ( {
42
+ a : {
43
+ type : "string"
44
+ } ,
45
+ b : {
46
+ type : "string"
47
+ }
48
+ } )
49
+ } )
50
+ it ( "should return an empty Map when missing definitions" , function ( ) {
51
+
52
+ // Given
53
+ const spec = fromJS ( {
54
+ openapi : "3.0.0"
55
+ } )
56
+
57
+ const system = {
58
+ getSystem : ( ) => system ,
59
+ specSelectors : {
60
+ specJson : ( ) => spec ,
61
+ }
62
+ }
63
+
64
+ // When
65
+ let res = definitions ( ( ) => null , system ) ( fromJS ( {
66
+ json : spec
67
+ } ) )
68
+
69
+ // Then
70
+ expect ( res . toJS ( ) ) . toEqual ( { } )
71
+ } )
72
+ it ( "should return an empty Map when given non-object definitions" , function ( ) {
73
+
74
+ // Given
75
+ const spec = fromJS ( {
76
+ openapi : "3.0.0" ,
77
+ components : {
78
+ schemas : "..."
79
+ }
80
+ } )
81
+
82
+ const system = {
83
+ getSystem : ( ) => system ,
84
+ specSelectors : {
85
+ specJson : ( ) => spec ,
86
+ }
87
+ }
88
+
89
+ // When
90
+ let res = definitions ( ( ) => null , system ) ( fromJS ( {
91
+ json : spec
92
+ } ) )
93
+
94
+ // Then
95
+ expect ( res . toJS ( ) ) . toEqual ( { } )
96
+ } )
97
+ } )
98
+
99
+ } )
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import expect from "expect"
3
3
import { fromJS } from "immutable"
4
4
import { fromJSOrdered } from "core/utils"
5
5
import {
6
+ definitions ,
6
7
parameterValues ,
7
8
contentTypeValues ,
8
9
operationScheme ,
@@ -21,6 +22,70 @@ import {
21
22
22
23
describe ( "spec plugin - selectors" , function ( ) {
23
24
25
+ describe ( "definitions" , function ( ) {
26
+ it ( "should return definitions by default" , function ( ) {
27
+
28
+ // Given
29
+ const spec = fromJS ( {
30
+ json : {
31
+ swagger : "2.0" ,
32
+ definitions : {
33
+ a : {
34
+ type : "string"
35
+ } ,
36
+ b : {
37
+ type : "string"
38
+ }
39
+ }
40
+ }
41
+ } )
42
+
43
+ // When
44
+ let res = definitions ( spec )
45
+
46
+ // Then
47
+ expect ( res . toJS ( ) ) . toEqual ( {
48
+ a : {
49
+ type : "string"
50
+ } ,
51
+ b : {
52
+ type : "string"
53
+ }
54
+ } )
55
+ } )
56
+ it ( "should return an empty Map when missing definitions" , function ( ) {
57
+
58
+ // Given
59
+ const spec = fromJS ( {
60
+ json : {
61
+ swagger : "2.0"
62
+ }
63
+ } )
64
+
65
+ // When
66
+ let res = definitions ( spec )
67
+
68
+ // Then
69
+ expect ( res . toJS ( ) ) . toEqual ( { } )
70
+ } )
71
+ it ( "should return an empty Map when given non-object definitions" , function ( ) {
72
+
73
+ // Given
74
+ const spec = fromJS ( {
75
+ json : {
76
+ swagger : "2.0" ,
77
+ definitions : "..."
78
+ }
79
+ } )
80
+
81
+ // When
82
+ let res = definitions ( spec )
83
+
84
+ // Then
85
+ expect ( res . toJS ( ) ) . toEqual ( { } )
86
+ } )
87
+ } )
88
+
24
89
describe ( "parameterValue" , function ( ) {
25
90
26
91
it ( "should return Map({}) if no path found" , function ( ) {
You can’t perform that action at this time.
0 commit comments