Created
April 24, 2014 22:05
-
-
Save fehguy/11271106 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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