swagger-api / swagger-play

Apache License 2.0
330 stars 180 forks source link

class ApiHelpController exists, but it has no companion object #50

Open livehl opened 8 years ago

livehl commented 8 years ago

play 2.4.4 [error] Note: class ApiHelpController exists, but it has no companion object.

GET /api-docs controllers.ApiHelpController.getResources replace GET /api-docs @controllers.ApiHelpController.getResources

epot commented 8 years ago

Try to add @ before controllers.Api... in your routes file.

matanox commented 8 years ago

I am currently using play framework's string interpolation DSL not the routes file, and adding the @ seems not enough, it fails to compile with the same error as above. Is a certain import required for it?

import play.api.routing.sird._
import play.api.mvc._
import play.api.mvc.BodyParsers._
import play.api.libs.json.JsValue
import play.api.libs.json.Json
import play.core.routing.Route

trait ExposeRoute {
  type Route = PartialFunction[play.api.mvc.RequestHeader,play.api.mvc.Handler]
  def route: Route
}

object SwaggerRoute extends ExposeRoute {

  def route: Route = {    
    /*
     * Needed for Swagger doing its thing.. see https://github.com/swagger-api/swagger-play/tree/master/play-2.4/swagger-play2
     */
    case GET(p"/swagger.json") => // See reference at https://www.playframework.com/documentation/2.5.x/ScalaSirdRouter
      controllers.ApiHelpController.getResources
    }
}
cdparra commented 8 years ago

Adding @ before controllers (as pointed by @epot) fixed the issue for me. Could you explain the logic behind this? (if possible)

epot commented 7 years ago

I will probably write a very bad explanation if I tried to. I know I encountered this issue while migrating from old 2.0 Play versions. You can take a look at the official doc to understand: https://www.playframework.com/documentation/2.5.x/ScalaDependencyInjection (see "Dependency injecting controllers").