Created
July 12, 2016 14:26
-
-
Save fernandomora/3e7db0cba2606b4b46e4d1ef8fe0b7d0 to your computer and use it in GitHub Desktop.
SwaggerFilterSupport for https://github.com/xiaodongw/swagger-finatra
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
import com.github.xiaodongw.swagger.finatra.{SwaggerSupport, SwaggerSupportBase} | |
import com.twitter.finagle.Filter | |
import com.twitter.finagle.http.{Request, Response} | |
import com.twitter.finatra.http.Controller | |
import io.swagger.models.Swagger | |
import io.swagger.models.Operation | |
trait SwaggerFilterSupport extends SwaggerSupport { self: Controller => | |
override protected implicit val swagger: Swagger | |
private type HttpFilter = Filter[Request, Response, Request, Response] | |
private def underlyingRouteDSL(next: HttpFilter) = filter(next) | |
def swaggerFilter(next: HttpFilter) = new SwaggerFilter(this, next, swagger) | |
class SwaggerFilter(controller: SwaggerFilterSupport, next: HttpFilter, sw: Swagger) extends SwaggerSupportBase { | |
override protected implicit val swagger: Swagger = sw | |
def get[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "get", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
def post[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "post", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
def put[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "put", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
def patch[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "patch", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
def delete[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "delete", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
def head[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "head", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
def options[RequestType: Manifest, ResponseType: Manifest](path: String, op: Operation)(callback: RequestType => ResponseType): Unit = { | |
registerOperation(path, "options", op) | |
controller.underlyingRouteDSL(next).get(path)(callback) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment