4
4
5
5
const each = require ( 'lodash/each' ) ;
6
6
7
- module . exports . validate = function ( { jsSpec , isOAS3 } , config ) {
7
+ module . exports . validate = function ( { resolvedSpec , isOAS3 } , config ) {
8
8
const result = { } ;
9
9
result . error = [ ] ;
10
10
result . warning = [ ] ;
11
11
12
12
config = config . security_definitions ;
13
13
14
- const usedSchemes = { } ;
15
- const usedScopes = { } ;
14
+ const definedSchemes = { } ;
15
+ const definedScopes = { } ;
16
16
17
17
// collect the security requirements and all relevant scopes
18
18
19
19
const securityDefinitions = isOAS3
20
- ? jsSpec . components && jsSpec . components . securitySchemes
21
- : jsSpec . securityDefinitions ;
20
+ ? resolvedSpec . components && resolvedSpec . components . securitySchemes
21
+ : resolvedSpec . securityDefinitions ;
22
22
23
23
each ( securityDefinitions , ( scheme , name ) => {
24
24
if ( name . slice ( 0 , 2 ) === 'x-' ) return ;
25
25
26
- usedSchemes [ name ] = { } ;
27
- usedSchemes [ name ] . used = false ;
28
- usedSchemes [ name ] . type = scheme . type ;
26
+ definedSchemes [ name ] = { } ;
27
+ definedSchemes [ name ] . used = false ;
28
+ definedSchemes [ name ] . type = scheme . type ;
29
29
30
30
// collect scopes in oauth2 schemes
31
31
if ( scheme . type . toLowerCase ( ) === 'oauth2' ) {
@@ -34,19 +34,19 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
34
34
each ( scheme . flows , ( flow , flowType ) => {
35
35
if ( flow . scopes ) {
36
36
Object . keys ( flow . scopes ) . forEach ( scope => {
37
- usedScopes [ scope ] = { } ;
38
- usedScopes [ scope ] . used = false ;
39
- usedScopes [ scope ] . scheme = name ;
40
- usedScopes [ scope ] . flow = flowType ;
37
+ definedScopes [ scope ] = { } ;
38
+ definedScopes [ scope ] . used = false ;
39
+ definedScopes [ scope ] . scheme = name ;
40
+ definedScopes [ scope ] . flow = flowType ;
41
41
} ) ;
42
42
}
43
43
} ) ;
44
44
}
45
45
} else {
46
46
Object . keys ( scheme . scopes ) . forEach ( scope => {
47
- usedScopes [ scope ] = { } ;
48
- usedScopes [ scope ] . used = false ;
49
- usedScopes [ scope ] . scheme = name ;
47
+ definedScopes [ scope ] = { } ;
48
+ definedScopes [ scope ] . used = false ;
49
+ definedScopes [ scope ] . scheme = name ;
50
50
} ) ;
51
51
}
52
52
}
@@ -56,12 +56,12 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
56
56
// security objects can exist at either:
57
57
58
58
// 1) the top level of the spec (global definition)
59
- if ( jsSpec . security ) {
60
- flagUsedDefinitions ( jsSpec . security ) ;
59
+ if ( resolvedSpec . security ) {
60
+ flagUsedDefinitions ( resolvedSpec . security ) ;
61
61
}
62
62
63
63
// 2) within operations objects
64
- const paths = jsSpec . paths ;
64
+ const paths = resolvedSpec . paths ;
65
65
each ( paths , ( operations , pathName ) => {
66
66
if ( pathName . slice ( 0 , 2 ) === 'x-' ) return ;
67
67
each ( operations , ( operation , opName ) => {
@@ -78,16 +78,16 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
78
78
const name = Object . keys ( scheme ) [ 0 ] ;
79
79
80
80
// make sure this scheme was in the security definitions, then label as used
81
- if ( usedSchemes [ name ] ) {
82
- usedSchemes [ name ] . used = true ;
81
+ if ( definedSchemes [ name ] ) {
82
+ definedSchemes [ name ] . used = true ;
83
83
84
- const type = usedSchemes [ name ] . type ;
84
+ const type = definedSchemes [ name ] . type ;
85
85
const scopesArray = scheme [ name ] ;
86
86
87
87
if ( type . toLowerCase ( ) === 'oauth2' ) {
88
88
scopesArray . forEach ( scope => {
89
- if ( usedScopes [ scope ] ) {
90
- usedScopes [ scope ] . used = true ;
89
+ if ( definedScopes [ scope ] ) {
90
+ definedScopes [ scope ] . used = true ;
91
91
}
92
92
} ) ;
93
93
}
@@ -96,7 +96,7 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
96
96
}
97
97
98
98
// check what has been used and what has not been
99
- each ( usedSchemes , ( info , name ) => {
99
+ each ( definedSchemes , ( info , name ) => {
100
100
if ( info . used === false ) {
101
101
const checkStatus = config . unused_security_schemes ;
102
102
if ( checkStatus !== 'off' ) {
@@ -111,7 +111,7 @@ module.exports.validate = function({ jsSpec, isOAS3 }, config) {
111
111
}
112
112
} ) ;
113
113
114
- each ( usedScopes , ( info , name ) => {
114
+ each ( definedScopes , ( info , name ) => {
115
115
if ( info . used === false ) {
116
116
const checkStatus = config . unused_security_scopes ;
117
117
if ( checkStatus !== 'off' ) {
0 commit comments