Skip to content
This repository has been archived by the owner on Sep 14, 2022. It is now read-only.

Cleaning deprecated methods #155

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Swagger Play Integration

[![Build Status](https://travis-ci.org/swagger-api/swagger-play.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-play)

The goal of Swagger™ is to define a standard, language-agnostic interface to REST APIs which allows both humans and computers to discover and understand the capabilities of the service without access to source code, documentation, or through network traffic inspection. When properly defined via Swagger, a consumer can understand and interact with the remote service with a minimal amount of implementation logic. Similar to what interfaces have done for lower-level programming, Swagger removes the guesswork in calling the service.

Swagger-play is an integration specifically for the Play framework.
Expand Down
1 change: 1 addition & 0 deletions play-1.2/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Swagger Play 1.2.x Framework Module


**NOTE! This repository is available for historical reasons and the project is no longer supported**

## Overview
Expand Down
1 change: 1 addition & 0 deletions play-2.1/swagger-play2/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Swagger Play2 Module


## Overview
This is a module to support the play2 framework from [playframework](http://www.playframework.org). It is written in scala but can be used with either java or scala-based play2 applications.

Expand Down
5 changes: 3 additions & 2 deletions play-2.4/swagger-play2/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[![Build Status](https://travis-ci.org/rayyildiz/swagger-play.svg?branch=master)](https://travis-ci.org/rayyildiz/swagger-play)

# Swagger Play2 Module

[![Build Status](https://travis-ci.org/swagger-api/swagger-play.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-play)


## Overview
This is a module to support the play2 framework from [playframework](http://www.playframework.org). It is written in scala but can be used with either java or scala-based play2 applications.

Expand Down
2 changes: 1 addition & 1 deletion play-2.4/swagger-play2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ pomExtra := {
</developers>
}

lazy val root = (project in file(".")).enablePlugins(PlayScala)
lazy val root = (project in file(".")).enablePlugins(PlayScala)
4 changes: 2 additions & 2 deletions play-2.5/swagger-play2/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Build Status](https://travis-ci.org/rayyildiz/swagger-play.svg?branch=master)](https://travis-ci.org/rayyildiz/swagger-play)

# Swagger Play2 Module

[![Build Status](https://travis-ci.org/swagger-api/swagger-play.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-play)

## Overview
This is a module to support the play2 framework from [playframework](http://www.playframework.org). It is written in scala but can be used with either java or scala-based play2 applications.

Expand Down
5 changes: 3 additions & 2 deletions play-2.6/swagger-play2/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[![Build Status](https://travis-ci.org/rayyildiz/swagger-play.svg?branch=master)](https://travis-ci.org/rayyildiz/swagger-play)

# Swagger Play2 Module

[![Build Status](https://travis-ci.org/swagger-api/swagger-play.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-play)


## Overview
This is a module to support the play2 framework from [playframework](http://www.playframework.org). It is written in scala but can be used with either java or scala-based play2 applications.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ class PlayApiScanner() extends Scanner with SwaggerConfig {

private def updateInfoFromConfig(swagger: Swagger): Swagger = {

var info = new Info()
val info = new Info()
val playSwaggerConfig = PlayConfigFactory.getConfig

if (StringUtils.isNotBlank(playSwaggerConfig.description)) {
info.description(playSwaggerConfig.description);
info.description(playSwaggerConfig.description)
}

if (StringUtils.isNotBlank(playSwaggerConfig.title)) {
info.title(playSwaggerConfig.title);
info.title(playSwaggerConfig.title)
} else {
// title tag needs to be present to validate against schema
info.title("");
info.title("")
}

if (StringUtils.isNotBlank(playSwaggerConfig.version)) {
info.version(playSwaggerConfig.version);
info.version(playSwaggerConfig.version)
}

if (StringUtils.isNotBlank(playSwaggerConfig.termsOfServiceUrl)) {
Expand All @@ -43,12 +43,12 @@ class PlayApiScanner() extends Scanner with SwaggerConfig {

if (playSwaggerConfig.contact != null) {
info.contact(new Contact()
.name(playSwaggerConfig.contact));
.name(playSwaggerConfig.contact))
}
if (playSwaggerConfig.license != null && playSwaggerConfig.licenseUrl != null) {
info.license(new License()
.name(playSwaggerConfig.license)
.url(playSwaggerConfig.licenseUrl));
.url(playSwaggerConfig.licenseUrl))
}
swagger.info(info)
}
Expand All @@ -60,7 +60,7 @@ class PlayApiScanner() extends Scanner with SwaggerConfig {
}
updateInfoFromConfig(swagger)
swagger.host(playSwaggerConfig.host)
swagger.basePath(playSwaggerConfig.basePath);
swagger.basePath(playSwaggerConfig.basePath)

}

Expand All @@ -72,15 +72,15 @@ class PlayApiScanner() extends Scanner with SwaggerConfig {
Logger("swagger").info("ControllerScanner - looking for controllers with API annotation")


var routes = RouteFactory.getRoute().getAll().toList
val routes = RouteFactory.getRoute().getAll().toList

// get controller names from application routes
val controllers = routes.map { case (_, route) =>
s"${route.call.packageName}.${route.call.controller}"
}.distinct


var list = controllers.collect {
val list = controllers.collect {
case className: String if {
try {
SwaggerContext.loadClass(className).getAnnotation(classOf[Api]) != null
Expand All @@ -100,7 +100,7 @@ class PlayApiScanner() extends Scanner with SwaggerConfig {
}

override def getPrettyPrint(): Boolean = {
true;
true
}

override def setPrettyPrint(x: Boolean) {}
Expand Down
22 changes: 11 additions & 11 deletions play-2.6/swagger-play2/app/play/modules/swagger/SwaggerPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,45 +39,45 @@ class SwaggerPluginImpl @Inject()(lifecycle: ApplicationLifecycle, router: Route
val config = app.configuration
logger.info("Swagger - starting initialisation...")

val apiVersion = config.getString("api.version") match {
val apiVersion = config.getOptional[String]("api.version") match {
case None => "beta"
case Some(value) => value
}

val basePath = config.getString("swagger.api.basepath")
val basePath = config.getOptional[String]("swagger.api.basepath")
.filter(path => !path.isEmpty)
.getOrElse("/")

val host = config.getString("swagger.api.host")
val host = config.getOptional[String]("swagger.api.host")
.filter(host => !host.isEmpty)
.getOrElse("localhost:9000")

val title = config.getString("swagger.api.info.title") match {
val title = config.getOptional[String]("swagger.api.info.title") match {
case None => ""
case Some(value)=> value
}

val description = config.getString("swagger.api.info.description") match {
val description = config.getOptional[String]("swagger.api.info.description") match {
case None => ""
case Some(value)=> value
}

val termsOfServiceUrl = config.getString("swagger.api.info.termsOfServiceUrl") match {
val termsOfServiceUrl = config.getOptional[String]("swagger.api.info.termsOfServiceUrl") match {
case None => ""
case Some(value)=> value
}

val contact = config.getString("swagger.api.info.contact") match {
val contact = config.getOptional[String]("swagger.api.info.contact") match {
case None => ""
case Some(value)=> value
}

val license = config.getString("swagger.api.info.license") match {
val license = config.getOptional[String]("swagger.api.info.license") match {
case None => ""
case Some(value)=> value
}

val licenseUrl = config.getString("swagger.api.info.licenseUrl") match {
val licenseUrl = config.getOptional[String]("swagger.api.info.licenseUrl") match {
// licenceUrl needs to be a valid URL to validate against schema
case None => "http://licenseUrl"
case Some(value)=> value
Expand Down Expand Up @@ -110,7 +110,7 @@ class SwaggerPluginImpl @Inject()(lifecycle: ApplicationLifecycle, router: Route

val routesFile = config.underlying.hasPath("play.http.router") match {
case false => "routes"
case true => config.getString("play.http.router") match {
case true => config.getOptional[String]("play.http.router") match {
case None => "routes"
case Some(value)=> playRoutesClassNameToFileName(value)
}
Expand Down Expand Up @@ -147,7 +147,7 @@ class SwaggerPluginImpl @Inject()(lifecycle: ApplicationLifecycle, router: Route

val route = new RouteWrapper(routesRules)
RouteFactory.setRoute(route)
app.configuration.getString("swagger.filter") match {
app.configuration.getOptional[String]("swagger.filter") match {
case Some(e) if (e != "") => {
try {
FilterFactory setFilter SwaggerContext.loadClass(e).newInstance.asInstanceOf[SwaggerSpecFilter]
Expand Down
1 change: 1 addition & 0 deletions play-2.6/swagger-play2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ scalaVersion := "2.11.8"
crossScalaVersions := Seq(scalaVersion.value, "2.12.2")

libraryDependencies ++= Seq(
guice,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.8.9",
"org.slf4j" % "slf4j-api" % "1.7.21",
"io.swagger" % "swagger-core" % "1.5.16",
Expand Down
2 changes: 1 addition & 1 deletion play-2.6/swagger-play2/project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.13
sbt.version=0.13.15
7 changes: 4 additions & 3 deletions play-2.6/swagger-play2/test/testdata/CatController.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package testdata

import io.swagger.annotations._
import javax.inject.Inject

import play.api.mvc.{Action, Controller}
import io.swagger.annotations._
import play.api.mvc._

@Api(value = "/apitest/cats", description = "play with cats")
class CatController extends Controller {
class CatController @Inject() () extends InjectedController {

@ApiOperation(value = "addCat1",
httpMethod = "PUT",
Expand Down
9 changes: 5 additions & 4 deletions play-2.6/swagger-play2/test/testdata/DocumentController.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package testdata

import io.swagger.annotations._
import javax.inject.Inject

import play.api.mvc.Controller
import play.mvc.{Result, Http}
import io.swagger.annotations._
import play.api.mvc.{InjectedController}
import play.mvc.{Http, Result}

@Api(value = "/apitest/document", description = "documents", tags = Array("Documents"))
class DocumentController extends Controller {
class DocumentController @Inject() () extends InjectedController {

@ApiOperation(value = "Register acceptance of a file on a settlement",
notes = "Accept file",
Expand Down
7 changes: 5 additions & 2 deletions play-2.6/swagger-play2/test/testdata/DogController.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package testdata

import javax.inject.Inject

import io.swagger.annotations._
import play.api.mvc.{Action, Controller}
import play.api.mvc.{Action, Controller, InjectedController}

import scala.concurrent.Future

// todo - test for these
Expand All @@ -18,7 +21,7 @@ import scala.concurrent.Future
))
)
)
object DogController extends Controller {
class DogController @Inject() () extends InjectedController {

@ApiOperation(value="addDog0")
def add0(id:String) = Action {
Expand Down
6 changes: 4 additions & 2 deletions play-2.6/swagger-play2/test/testdata/FlyController.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package testdata

import play.api.mvc.{Action, Controller}
import javax.inject.Inject

object FlyController extends Controller {
import play.api.mvc.{InjectedController}

class FlyController @Inject() () extends InjectedController {

def list = Action {
request =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package testdata

import javax.inject.Inject

import io.swagger.annotations._
import play.api.mvc.Controller
import play.mvc.{Result, Http}
import play.api.mvc.{InjectedController}
import play.mvc.{Http, Result}

@Api(value = "/apitest/pointsofinterest", description = "Points of interest")
class PointOfInterestController extends Controller {
class PointOfInterestController @Inject() () extends InjectedController {

@ApiOperation(value = "Get points of interest",
notes = "Returns points of interest",
Expand Down