finatra-swagger


License

License

Categories

Categories

Swagger Program Interface REST Frameworks
GroupId

GroupId

com.jakehschwartz
ArtifactId

ArtifactId

finatra-swagger_2.11
Last Version

Last Version

21.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

finatra-swagger
finatra-swagger
Project URL

Project URL

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

Project Organization

com.jakehschwartz
Source Code Management

Source Code Management

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

Download finatra-swagger_2.11

How to add to project

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

Dependencies

compile (8)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
com.twitter : finatra-http_2.11 jar 21.2.0
io.swagger : swagger-core jar 1.6.2
io.swagger : swagger-scala-module_2.11 jar 1.0.6
com.fasterxml.jackson.datatype : jackson-datatype-joda jar 2.11.2
com.fasterxml.jackson.module : jackson-module-scala_2.11 jar 2.11.2
org.webjars : swagger-ui jar 3.35.2
net.bytebuddy : byte-buddy jar 1.10.19

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.11 jar 3.1.3

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.13 and major Finatra versions going back to 2.10.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.jakehschwartz" %% "finatra-swagger" % "21.1.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

To see these in action, check out the examples directory

Versions

Version
21.2.0
21.1.0
20.12.1
20.12.0
20.10.0
20.9.0
20.8.1
20.8.0
20.7.0
20.6.1
20.6.0
20.5.0
20.4.1
20.3.0
20.1.0
19.12.1
19.12.0
19.11.0
19.10.0
19.9.0
19.8.0
19.7.0
19.6.0
19.5.1
19.5.0
19.4.3
19.4.1
0.1.0