This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3, feature: Initial swagger -> ast conversion for security definitions
- Loading branch information
1 parent
5b51d0f
commit 995046f
Showing
11 changed files
with
75 additions
and
22 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
44 changes: 44 additions & 0 deletions
44
compiler/src/main/scala/de/zalando/swagger/SecurityConverter.scala
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,44 @@ | ||
package de.zalando.swagger | ||
|
||
import java.net.URL | ||
|
||
import de.zalando.apifirst.Application.SecurityDefinitionsTable | ||
import de.zalando.apifirst.{ParameterPlace, Security} | ||
import de.zalando.swagger.strictModel._ | ||
|
||
/** | ||
* @author slasch | ||
* @since 05.03.2016 | ||
*/ | ||
object SecurityConverter { | ||
|
||
def convertDefinitions(swaggerDefinitions: SecurityDefinitions): SecurityDefinitionsTable = | ||
if (swaggerDefinitions == null) Map.empty | ||
else swaggerDefinitions.collect { | ||
case (name, basic: BasicAuthenticationSecurity) => | ||
name -> Security.Basic(Option(basic.description)) | ||
case (name, apiKey: ApiKeySecurity) => | ||
require(apiKey.name != null && apiKey.name.nonEmpty) | ||
require(apiKey.in != null && apiKey.in.nonEmpty) | ||
val place = ParameterPlace.withName(apiKey.in.toLowerCase) | ||
require(place == ParameterPlace.HEADER || place == ParameterPlace.QUERY) | ||
name -> Security.ApiKey(Option(apiKey.description), apiKey.name, place) | ||
case (name, oauth: Oauth2ImplicitSecurity) => | ||
val authorizationUrl = new URL(oauth.authorizationUrl) | ||
name -> Security.OAuth2Implicit(Option(oauth.description), authorizationUrl, oauth.scopes) | ||
case (name, oauth: Oauth2PasswordSecurity) => | ||
val tokenUrl = new URL(oauth.tokenUrl) | ||
name -> Security.OAuth2Password(Option(oauth.description), tokenUrl, oauth.scopes) | ||
case (name, oauth: Oauth2ApplicationSecurity) => | ||
val tokenUrl = new URL(oauth.tokenUrl) | ||
name -> Security.OAuth2Application(Option(oauth.description), tokenUrl, oauth.scopes) | ||
case (name, oauth: Oauth2AccessCodeSecurity) => | ||
val authorizationUrl = new URL(oauth.authorizationUrl) | ||
val tokenUrl = new URL(oauth.tokenUrl) | ||
name -> Security.OAuth2AccessCode(Option(oauth.description), authorizationUrl, tokenUrl, oauth.scopes) | ||
} | ||
} | ||
|
||
|
||
|
||
|
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
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