diff --git a/compiler/src/main/resources/play_scala_controller_security.mustache b/compiler/src/main/resources/play_scala_controller_security.mustache index 36aaae8..61e12a6 100644 --- a/compiler/src/main/resources/play_scala_controller_security.mustache +++ b/compiler/src/main/resources/play_scala_controller_security.mustache @@ -7,28 +7,29 @@ import de.zalando.play.controllers.PlayBodyParsing import {{import.name}} {{/for}} +trait SecurityExtractors { +{{for extractor in security_extractors.extractors}} + def {{extractor.name}}[User >: Any](header: RequestHeader): Option[User] = ??? +{{/for}} + +} + {{for controller in controllers}} -trait {{controller.security_trait}} { +trait {{controller.security_trait}} extends SecurityExtractors { val unauthorizedContent = ??? val mimeType: String = ??? - {{for m in controller.methods}} - {{if m.needs_security}} - {{for security_check in m.security_checks}} - def {{security_check.name}}[User >: Any](header: RequestHeader): Option[User] = ??? - {{/for}} - - val {{m.secure_checks}} = Seq({{for security_check in m.security_checks}}{{security_check.name}} _{{if security_check.isNotLast}}, {{/if}}{{/for}}) + {{for m in controller.methods}}{{if m.needs_security}} object {{m.secure_action}} extends AuthenticatedBuilder( req => { - val individualChecks = {{m.secure_checks}}.map(_.apply(req)) + val secureChecks = Seq({{for security_check in m.security_checks}}{{security_check.name}} _{{if security_check.isNotLast}}, {{/if}}{{/for}}) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - {{/if}} - {{/for}} + {{/if}}{{/for}} private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => { implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType) diff --git a/compiler/src/main/scala/de/zalando/apifirst/generators/AstScalaPlayEnricher.scala b/compiler/src/main/scala/de/zalando/apifirst/generators/AstScalaPlayEnricher.scala index 120205d..166093b 100644 --- a/compiler/src/main/scala/de/zalando/apifirst/generators/AstScalaPlayEnricher.scala +++ b/compiler/src/main/scala/de/zalando/apifirst/generators/AstScalaPlayEnricher.scala @@ -66,7 +66,8 @@ class ScalaPlayTypeEnricher(val app: StrictModel) extends Transformation[Type] w /** * Enriches AST with information related to the specification as whole */ -class ScalaPlaySpecEnricher(val app: StrictModel) extends Transformation[StrictModel] with MarshallersStep { +class ScalaPlaySpecEnricher(val app: StrictModel) extends Transformation[StrictModel] + with MarshallersStep with SecurityStep { override def data = Seq(Reference.root -> app) diff --git a/compiler/src/main/scala/de/zalando/apifirst/generators/SecurityStep.scala b/compiler/src/main/scala/de/zalando/apifirst/generators/SecurityStep.scala new file mode 100644 index 0000000..b02d97b --- /dev/null +++ b/compiler/src/main/scala/de/zalando/apifirst/generators/SecurityStep.scala @@ -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) +} \ No newline at end of file diff --git a/compiler/src/main/scala/de/zalando/apifirst/generators/controllersStep.scala b/compiler/src/main/scala/de/zalando/apifirst/generators/controllersStep.scala index 61b9e04..95241ea 100644 --- a/compiler/src/main/scala/de/zalando/apifirst/generators/controllersStep.scala +++ b/compiler/src/main/scala/de/zalando/apifirst/generators/controllersStep.scala @@ -2,7 +2,7 @@ package de.zalando.apifirst.generators import de.zalando.apifirst.Application.{ApiCall, Parameter, ParameterRef} import de.zalando.apifirst.Domain._ -import de.zalando.apifirst.{Security, ScalaName, Http, ParameterPlace} +import de.zalando.apifirst.{Http, ParameterPlace} import de.zalando.apifirst.ScalaName._ import de.zalando.apifirst.generators.DenotationNames._ import de.zalando.apifirst.naming.Reference @@ -12,7 +12,7 @@ import de.zalando.play.controllers.WriterFactories * @author slasch * @since 31.12.2015. */ -trait CallControllersStep extends EnrichmentStep[ApiCall] with ControllersCommons { +trait CallControllersStep extends EnrichmentStep[ApiCall] with ControllersCommons with SecurityCommons { override def steps = controllers +: super.steps @@ -83,18 +83,10 @@ trait CallControllersStep extends EnrichmentStep[ApiCall] with ControllersCommon private def securityData(call: ApiCall)(implicit table: DenotationTable): Map[String, Any] = Map( "needs_security" -> call.security.nonEmpty, - "secure_action" -> securityName(call.security, "Action"), - "secure_checks" -> securityName(call.security, "Checks"), - "security_checks" -> call.security.map(securityCheck) + "secure_action" -> nameWithSuffix(call, "SecureAction"), + "security_checks" -> call.security.map(s => Map("name" -> securityCheck(s.name))) ) - private def securityCheck(constraint: Security.Constraint): Map[String, Any] = Map( - "name" -> securityName(Set(constraint), "Extractor") - ) - - private def securityName(security: Set[Security.Constraint], suffix: String): String = - security.map(_.name).mkString("", "_", "_"+suffix) - private def needsCustom(mimeTypes: Set[Http.MimeType]): Boolean = mimeTypes.map(_.name).diff(WriterFactories.factories.keySet).nonEmpty diff --git a/compiler/src/main/scala/de/zalando/apifirst/generators/playScala.scala b/compiler/src/main/scala/de/zalando/apifirst/generators/playScala.scala index 6680ffe..1026cf9 100644 --- a/compiler/src/main/scala/de/zalando/apifirst/generators/playScala.scala +++ b/compiler/src/main/scala/de/zalando/apifirst/generators/playScala.scala @@ -106,6 +106,9 @@ class ScalaGenerator(val strictModel: StrictModel) extends PlayScalaControllerAn val unmarshallers = ReShaper.filterByType("unmarshallers", denotationTable) val grouppedunMarshallers = ReShaper.groupByType(unmarshallers.toSeq).toMap + val securityExtractors = ReShaper.filterByType("security_extractors", denotationTable) + val extractors = ReShaper.groupByType(securityExtractors.toSeq).toMap + val (unmanagedParts: Map[ApiCall, UnmanagedPart], unmanagedImports: Seq[String]) = analyzeController(currentController, denotationTable) @@ -126,6 +129,7 @@ class ScalaGenerator(val strictModel: StrictModel) extends PlayScalaControllerAn "unmanaged_imports" -> unmanagedImports.map(i => Map("name" -> i)) ) + val securityChecks = ReShaper.groupByType(controllersList.toSeq).toMap val singlePackage = Map( "classes" -> ReShaper.filterByType("classes", denotationTable), @@ -136,6 +140,7 @@ class ScalaGenerator(val strictModel: StrictModel) extends PlayScalaControllerAn "tests" -> ReShaper.filterByType("tests", denotationTable), "marshallers" -> grouppedMarshallers, "unmarshallers" -> grouppedunMarshallers, + "security_extractors" -> extractors, "bindings" -> bindingsByType ) diff --git a/compiler/src/test/resources/expected_results/controllers/basic.auth.api.yaml.base.scala b/compiler/src/test/resources/expected_results/controllers/basic.auth.api.yaml.base.scala index 4e22ce4..0f551f3 100644 --- a/compiler/src/test/resources/expected_results/controllers/basic.auth.api.yaml.base.scala +++ b/compiler/src/test/resources/expected_results/controllers/basic.auth.api.yaml.base.scala @@ -10,7 +10,6 @@ import scala.util._ - trait BasicAuthApiYamlBase extends Controller with PlayBodyParsing with BasicAuthApiYamlSecurity { private type getActionRequestType = (Unit) private type getActionType = getActionRequestType => Try[(Int, Any)] @@ -18,7 +17,7 @@ trait BasicAuthApiYamlBase extends Controller with PlayBodyParsing with BasicAu private val errorToStatusget: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getAction = (f: getActionType) => basicAuth_Action { request => + def getAction = (f: getActionType) => getSecureAction { request => val providedTypes = Seq[String]() negotiateContent(request.acceptedTypes, providedTypes).map { getResponseMimeType => diff --git a/compiler/src/test/resources/expected_results/controllers/full.petstore.api.yaml.base.scala b/compiler/src/test/resources/expected_results/controllers/full.petstore.api.yaml.base.scala index 8943a5a..2e1b098 100644 --- a/compiler/src/test/resources/expected_results/controllers/full.petstore.api.yaml.base.scala +++ b/compiler/src/test/resources/expected_results/controllers/full.petstore.api.yaml.base.scala @@ -14,7 +14,6 @@ import de.zalando.play.controllers.PlayPathBindables - trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with FullPetstoreApiYamlSecurity { private type findPetsByTagsActionRequestType = (PetsFindByStatusGetStatus) private type findPetsByTagsActionType = findPetsByTagsActionRequestType => Try[(Int, Any)] @@ -26,7 +25,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full } - def findPetsByTagsAction = (f: findPetsByTagsActionType) => (tags: PetsFindByStatusGetStatus) => petstore_auth_Action { request => + def findPetsByTagsAction = (f: findPetsByTagsActionType) => (tags: PetsFindByStatusGetStatus) => findPetsByTagsSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { findPetsByTagsResponseMimeType => @@ -458,7 +457,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full optionParser[Pet](bodyMimeType, customParsers, "Invalid PetsPostBody", maxLength) } - def updatePetAction = (f: updatePetActionType) => petstore_auth_Action(updatePetParser(Seq[String]("application/json", "application/xml"))) { request => + def updatePetAction = (f: updatePetActionType) => updatePetSecureAction(updatePetParser(Seq[String]("application/json", "application/xml"))) { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { updatePetResponseMimeType => @@ -525,7 +524,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full optionParser[Pet](bodyMimeType, customParsers, "Invalid PetsPostBody", maxLength) } - def addPetAction = (f: addPetActionType) => petstore_auth_Action(addPetParser(Seq[String]("application/json", "application/xml"))) { request => + def addPetAction = (f: addPetActionType) => addPetSecureAction(addPetParser(Seq[String]("application/json", "application/xml"))) { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { addPetResponseMimeType => @@ -789,7 +788,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full } - def getPetByIdAction = (f: getPetByIdActionType) => (petId: Long) => api_key_petstore_auth_Action { request => + def getPetByIdAction = (f: getPetByIdActionType) => (petId: Long) => getPetByIdSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { getPetByIdResponseMimeType => @@ -842,7 +841,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full } - def updatePetWithFormAction = (f: updatePetWithFormActionType) => (petId: String, name: String, status: String) => petstore_auth_Action { request => + def updatePetWithFormAction = (f: updatePetWithFormActionType) => (petId: String, name: String, status: String) => updatePetWithFormSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { updatePetWithFormResponseMimeType => @@ -893,7 +892,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full } - def deletePetAction = (f: deletePetActionType) => (petId: Long) => petstore_auth_Action { request => + def deletePetAction = (f: deletePetActionType) => (petId: Long) => deletePetSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { deletePetResponseMimeType => @@ -953,7 +952,7 @@ trait FullPetstoreApiYamlBase extends Controller with PlayBodyParsing with Full } - def findPetsByStatusAction = (f: findPetsByStatusActionType) => (status: PetsFindByStatusGetStatus) => petstore_auth_Action { request => + def findPetsByStatusAction = (f: findPetsByStatusActionType) => (status: PetsFindByStatusGetStatus) => findPetsByStatusSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { findPetsByStatusResponseMimeType => diff --git a/compiler/src/test/resources/expected_results/controllers/instagram.api.yaml.base.scala b/compiler/src/test/resources/expected_results/controllers/instagram.api.yaml.base.scala index 9e9baeb..37652d5 100644 --- a/compiler/src/test/resources/expected_results/controllers/instagram.api.yaml.base.scala +++ b/compiler/src/test/resources/expected_results/controllers/instagram.api.yaml.base.scala @@ -12,7 +12,6 @@ import de.zalando.play.controllers.PlayPathBindables - trait InstagramApiYamlBase extends Controller with PlayBodyParsing with InstagramApiYamlSecurity { private type getmediaByMedia_idLikesActionRequestType = (Int) private type getmediaByMedia_idLikesActionType = getmediaByMedia_idLikesActionRequestType => Try[(Int, Any)] @@ -20,7 +19,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetmediaByMedia_idLikes: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getmediaByMedia_idLikesAction = (f: getmediaByMedia_idLikesActionType) => (media_id: Int) => oauth_key_Action { request => + def getmediaByMedia_idLikesAction = (f: getmediaByMedia_idLikesActionType) => (media_id: Int) => getmediaByMedia_idLikesSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getmediaByMedia_idLikesResponseMimeType => @@ -67,7 +66,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatuspostmediaByMedia_idLikes: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def postmediaByMedia_idLikesAction = (f: postmediaByMedia_idLikesActionType) => (media_id: Int) => oauth_Action { request => + def postmediaByMedia_idLikesAction = (f: postmediaByMedia_idLikesActionType) => (media_id: Int) => postmediaByMedia_idLikesSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { postmediaByMedia_idLikesResponseMimeType => @@ -114,7 +113,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusdeletemediaByMedia_idLikes: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def deletemediaByMedia_idLikesAction = (f: deletemediaByMedia_idLikesActionType) => (media_id: Int) => oauth_key_Action { request => + def deletemediaByMedia_idLikesAction = (f: deletemediaByMedia_idLikesActionType) => (media_id: Int) => deletemediaByMedia_idLikesSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { deletemediaByMedia_idLikesResponseMimeType => @@ -161,7 +160,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersByUser_idFollows: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersByUser_idFollowsAction = (f: getusersByUser_idFollowsActionType) => (user_id: Double) => oauth_key_Action { request => + def getusersByUser_idFollowsAction = (f: getusersByUser_idFollowsActionType) => (user_id: Double) => getusersByUser_idFollowsSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersByUser_idFollowsResponseMimeType => @@ -208,7 +207,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetlocationsByLocation_id: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getlocationsByLocation_idAction = (f: getlocationsByLocation_idActionType) => (location_id: Int) => oauth_key_Action { request => + def getlocationsByLocation_idAction = (f: getlocationsByLocation_idActionType) => (location_id: Int) => getlocationsByLocation_idSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getlocationsByLocation_idResponseMimeType => @@ -255,7 +254,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersSearch: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersSearchAction = (f: getusersSearchActionType) => (q: String, count: MediaFilter) => oauth_key_Action { request => + def getusersSearchAction = (f: getusersSearchActionType) => (q: String, count: MediaFilter) => getusersSearchSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersSearchResponseMimeType => @@ -302,7 +301,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersSelfMediaLiked: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersSelfMediaLikedAction = (f: getusersSelfMediaLikedActionType) => (count: MediaId, max_like_id: MediaId) => oauth_key_Action { request => + def getusersSelfMediaLikedAction = (f: getusersSelfMediaLikedActionType) => (count: MediaId, max_like_id: MediaId) => getusersSelfMediaLikedSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersSelfMediaLikedResponseMimeType => @@ -349,7 +348,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgettagsByTag_name: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def gettagsByTag_nameAction = (f: gettagsByTag_nameActionType) => (tag_name: String) => oauth_key_Action { request => + def gettagsByTag_nameAction = (f: gettagsByTag_nameActionType) => (tag_name: String) => gettagsByTag_nameSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { gettagsByTag_nameResponseMimeType => @@ -396,7 +395,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgettagsSearch: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def gettagsSearchAction = (f: gettagsSearchActionType) => (q: MediaFilter) => oauth_key_Action { request => + def gettagsSearchAction = (f: gettagsSearchActionType) => (q: MediaFilter) => gettagsSearchSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { gettagsSearchResponseMimeType => @@ -443,7 +442,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersByUser_idFollowed_by: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersByUser_idFollowed_byAction = (f: getusersByUser_idFollowed_byActionType) => (user_id: Double) => oauth_key_Action { request => + def getusersByUser_idFollowed_byAction = (f: getusersByUser_idFollowed_byActionType) => (user_id: Double) => getusersByUser_idFollowed_bySecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersByUser_idFollowed_byResponseMimeType => @@ -490,7 +489,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetmediaByMedia_idComments: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getmediaByMedia_idCommentsAction = (f: getmediaByMedia_idCommentsActionType) => (media_id: Int) => oauth_key_Action { request => + def getmediaByMedia_idCommentsAction = (f: getmediaByMedia_idCommentsActionType) => (media_id: Int) => getmediaByMedia_idCommentsSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getmediaByMedia_idCommentsResponseMimeType => @@ -551,7 +550,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr optionParser[Double](bodyMimeType, customParsers, "Invalid LocationLatitude", maxLength) } - def postmediaByMedia_idCommentsAction = (f: postmediaByMedia_idCommentsActionType) => (media_id: Int) => oauth_Action(postmediaByMedia_idCommentsParser(Seq[String]("application/json"))) { request => + def postmediaByMedia_idCommentsAction = (f: postmediaByMedia_idCommentsActionType) => (media_id: Int) => postmediaByMedia_idCommentsSecureAction(postmediaByMedia_idCommentsParser(Seq[String]("application/json"))) { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { postmediaByMedia_idCommentsResponseMimeType => @@ -599,7 +598,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusdeletemediaByMedia_idComments: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def deletemediaByMedia_idCommentsAction = (f: deletemediaByMedia_idCommentsActionType) => (media_id: Int) => oauth_key_Action { request => + def deletemediaByMedia_idCommentsAction = (f: deletemediaByMedia_idCommentsActionType) => (media_id: Int) => deletemediaByMedia_idCommentsSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { deletemediaByMedia_idCommentsResponseMimeType => @@ -646,7 +645,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgettagsByTag_nameMediaRecent: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def gettagsByTag_nameMediaRecentAction = (f: gettagsByTag_nameMediaRecentActionType) => (tag_name: String) => oauth_key_Action { request => + def gettagsByTag_nameMediaRecentAction = (f: gettagsByTag_nameMediaRecentActionType) => (tag_name: String) => gettagsByTag_nameMediaRecentSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { gettagsByTag_nameMediaRecentResponseMimeType => @@ -707,7 +706,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr optionParser[String](bodyMimeType, customParsers, "Invalid MediaFilter", maxLength) } - def postusersByUser_idRelationshipAction = (f: postusersByUser_idRelationshipActionType) => (user_id: Double) => oauth_Action(postusersByUser_idRelationshipParser(Seq[String]("application/json"))) { request => + def postusersByUser_idRelationshipAction = (f: postusersByUser_idRelationshipActionType) => (user_id: Double) => postusersByUser_idRelationshipSecureAction(postusersByUser_idRelationshipParser(Seq[String]("application/json"))) { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { postusersByUser_idRelationshipResponseMimeType => @@ -755,7 +754,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersSelfFeed: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersSelfFeedAction = (f: getusersSelfFeedActionType) => (count: MediaId, max_id: MediaId, min_id: MediaId) => oauth_key_Action { request => + def getusersSelfFeedAction = (f: getusersSelfFeedActionType) => (count: MediaId, max_id: MediaId, min_id: MediaId) => getusersSelfFeedSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersSelfFeedResponseMimeType => @@ -802,7 +801,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersByUser_id: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersByUser_idAction = (f: getusersByUser_idActionType) => (user_id: Double) => key_oauth_Action { request => + def getusersByUser_idAction = (f: getusersByUser_idActionType) => (user_id: Double) => getusersByUser_idSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersByUser_idResponseMimeType => @@ -849,7 +848,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetmediaSearch: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getmediaSearchAction = (f: getmediaSearchActionType) => (mAX_TIMESTAMP: MediaId, dISTANCE: Int, lNG: LocationLatitude, mIN_TIMESTAMP: MediaId, lAT: LocationLatitude) => oauth_key_Action { request => + def getmediaSearchAction = (f: getmediaSearchActionType) => (mAX_TIMESTAMP: MediaId, dISTANCE: Int, lNG: LocationLatitude, mIN_TIMESTAMP: MediaId, lAT: LocationLatitude) => getmediaSearchSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getmediaSearchResponseMimeType => @@ -896,7 +895,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetgeographiesByGeo_idMediaRecent: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getgeographiesByGeo_idMediaRecentAction = (f: getgeographiesByGeo_idMediaRecentActionType) => (geo_id: Int, count: MediaId, min_id: MediaId) => oauth_key_Action { request => + def getgeographiesByGeo_idMediaRecentAction = (f: getgeographiesByGeo_idMediaRecentActionType) => (geo_id: Int, count: MediaId, min_id: MediaId) => getgeographiesByGeo_idMediaRecentSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getgeographiesByGeo_idMediaRecentResponseMimeType => @@ -943,7 +942,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetmediaByShortcode: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getmediaByShortcodeAction = (f: getmediaByShortcodeActionType) => (shortcode: String) => oauth_key_Action { request => + def getmediaByShortcodeAction = (f: getmediaByShortcodeActionType) => (shortcode: String) => getmediaByShortcodeSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getmediaByShortcodeResponseMimeType => @@ -990,7 +989,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetlocationsSearch: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getlocationsSearchAction = (f: getlocationsSearchActionType) => (foursquare_v2_id: MediaId, facebook_places_id: MediaId, distance: MediaId, lat: LocationLatitude, foursquare_id: MediaId, lng: LocationLatitude) => oauth_key_Action { request => + def getlocationsSearchAction = (f: getlocationsSearchActionType) => (foursquare_v2_id: MediaId, facebook_places_id: MediaId, distance: MediaId, lat: LocationLatitude, foursquare_id: MediaId, lng: LocationLatitude) => getlocationsSearchSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getlocationsSearchResponseMimeType => @@ -1037,7 +1036,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersSelfRequested_by: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersSelfRequested_byAction = (f: getusersSelfRequested_byActionType) => oauth_key_Action { request => + def getusersSelfRequested_byAction = (f: getusersSelfRequested_byActionType) => getusersSelfRequested_bySecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersSelfRequested_byResponseMimeType => @@ -1078,7 +1077,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetmediaByMedia_id: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getmediaByMedia_idAction = (f: getmediaByMedia_idActionType) => (media_id: Int) => oauth_key_Action { request => + def getmediaByMedia_idAction = (f: getmediaByMedia_idActionType) => (media_id: Int) => getmediaByMedia_idSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getmediaByMedia_idResponseMimeType => @@ -1125,7 +1124,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetlocationsByLocation_idMediaRecent: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getlocationsByLocation_idMediaRecentAction = (f: getlocationsByLocation_idMediaRecentActionType) => (location_id: Int, max_timestamp: MediaId, min_timestamp: MediaId, min_id: MediaFilter, max_id: MediaFilter) => oauth_key_Action { request => + def getlocationsByLocation_idMediaRecentAction = (f: getlocationsByLocation_idMediaRecentActionType) => (location_id: Int, max_timestamp: MediaId, min_timestamp: MediaId, min_id: MediaFilter, max_id: MediaFilter) => getlocationsByLocation_idMediaRecentSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getlocationsByLocation_idMediaRecentResponseMimeType => @@ -1172,7 +1171,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetusersByUser_idMediaRecent: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getusersByUser_idMediaRecentAction = (f: getusersByUser_idMediaRecentActionType) => (user_id: Double, max_timestamp: MediaId, min_id: MediaFilter, min_timestamp: MediaId, max_id: MediaFilter, count: MediaId) => oauth_key_Action { request => + def getusersByUser_idMediaRecentAction = (f: getusersByUser_idMediaRecentActionType) => (user_id: Double, max_timestamp: MediaId, min_id: MediaFilter, min_timestamp: MediaId, max_id: MediaFilter, count: MediaId) => getusersByUser_idMediaRecentSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getusersByUser_idMediaRecentResponseMimeType => @@ -1219,7 +1218,7 @@ trait InstagramApiYamlBase extends Controller with PlayBodyParsing with Instagr private val errorToStatusgetmediaPopular: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getmediaPopularAction = (f: getmediaPopularActionType) => oauth_key_Action { request => + def getmediaPopularAction = (f: getmediaPopularActionType) => getmediaPopularSecureAction { request => val providedTypes = Seq[String]("application/json") negotiateContent(request.acceptedTypes, providedTypes).map { getmediaPopularResponseMimeType => diff --git a/compiler/src/test/resources/expected_results/controllers/security.api.yaml.base.scala b/compiler/src/test/resources/expected_results/controllers/security.api.yaml.base.scala index 2ad7486..4effc81 100644 --- a/compiler/src/test/resources/expected_results/controllers/security.api.yaml.base.scala +++ b/compiler/src/test/resources/expected_results/controllers/security.api.yaml.base.scala @@ -13,7 +13,6 @@ import de.zalando.play.controllers.PlayPathBindables - trait SecurityApiYamlBase extends Controller with PlayBodyParsing with SecurityApiYamlSecurity { private type getPetsByIdActionRequestType = (PetsIdGetId) private type getPetsByIdActionType = getPetsByIdActionRequestType => Try[(Int, Any)] @@ -21,7 +20,7 @@ trait SecurityApiYamlBase extends Controller with PlayBodyParsing with Security private val errorToStatusgetPetsById: PartialFunction[Throwable, Status] = PartialFunction.empty[Throwable, Status] - def getPetsByIdAction = (f: getPetsByIdActionType) => (id: PetsIdGetId) => githubAccessCode_internalApiKey_Action { request => + def getPetsByIdAction = (f: getPetsByIdActionType) => (id: PetsIdGetId) => getPetsByIdSecureAction { request => val providedTypes = Seq[String]("application/json", "text/html") negotiateContent(request.acceptedTypes, providedTypes).map { getPetsByIdResponseMimeType => diff --git a/compiler/src/test/resources/expected_results/controllers/split.petstore.api.yaml.base.scala b/compiler/src/test/resources/expected_results/controllers/split.petstore.api.yaml.base.scala index 98199e1..567973e 100644 --- a/compiler/src/test/resources/expected_results/controllers/split.petstore.api.yaml.base.scala +++ b/compiler/src/test/resources/expected_results/controllers/split.petstore.api.yaml.base.scala @@ -25,7 +25,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl } - def findPetsByTagsAction = (f: findPetsByTagsActionType) => (tags: PetsFindByStatusGetStatus) => petstore_auth_Action { request => + def findPetsByTagsAction = (f: findPetsByTagsActionType) => (tags: PetsFindByStatusGetStatus) => findPetsByTagsSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { findPetsByTagsResponseMimeType => @@ -457,7 +457,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl optionParser[Pet](bodyMimeType, customParsers, "Invalid PetsPostBody", maxLength) } - def updatePetAction = (f: updatePetActionType) => petstore_auth_Action(updatePetParser(Seq[String]("application/json", "application/xml"))) { request => + def updatePetAction = (f: updatePetActionType) => updatePetSecureAction(updatePetParser(Seq[String]("application/json", "application/xml"))) { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { updatePetResponseMimeType => @@ -524,7 +524,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl optionParser[Pet](bodyMimeType, customParsers, "Invalid PetsPostBody", maxLength) } - def addPetAction = (f: addPetActionType) => petstore_auth_Action(addPetParser(Seq[String]("application/json", "application/xml"))) { request => + def addPetAction = (f: addPetActionType) => addPetSecureAction(addPetParser(Seq[String]("application/json", "application/xml"))) { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { addPetResponseMimeType => @@ -788,7 +788,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl } - def getPetByIdAction = (f: getPetByIdActionType) => (petId: Long) => api_key_petstore_auth_Action { request => + def getPetByIdAction = (f: getPetByIdActionType) => (petId: Long) => getPetByIdSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { getPetByIdResponseMimeType => @@ -841,7 +841,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl } - def updatePetWithFormAction = (f: updatePetWithFormActionType) => (petId: String, name: String, status: String) => petstore_auth_Action { request => + def updatePetWithFormAction = (f: updatePetWithFormActionType) => (petId: String, name: String, status: String) => updatePetWithFormSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { updatePetWithFormResponseMimeType => @@ -892,7 +892,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl } - def deletePetAction = (f: deletePetActionType) => (petId: Long) => petstore_auth_Action { request => + def deletePetAction = (f: deletePetActionType) => (petId: Long) => deletePetSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { deletePetResponseMimeType => @@ -952,7 +952,7 @@ trait SplitPetstoreApiYamlBase extends Controller with PlayBodyParsing with Spl } - def findPetsByStatusAction = (f: findPetsByStatusActionType) => (status: PetsFindByStatusGetStatus) => petstore_auth_Action { request => + def findPetsByStatusAction = (f: findPetsByStatusActionType) => (status: PetsFindByStatusGetStatus) => findPetsByStatusSecureAction { request => val providedTypes = Seq[String]("application/json", "application/xml") negotiateContent(request.acceptedTypes, providedTypes).map { findPetsByStatusResponseMimeType => diff --git a/compiler/src/test/resources/expected_results/security/basic.auth.api.yaml.scala b/compiler/src/test/resources/expected_results/security/basic.auth.api.yaml.scala index 07dcbba..38283b6 100644 --- a/compiler/src/test/resources/expected_results/security/basic.auth.api.yaml.scala +++ b/compiler/src/test/resources/expected_results/security/basic.auth.api.yaml.scala @@ -4,18 +4,21 @@ import play.api.mvc._ import Security.AuthenticatedBuilder import de.zalando.play.controllers.PlayBodyParsing +trait SecurityExtractors { + def basicAuth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + +} + -trait BasicAuthApiYamlSecurity { +trait BasicAuthApiYamlSecurity extends SecurityExtractors { val unauthorizedContent = ??? val mimeType: String = ??? - - def basicAuth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - val basicAuth_Checks = Seq(basicAuth_Extractor _) - - object basicAuth_Action extends AuthenticatedBuilder( + + object getSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = basicAuth_Checks.map(_.apply(req)) + val secureChecks = Seq(basicAuth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) diff --git a/compiler/src/test/resources/expected_results/security/full.petstore.api.yaml.scala b/compiler/src/test/resources/expected_results/security/full.petstore.api.yaml.scala index 6abe17a..3edf5e2 100644 --- a/compiler/src/test/resources/expected_results/security/full.petstore.api.yaml.scala +++ b/compiler/src/test/resources/expected_results/security/full.petstore.api.yaml.scala @@ -6,113 +6,81 @@ import de.zalando.play.controllers.PlayBodyParsing import de.zalando.play.controllers.ArrayWrapper import org.joda.time.DateTime +trait SecurityExtractors { + def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + +} + -trait FullPetstoreApiYamlSecurity { +trait FullPetstoreApiYamlSecurity extends SecurityExtractors { val unauthorizedContent = ??? val mimeType: String = ??? - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - object petstore_auth_Action extends AuthenticatedBuilder( + + object findPetsByTagsSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - - - - - - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object updatePetSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object addPetSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - - - - - def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val api_key_petstore_auth_Checks = Seq(api_key_Extractor _, petstore_auth_Extractor _) - - object api_key_petstore_auth_Action extends AuthenticatedBuilder( + object getPetByIdSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = api_key_petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(api_key_Extractor _, petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object updatePetWithFormSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object deletePetSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object findPetsByStatusSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => { implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType) diff --git a/compiler/src/test/resources/expected_results/security/instagram.api.yaml.scala b/compiler/src/test/resources/expected_results/security/instagram.api.yaml.scala index a07ce52..70c4daf 100644 --- a/compiler/src/test/resources/expected_results/security/instagram.api.yaml.scala +++ b/compiler/src/test/resources/expected_results/security/instagram.api.yaml.scala @@ -4,366 +4,247 @@ import play.api.mvc._ import Security.AuthenticatedBuilder import de.zalando.play.controllers.PlayBodyParsing - -trait InstagramApiYamlSecurity { - val unauthorizedContent = ??? - val mimeType: String = ??? - +trait SecurityExtractors { def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) +} + + +trait InstagramApiYamlSecurity extends SecurityExtractors { + val unauthorizedContent = ??? + val mimeType: String = ??? - object oauth_key_Action extends AuthenticatedBuilder( + + object getmediaByMedia_idLikesSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_Checks = Seq(oauth_Extractor _) - - object oauth_Action extends AuthenticatedBuilder( + object postmediaByMedia_idLikesSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object deletemediaByMedia_idLikesSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersByUser_idFollowsSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getlocationsByLocation_idSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersSearchSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersSelfMediaLikedSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object gettagsByTag_nameSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object gettagsSearchSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersByUser_idFollowed_bySecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getmediaByMedia_idCommentsSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_Checks = Seq(oauth_Extractor _) - - object oauth_Action extends AuthenticatedBuilder( + object postmediaByMedia_idCommentsSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object deletemediaByMedia_idCommentsSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object gettagsByTag_nameMediaRecentSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_Checks = Seq(oauth_Extractor _) - - object oauth_Action extends AuthenticatedBuilder( + object postusersByUser_idRelationshipSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersSelfFeedSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val key_oauth_Checks = Seq(key_Extractor _, oauth_Extractor _) - - object key_oauth_Action extends AuthenticatedBuilder( + object getusersByUser_idSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = key_oauth_Checks.map(_.apply(req)) + val secureChecks = Seq(key_Extractor _, oauth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getmediaSearchSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getgeographiesByGeo_idMediaRecentSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getmediaByShortcodeSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getlocationsSearchSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersSelfRequested_bySecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getmediaByMedia_idSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getlocationsByLocation_idMediaRecentSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getusersByUser_idMediaRecentSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def oauth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val oauth_key_Checks = Seq(oauth_Extractor _, key_Extractor _) - - object oauth_key_Action extends AuthenticatedBuilder( + object getmediaPopularSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = oauth_key_Checks.map(_.apply(req)) + val secureChecks = Seq(oauth_Extractor _, key_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) diff --git a/compiler/src/test/resources/expected_results/security/security.api.yaml.scala b/compiler/src/test/resources/expected_results/security/security.api.yaml.scala index fe7740f..fe59da4 100644 --- a/compiler/src/test/resources/expected_results/security/security.api.yaml.scala +++ b/compiler/src/test/resources/expected_results/security/security.api.yaml.scala @@ -5,19 +5,24 @@ import Security.AuthenticatedBuilder import de.zalando.play.controllers.PlayBodyParsing import de.zalando.play.controllers.ArrayWrapper - -trait SecurityApiYamlSecurity { - val unauthorizedContent = ??? - val mimeType: String = ??? - +trait SecurityExtractors { def githubAccessCode_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + def petstoreImplicit_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? def internalApiKey_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + def justBasicStuff_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + +} - val githubAccessCode_internalApiKey_Checks = Seq(githubAccessCode_Extractor _, internalApiKey_Extractor _) - object githubAccessCode_internalApiKey_Action extends AuthenticatedBuilder( +trait SecurityApiYamlSecurity extends SecurityExtractors { + val unauthorizedContent = ??? + val mimeType: String = ??? + + + object getPetsByIdSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = githubAccessCode_internalApiKey_Checks.map(_.apply(req)) + val secureChecks = Seq(githubAccessCode_Extractor _, internalApiKey_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) diff --git a/compiler/src/test/resources/expected_results/security/split.petstore.api.yaml.scala b/compiler/src/test/resources/expected_results/security/split.petstore.api.yaml.scala index e889a07..1211037 100644 --- a/compiler/src/test/resources/expected_results/security/split.petstore.api.yaml.scala +++ b/compiler/src/test/resources/expected_results/security/split.petstore.api.yaml.scala @@ -6,113 +6,81 @@ import de.zalando.play.controllers.PlayBodyParsing import de.zalando.play.controllers.ArrayWrapper import org.joda.time.DateTime +trait SecurityExtractors { + def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? + +} + -trait SplitPetstoreApiYamlSecurity { +trait SplitPetstoreApiYamlSecurity extends SecurityExtractors { val unauthorizedContent = ??? val mimeType: String = ??? - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - object petstore_auth_Action extends AuthenticatedBuilder( + + object findPetsByTagsSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - - - - - - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object updatePetSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object addPetSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - - - - - def api_key_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val api_key_petstore_auth_Checks = Seq(api_key_Extractor _, petstore_auth_Extractor _) - - object api_key_petstore_auth_Action extends AuthenticatedBuilder( + object getPetByIdSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = api_key_petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(api_key_Extractor _, petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object updatePetWithFormSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object deletePetSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - - def petstore_auth_Extractor[User >: Any](header: RequestHeader): Option[User] = ??? - - val petstore_auth_Checks = Seq(petstore_auth_Extractor _) - - object petstore_auth_Action extends AuthenticatedBuilder( + object findPetsByStatusSecureAction extends AuthenticatedBuilder( req => { - val individualChecks = petstore_auth_Checks.map(_.apply(req)) + val secureChecks = Seq(petstore_auth_Extractor _) + val individualChecks = secureChecks.map(_.apply(req)) individualChecks.find(_.isEmpty).getOrElse(Option(individualChecks.flatten)) }, onUnauthorized(mimeType, unauthorizedContent) ) - private def onUnauthorized[C](mimeType: String, content: C): RequestHeader => Result =_ => { implicit val writeable = PlayBodyParsing.anyToWritable[C](mimeType)