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, refactor: Extracted specification-related part from security trait
- Loading branch information
1 parent
2c97099
commit 8ebb31f
Showing
15 changed files
with
270 additions
and
412 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
38 changes: 38 additions & 0 deletions
38
compiler/src/main/scala/de/zalando/apifirst/generators/SecurityStep.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,38 @@ | ||
package de.zalando.apifirst.generators | ||
|
||
import de.zalando.apifirst.Application.StrictModel | ||
import de.zalando.apifirst.generators.DenotationNames._ | ||
import de.zalando.apifirst.{Security, ParameterPlace, ScalaName} | ||
import de.zalando.play.controllers.WriterFactories | ||
|
||
import scala.ref.WeakReference | ||
|
||
/** | ||
* @author slasch | ||
* @since 07.03.2016 | ||
*/ | ||
trait SecurityStep extends EnrichmentStep[StrictModel] with SecurityCommons { | ||
|
||
override def steps = security +: super.steps | ||
|
||
/** | ||
* Puts security related information into the denotation table | ||
* | ||
* @return | ||
*/ | ||
protected val security: SingleStep = spec => table => { | ||
val extractors: Iterable[Map[String, String]] = spec._2.securityDefinitionsTable.map { case (name, definition) => | ||
Map("name" -> securityCheck(name)) | ||
} | ||
if (extractors.isEmpty) Map.empty | ||
else Map("security_extractors" -> Map("extractors" -> extractors)) | ||
} | ||
} | ||
|
||
trait SecurityCommons { | ||
def securityCheck(name: String) = | ||
ScalaName.escape(name + "_Extractor") | ||
|
||
def securityName(suffix: String, security: Security.Constraint*): String = | ||
security.map(_.name).mkString("", "_", "_"+suffix) | ||
} |
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
Oops, something went wrong.