Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controllers implementing SwaggerController needs to implement dsl. #79

Open
mani199184 opened this issue Apr 26, 2022 · 4 comments
Open

Comments

@mani199184
Copy link

mani199184 commented Apr 26, 2022

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

@mani199184
Copy link
Author

mani199184 commented Apr 26, 2022

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"

@mani199184 mani199184 changed the title Controllers implementing SwaggerController needs to implement swagger and dsl. Controllers implementing SwaggerController needs to implement dsl. Apr 26, 2022
@jakehschwartz
Copy link
Owner

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
Copy link
Author

mani199184 commented Apr 26, 2022

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
Copy link

mgd43b commented Apr 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants