swagger-api / swagger-play

Apache License 2.0
330 stars 181 forks source link

ApiListingCache share same cache for different docRoots #204

Open gaeljw opened 5 years ago

gaeljw commented 5 years ago

Hello,

Imagine you have 2 endpoints:

If you use ApiHelpController.getResource("/public") in one endpoint and ApiHelpController.getResource("/private") in the other, it won't work because there is a cache that keeps the Swagger definition and this cache is shared whatever the docRoot you use (/public or /private in this case).

The responsible code is the following in ApiListingCache:

def listing(docRoot: String, host: String): Option[Swagger] = {
    cache.orElse {
      ...
      cache = Some(swagger)
      cache
    }
    cache.get.setHost(host)
    cache
  }

IMHO, we should have a different cache per docRoot value.