finatra-swagger


License

License

Categories

Categories

Swagger Program Interface REST Frameworks
GroupId

GroupId

com.github.ikhoon
ArtifactId

ArtifactId

finatra-swagger_2.12
Last Version

Last Version

18.9.1
Release Date

Release Date

Type

Type

jar
Description

Description

finatra-swagger
finatra-swagger
Project URL

Project URL

https://github.com/ikhoon/finatra-swagger
Project Organization

Project Organization

com.github.ikhoon
Source Code Management

Source Code Management

https://github.com/ikhoon/finatra-swagger

Download finatra-swagger_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ikhoon/finatra-swagger_2.12/ -->
<dependency>
    <groupId>com.github.ikhoon</groupId>
    <artifactId>finatra-swagger_2.12</artifactId>
    <version>18.9.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ikhoon/finatra-swagger_2.12/
implementation 'com.github.ikhoon:finatra-swagger_2.12:18.9.1'
// https://jarcasting.com/artifacts/com.github.ikhoon/finatra-swagger_2.12/
implementation ("com.github.ikhoon:finatra-swagger_2.12:18.9.1")
'com.github.ikhoon:finatra-swagger_2.12:jar:18.9.1'
<dependency org="com.github.ikhoon" name="finatra-swagger_2.12" rev="18.9.1">
  <artifact name="finatra-swagger_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ikhoon', module='finatra-swagger_2.12', version='18.9.1')
)
libraryDependencies += "com.github.ikhoon" % "finatra-swagger_2.12" % "18.9.1"
[com.github.ikhoon/finatra-swagger_2.12 "18.9.1"]

Dependencies

compile (6)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.7
com.twitter : finatra-http_2.12 jar 18.9.1
io.swagger : swagger-core jar 1.5.17
io.swagger : swagger-scala-module_2.12 jar 1.0.4
org.webjars : swagger-ui jar 3.2.0
net.bytebuddy : byte-buddy jar 1.7.5

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.12 jar 3.0.5

Project Modules

There are no modules declared in this project.

finatra-swagger

CircleCI Codacy Badge

Add Swagger UI support to Finatra web framework.

Currently supports Scala 2.12 & 2.11 with Finatra 17.12.0

For older versions, see the original repository by xiaodongw

Getting started

The major and minor version of the library matches the Finatra major and minor version:

libraryDependencies += "com.github.ikhoon" %% "finatra-swagger" % "17.12.0"

First, create a subclass of a SwaggerModule

object SampleSwaggerModule extends SwaggerModule {

  @Singleton
  @Provides
  def swagger: Swagger = {
    val swagger = new Swagger()

    val info = new Info()
      .description("The Student / Course management API, this is a sample for swagger document generation")
      .version("1.0.1")
      .title("Student / Course Management API")

    swagger
      .info(info)
      .addSecurityDefinition("sampleBasic", {
        val d = new BasicAuthDefinition()
        d.setType("basic")
        d
      })

    swagger
  }
}

Then add the module to the list of modules in the Server. Don't forget to include the DocsController in the router!

object SampleApp extends HttpServer {
  override protected def modules = Seq(SampleSwaggerModule)

  override def configureHttp(router: HttpRouter) {
    router
      .add[DocsController]
      ...
  } 
}

Lastly, configure the endpoints using the SwaggerRouteDSL

class SampleController@Inject()(s: Swagger) extends SwaggerController {
  implicit protected val swagger = s

  getWithDoc("/students/:id") { o =>
    o.summary("Read the detail information about the student")
      .tag("Student")
      .routeParam[String]("id", "the student id")
      .responseWith[Student](200, "the student details")
      .responseWith(404, "the student is not found")
  } { request =>
    ...
  }

To see the Swagger UI, use the /docs endpoint. This can be overridden using the Finatra flag "swagger.docs.endpoint"

To see the model that is JSON document that is generated, use /swagger.json.

Features

TODO

To see these in action, check out the examples directory

Versions

Version
18.9.1
18.9.1-RC1
18.4.4
18.4.3
18.4.2-RC3
18.4.2-RC1
18.4.1
18.4.1-RC1
18.4.0
17.12.0
2.13.0