-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
440 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Given a block of security data, either return the key, if there are no scopes, | ||
* or return the sorted, joined up scopes. | ||
* | ||
* From the official docs | ||
* > `security` is an array of hashmaps, where each hashmap contains | ||
* > one or more named security schemes. | ||
* | ||
* @param security — The array of security blocks | ||
* @return the key if there are no scopes, or | ||
* the joined up sorted scopes if there are scopes, or | ||
* undefined if the array of blocks is empty | ||
*/ | ||
const keyOrScopes = ([data]) => { | ||
if (!data) return // there is no security | ||
const [key] = Object.keys(data) // we only care about the first key | ||
const scopes = data[key] // there must be at least one key | ||
if (!scopes.length) return key // if there are no scopes use the key instead | ||
return scopes.sort().join(',') | ||
} | ||
|
||
module.exports = keyOrScopes | ||
|
||
/* | ||
security: [] | ||
=> undefined | ||
security: | ||
- someKey: [] | ||
=> someKey | ||
security: | ||
- someKey: | ||
- scope1 | ||
- scope2 | ||
=> scope1,scope2 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const keyOrScopes = require('./keyOrScopes') | ||
|
||
/** | ||
* Maps the supplied security block (if any) to a simple string representation | ||
* that can in turn be used as a key for the appropriate security middleware. | ||
* | ||
* Refs: | ||
* - V2 https://swagger.io/docs/specification/2-0/authentication | ||
* - V3 https://swagger.io/docs/specification/authentication | ||
* | ||
* @param security — A swagger security block | ||
* @param globalSecurity — A previously computed global security key. | ||
* @return a string representation used as a key for the appropriate security middleware. | ||
*/ | ||
const normaliseSecurity = (security, globalSecurity) => | ||
security ? keyOrScopes(security) : globalSecurity | ||
|
||
module.exports = normaliseSecurity |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.