jakehschwartz / finatra-swagger

Swagger Support For Finatra
https://jakehschwartz.github.io/swagger-finatra
Apache License 2.0
28 stars 19 forks source link

Controllers implementing SwaggerController needs to implement dsl. #79

Open mani199184 opened 2 years ago

mani199184 commented 2 years ago

dsl can be implemented with line "override protected val dsl = self"

ref: https://github.com/xiaodongw/swagger-finatra/blob/master/src/main/scala/com/github/xiaodongw/swagger/finatra/SwaggerSupport.scala#L7

https://github.com/jakehschwartz/finatra-swagger/blob/e40474826506112c2500c1166c393ff77cd25e95/src/main/scala/com/jakehschwartz/finatra/swagger/SwaggerController.scala#L7

mani199184 commented 2 years ago

My controllers are trying to extend SwaggerController without dependency injections. I am creating objects of controllers with swagger parameter. Like class mycontroller(s: Swagger) extends SwaggerController { override implicit protected val swagger = s ... }

I am getting error "class mycontroller needs to be abstract, since value dsl in trait SwaggerRouteDSL of type com.twitter.finatra.http.RouteDSL is not defined"

jakehschwartz commented 2 years ago

I havent figured out how to create a SwaggerController without injecting the Swagger/OpenAPI object. This is because the object is created in your project via Module with the information you want to show in your documentation page.

Happy to accept any pull requests to make this more streamlined.

mani199184 commented 2 years ago

Can't we use this finantra-swagger without dependecy injection? I created an object of swagger module and used it in mycontroller. Can I use it like below code? If yes, why I am getting error "class mycontroller needs to be abstract, since value dsl in trait SwaggerRouteDSL of type com.twitter.finatra.http.RouteDSL is not defined"

Swagger module:

`lazy val myswagger : Swagger = {
    val swagger = new Swagger()
    val info = new Info()
      .title("API")
      .description(
        """ test
      """.stripMargin)
      .version("1.0")

    swagger
      .info(info)
      .addProduces("application/json")

    swagger.addConsumes("application/json")
    swagger
  }`

My controller

class mycontroller(s: Swagger) extends SwaggerController { override implicit protected val swagger = s ... } http server

`class MyHttpServer()
  extends HttpServer {
  override def jacksonModule = CustomJacksonModule

  override protected def configureHttp(router: HttpRouter): Unit = {
    router.add[DocsController]
    router.add(new  mycontroller(myswagger))
  }

  /**
    * Set it to 32KB solves the problem
    * @param server
    * @return
    */
  override protected def configureHttpServer(server: Http.Server) = {
    super.configureHttpServer(server)
      .configured(http.param.MaxHeaderSize(32.kilobytes))
  }
}`
mgd43b commented 2 years ago

I think one of the concepts with Finatra is that it uses a lot of injection, which is why this module is this way.