-
-
Save casualjim/11272244 to your computer and use it in GitHub Desktop.
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
abstract class BaseResource(implicit protected val swagger: Swagger) | |
extends ScalatraServlet with FutureSupport with JacksonJsonSupport with SwaggerSupport with Imports { | |
override protected val applicationName = Some("messaging-api") | |
protected def applicationDescription = "Messaging Services API" | |
protected implicit val defaultTimeout = Timeout(5 seconds) | |
override val jsonpCallbackParameterNames: Iterable[String] = Some("callback") | |
protected override def transformRequestBody(body: JValue): JValue = body.camelizeKeys | |
protected override def transformResponseBody(body: JValue): JValue = body.underscoreKeys | |
before() { | |
contentType = formats("json") | |
} | |
} |
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
trait Imports { | |
implicit def jsonFormats = GlobalContext.jsonFormats | |
implicit def swagger = GlobalContext.swagger | |
implicit val system = GlobalContext.system | |
implicit val executor = GlobalContext.executor | |
} | |
object GlobalContext { | |
implicit def jsonFormats: Formats = DefaultFormats + new TemplateTypeSerializer + new EnumNameSerializer(DeliveryStatus) | |
implicit def swagger = new MessagingSwagger | |
implicit val system = ActorSystem() | |
implicit val executor = system.dispatcher | |
} |
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
class ScalatraBootstrap extends LifeCycle with Logging with Imports { | |
implicit val swagger= new Swagger | |
override def destroy(context: ServletContext) { | |
system.shutdown() | |
} | |
override def init(context: ServletContext) { | |
context.mount(new TestResource, "/api/test") | |
context.mount(new MessagingResourcesApp, "/api-docs/*") | |
} | |
} |
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
class TestResource(implicit swagger: Swagger) extends BaseResource() with Logging { | |
val renderTemplate = (apiOperation[String]("getSomething") | |
summary "Get random data" | |
parameter pathParam[String]("name").description("Name") | |
) | |
post("/:name", operation(renderTemplate)) { | |
new AsyncResult() { | |
override val is = Future { | |
Ok(Map("a" -> "b", "name" -> params("name"))) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment