Skip to content

Instantly share code, notes, and snippets.

@fehguy
Created April 24, 2014 22:05
Show Gist options
  • Save fehguy/11271106 to your computer and use it in GitHub Desktop.
Save fehguy/11271106 to your computer and use it in GitHub Desktop.
def listing(docRoot: String, app: Application, sc: ServletConfig): Option[Map[String, ApiListing]] = {
var _cache: Option[Map[String, ApiListing]] = None
_cache.orElse{
LOGGER.debug("loading cache")
ClassReaders.reader.map{reader =>
ScannerFactory.scanner.map(scanner => {
val classes = scanner match {
case scanner: JaxrsScanner => scanner.asInstanceOf[JaxrsScanner].classesFromContext(app, null)
case _ => List()
}
// For each top level resource, parse it and look for swagger annotations.
val listings = (for(cls <- classes) yield reader.read(docRoot, cls, ConfigFactory.config)).flatten.toList
val mergedListings = groupByResourcePath(listings)
_cache = Some((mergedListings.map(m => {
// always start with "/"
val resourcePath = m.resourcePath.startsWith ("/") match {
case true => m.resourcePath
case false => "/" + m.resourcePath
}
LOGGER.debug("adding resource path " + resourcePath)
(resourcePath, m)
})).toMap)
})
// }
_cache
}
if(_cache != None)
LOGGER.debug("cache has " + _cache.get.keys + " keys")
else
LOGGER.debug("cache is empty")
_cache
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment