Skip to content

Instantly share code, notes, and snippets.

@kciesielski
Last active December 15, 2015 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kciesielski/0cf4fecf0aa664359d00 to your computer and use it in GitHub Desktop.
Save kciesielski/0cf4fecf0aa664359d00 to your computer and use it in GitHub Desktop.
Simple POST definition in Swagger
class ExampleServlet(val swagger: Swagger) extends ScalatraServlet
with ExampleServletSwaggerDefinition with JacksonJsonSupport with JValueResult {
// ...
post("/", operation(addItemOperation)) {
val newItemRequest = parsedBody.extract[NewItemRequest]
ExampleItemDetails("new-item-id", newItemRequest.name, "product", Owner(1, "Owner name", true), new Date())
}
// ...
}
trait ExampleServletSwaggerDefinition extends SwaggerSupport {
// ...
val addItemOperation = apiOperation[ExampleItemDetails]("addNewItem")
.parameter(bodyParam[NewItemRequest]("newItem").description("New item definition").required)
.summary("Creates a new item and returns its details")
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment