All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.modules.swagger.ApiListingCache.scala Maven / Gradle / Ivy

package play.modules.swagger

import io.swagger.config._
import io.swagger.models.Swagger
import play.api.Logger

object ApiListingCache {
  var cache: Option[Swagger] = None

  def listing(docRoot: String, host: String): Option[Swagger] = {
    cache.orElse {
      Logger("swagger").debug("Loading API metadata")

      val scanner = ScannerFactory.getScanner
      val classes = scanner.classes()
      val reader = new PlayReader(null)
      var swagger = reader.read(classes)

      scanner match {
        case config: SwaggerConfig =>
          swagger = config.configure(swagger)
        case config =>
          // no config, do nothing
      }
      cache = Some(swagger)
      cache
    }
    cache.get.setHost(host)
    cache
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy