swagger-api / swagger-play

Apache License 2.0
330 stars 181 forks source link

Basic Auth Support #120

Open yeryomenkom opened 7 years ago

yeryomenkom commented 7 years ago

How can I add in the root of generated json file this part? "securityDefinitions":{ "basic_auth":{ "type":"basic", "name":"basic" } }

dwickern commented 7 years ago

I had the same issue. You can subclass the SwaggerBaseApiController with your own getResources:

class MyApiController extends SwaggerBaseApiController {
  def getResources = Action {
    request =>
      implicit val requestHeader: RequestHeader = request
      val host = requestHeader.host
      val resourceListing = getResourceListing(host)
      resourceListing.addSecurityDefinition("basic_auth", new BasicAuthDefinition)
      val responseStr = returnXml(request) match {
        case true => toXmlString(resourceListing)
        case false => toJsonString(resourceListing)
      }
      returnValue(request, responseStr)
  }
}