File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed
Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 171171 }
172172 }
173173 },
174+ "/multiple-combo-auths-duped" : {
175+ "get" : {
176+ "responses" : {
177+ "200" : {
178+ "description" : " OK"
179+ },
180+ "400" : {
181+ "description" : " Bad Request"
182+ }
183+ },
184+ "security" : [
185+ {
186+ "apiKeyScheme" : [],
187+ "httpBearer" : []
188+ },
189+ {
190+ "apiKeyScheme" : [],
191+ "apiKeySignature" : []
192+ }
193+ ]
194+ }
195+ },
174196 "/unknown-auth-type" : {
175197 "post" : {
176198 "operationId" : " unknownAuthType" ,
225247 }
226248 }
227249 },
250+ "httpBearer" : {
251+ "type" : " http" ,
252+ "scheme" : " bearer"
253+ },
228254 "apiKeyScheme" : {
229255 "type" : " apiKey" ,
230256 "name" : " testKey" ,
231257 "in" : " header"
232258 },
259+ "apiKeySignature" : {
260+ "type" : " apiKey" ,
261+ "name" : " X-AUTH-SIGNATURE" ,
262+ "in" : " header"
263+ },
233264 "unknownAuthType" : {
234265 "type" : " demigorgon" ,
235266 "name" : " eleven" ,
Original file line number Diff line number Diff line change @@ -236,6 +236,13 @@ describe('#prepareSecurity()', () => {
236236 expect ( operation . prepareSecurity ( ) . Header ) . toHaveLength ( 1 ) ;
237237 } ) ;
238238
239+ it ( 'should dedupe securities in within an && and || situation' , ( ) => {
240+ const operation = new Oas ( multipleSecurities ) . operation ( '/multiple-combo-auths-duped' , 'get' ) ;
241+
242+ expect ( operation . prepareSecurity ( ) . Bearer ) . toHaveLength ( 1 ) ;
243+ expect ( operation . prepareSecurity ( ) . Header ) . toHaveLength ( 2 ) ;
244+ } ) ;
245+
239246 it . todo ( 'should set a `key` property' ) ;
240247
241248 it . todo ( 'should throw if attempting to use a non-existent scheme' ) ;
Original file line number Diff line number Diff line change 1+ /* eslint-disable no-underscore-dangle */
12const findSchemaDefinition = require ( './lib/find-schema-definition' ) ;
23
34class Operation {
@@ -65,7 +66,6 @@ class Operation {
6566 return false ;
6667 }
6768
68- // eslint-disable-next-line no-underscore-dangle
6969 security . _key = key ;
7070
7171 return { type, security } ;
@@ -76,7 +76,12 @@ class Operation {
7676 // Remove non-existent schemes
7777 if ( ! security ) return ;
7878 if ( ! prev [ security . type ] ) prev [ security . type ] = [ ] ;
79- prev [ security . type ] . push ( security . security ) ;
79+
80+ // Only add schemes we haven't seen yet.
81+ const exists = prev [ security . type ] . findIndex ( sec => sec . _key === security . security . _key ) ;
82+ if ( exists < 0 ) {
83+ prev [ security . type ] . push ( security . security ) ;
84+ }
8085 } ) ;
8186 return prev ;
8287 } , { } ) ;
You can’t perform that action at this time.
0 commit comments