Last active
December 29, 2015 12:19
-
-
Save chronodm/7669424 to your computer and use it in GitHub Desktop.
Scalatra operations that Swagger doesn't seem to be able to read.
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 RouterBase(val swagger: Swagger) extends ScalatraServlet with JacksonJsonSupport with SwaggerSupport { | |
protected implicit val jsonFormats: Formats = DefaultFormats | |
mapper.registerModule(new JodaModule()) | |
before() { | |
contentType = formats("json") | |
} | |
} | |
class BibRouter(config: { | |
val swagger: Swagger | |
val bibService: BibService | |
}) | |
extends RouterBase(config.swagger) { | |
protected def applicationDescription: String = "Bib API" | |
get("/", operation(apiOperation[List[Bib]]("getBibs") | |
summary "Get all bibs")) { | |
config.bibService.allBibs | |
} | |
get("/:id", operation(apiOperation[Bib]("getBib") | |
summary "Get a bib")) { | |
config.bibService.getBib(Integer.parseInt(params("id"))) | |
} | |
get("/ids", operation(apiOperation[List[Int]]("allBibIds") | |
summary "Get all bib IDs")) { | |
config.bibService.allBibIds | |
} | |
} | |
case class Bib( | |
id: Int, | |
modifiedDate: DateTime = new DateTime(0), | |
createdDate: DateTime = new DateTime(0), | |
suppressed: Boolean = false, | |
lang: Option[String] = None, | |
title: Option[String] = None, | |
author: Option[String] = None, | |
materialType: Option[MaterialType] = None, | |
bibLevel: Option[BibLevel] = None, | |
publishYear: Option[Int] = None, | |
catalogDate: Option[DateTime] = None, | |
country: Option[String] = None, | |
fixedFields: Option[List[FixedField]] = None, | |
varFields: Option[List[VarField]] = None, | |
marc: Option[MarcInJson] = None | |
) | |
case class MaterialType( | |
code: Char, | |
value: Option[String] = None | |
) | |
case class BibLevel( | |
code: Char, | |
value: Option[String] = None | |
) | |
case class FixedField( | |
label: String, | |
number: Int, | |
value: Option[Any], | |
display: Option[String] | |
) | |
case class VarField( | |
label: String, | |
fieldTag: Char, | |
marcTag: Option[String] = None, | |
ind1: Option[Char] = None, | |
ind2: Option[Char] = None, | |
content: Either[String, List[SubField]] = Left("") | |
) | |
case class SubField( | |
tag: Char, | |
content: String | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment