From fd0e8aa7fabe10526ad49a4c163318ee22ecc558 Mon Sep 17 00:00:00 2001 From: frantuma Date: Wed, 18 Dec 2019 19:51:32 +0100 Subject: [PATCH 1/9] restructure - play-2.7 readme --- README.md | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index dc49c67..e5e7a9b 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,11 @@ # Swagger Play2 Module ## Overview -This is a module to support Swagger annotations within [Play Framework](http://www.playframework.org) controllers. This library uses Swagger 1.5 and supports Play 2.7 (version 2.0.x). It can be used for both Scala and Java based applications. -We also would like to support Swagger 2.0 in the future and contributions to that end will be gladly accepted. +This is a module to support Swagger annotations within [Play Framework](http://www.playframework.org) controllers. It is based on the library https://github.com/swagger-api/swagger-play with several improvements. This library uses Swagger 1.5 and Play 2.7. It can be used for both Scala and Java based applications. -## Version History +We also would like to support Swagger 2.0 in the future and contributions to that end will be gladly accepted. -* swagger-play2 2.0.1-SNAPSHOT supports play 2.7 and swagger 2.0. Merged from fork https://github.com/Iterable/swagger-play ###New and Noteworthy @@ -23,26 +21,6 @@ We also would like to support Swagger 2.0 in the future and contributions to tha - Add support for API keys (https://github.com/swagger-api/swagger-play/pull/117) - Add support for OAuth2 (https://github.com/swagger-api/swagger-play/pull/183) -* swagger-play2 1.7.1 supports play 2.7 and swagger 2.0. - -* swagger-play2 1.7.0 supports play 2.7 and swagger 2.0. - -* swagger-play2 1.6.1 supports play 2.6 and swagger 2.0. - -* swagger-play2 1.5.1 supports play 2.4 and swagger 2.0. If you need swagger 1.2 support, use 1.3.13. If you need 2.2 support, use 1.3.7 or earlier. - -* swagger-play2 1.3.13 supports play 2.4. If you need 2.2 support, use 1.3.7 or earlier. - -* swagger-play2 1.3.12 supports play 2.3. If you need 2.2 support, use 1.3.7 or earlier. - -* swagger-play2 1.3.7 supports play 2.2. If you need 2.1 support, please use 1.3.5 or earlier - -* swagger-play2 1.3.6 requires play 2.2.x. - -* swagger-play2 1.2.1 and greater support scala 2.10 and play 2.0 and 2.1. - -* swagger-play2 1.2.0 support scala 2.9.x and play 2.0, please use 1.2.0. - Usage ----- @@ -50,15 +28,13 @@ You can depend on pre-built libraries in maven central by adding the following d ``` libraryDependencies ++= Seq( - "io.swagger" %% "swagger-play2" % "2.0.1" + "io.swagger" %% "swagger-play2" % "2.0.1-SNAPSHOT" ) ``` Or you can build from source. ``` -cd play-2.7/swagger-play2 - sbt publishLocal ``` From ced41b54aa4ed6ee35f03520e3bbcbf90d59cb4b Mon Sep 17 00:00:00 2001 From: frantuma Date: Thu, 19 Dec 2019 13:08:44 +0100 Subject: [PATCH 2/9] restructure - play-2.7 fix travis --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 23a4ebe..367bd5b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,8 @@ cache: language: scala scala: - - 2.11.12 - - 2.12.6 + - 2.12.10 + - 2.13.1 script: - sbt ++$TRAVIS_SCALA_VERSION compile test From 0f09b7f4a8dad6002b3f1d807bc6275a4fccfef7 Mon Sep 17 00:00:00 2001 From: Francesco Tumanischvili Date: Thu, 19 Dec 2019 13:16:53 +0100 Subject: [PATCH 3/9] Update README.md --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e5e7a9b..0277451 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This is a module to support Swagger annotations within [Play Framework](http://w We also would like to support Swagger 2.0 in the future and contributions to that end will be gladly accepted. -###New and Noteworthy +### New and Noteworthy - Minimal dependencies: only depends on the core Play module, so it won't bring unnecessary dependencies on the Akka HTTP server or anything else from Play. - `SwaggerPlugin` no longer depends on on `Application`. @@ -21,8 +21,7 @@ We also would like to support Swagger 2.0 in the future and contributions to tha - Add support for API keys (https://github.com/swagger-api/swagger-play/pull/117) - Add support for OAuth2 (https://github.com/swagger-api/swagger-play/pull/183) -Usage ------ +## Usage You can depend on pre-built libraries in maven central by adding the following dependency: @@ -104,7 +103,7 @@ paramaters (variables) are passed to the method implicitly by the framework. AL with `ApiImplicitParam` annotations. If they are `queryParam`s or `pathParam`s, you can use `ApiParam` annotations. -# application.conf - config options +## application.conf - config options ``` api.version (String) - version of API | default: "beta" swagger.api.basepath (String) - base url | default: "http://localhost:9000" From e53fa0827f17ae8f44ee21824edb4be5a052d09b Mon Sep 17 00:00:00 2001 From: Francesco Tumanischvili Date: Thu, 19 Dec 2019 13:24:31 +0100 Subject: [PATCH 4/9] Add versions note to readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 0277451..84eaef1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ # Swagger Play2 Module +## Note + +This branch (`master`) holds the latest version (major version `2.x`) for latest play version supported (`2.7`); branch [play-2.6](https://github.com/swagger-api/swagger-play/tree/play-2.6) holds the swagger-play version for play `2.6` version (major.minor version `1.6.x`). + +Older versions are available though not anymore supported in the [archive](https://github.com/swagger-api/swagger-play/tree/archive) branch. + ## Overview This is a module to support Swagger annotations within [Play Framework](http://www.playframework.org) controllers. It is based on the library https://github.com/swagger-api/swagger-play with several improvements. This library uses Swagger 1.5 and Play 2.7. It can be used for both Scala and Java based applications. From 60bce7058caa8315aaf1520f43924398d2b9d766 Mon Sep 17 00:00:00 2001 From: Gabriel Ciuloaica Date: Fri, 27 Dec 2019 15:52:18 +0200 Subject: [PATCH 5/9] ref #214 - Vendor Extensions support in API Info --- src/main/resources/reference.conf | 2 ++ .../play/modules/swagger/PlayApiScanner.scala | 6 +++++ .../modules/swagger/PlaySwaggerConfig.scala | 14 +++++++++-- src/test/resources/reference.conf | 21 ++++++++++++++++ .../scala/PlayApiInfoConfigParserSpec.scala | 25 +++++++++++++++++++ src/test/scala/PlayApiListingCacheSpec.scala | 5 +++- 6 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/reference.conf create mode 100644 src/test/scala/PlayApiInfoConfigParserSpec.scala diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index cafebac..9c9c361 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -15,5 +15,7 @@ swagger.api { contact = "" license = "" licenseUrl = "http://licenseUrl" # needs to be a valid url to validate against schema + x-api-key: "test" + x-tags: ["api", "secure"] } } diff --git a/src/main/scala/play/modules/swagger/PlayApiScanner.scala b/src/main/scala/play/modules/swagger/PlayApiScanner.scala index 2a430cf..a26edc5 100644 --- a/src/main/scala/play/modules/swagger/PlayApiScanner.scala +++ b/src/main/scala/play/modules/swagger/PlayApiScanner.scala @@ -52,6 +52,12 @@ class PlayApiScanner @Inject()(config: PlaySwaggerConfig, routes: RouteWrapper, .name(config.license) .url(config.licenseUrl)) } + + val vendorExtensions = config.vendorExtensions.map { extension => + extension.name -> extension.value + }.toMap.asJava + + info.setVendorExtensions(vendorExtensions) swagger.info(info) } diff --git a/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala b/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala index a5a11cb..2686242 100644 --- a/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala +++ b/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala @@ -4,6 +4,10 @@ import com.typesafe.config.Config import javax.annotation.Nullable import play.api.Configuration +import scala.collection.JavaConverters._ + +case class Extension(name: String, value: AnyRef) + case class PlaySwaggerConfig( title: String, version: String, @@ -15,7 +19,8 @@ case class PlaySwaggerConfig( host: String, basePath: String, schemes: Seq[String], - filterClass: Option[String] + filterClass: Option[String], + vendorExtensions: List[Extension] ) { // Java APIs for reading the configuration def getSchemes: Array[String] = schemes.toArray @@ -37,7 +42,12 @@ object PlaySwaggerConfig { termsOfServiceUrl = configuration.get[String]("swagger.api.info.termsOfServiceUrl"), license = configuration.get[String]("swagger.api.info.license"), licenseUrl = configuration.get[String]("swagger.api.info.licenseUrl"), - filterClass = configuration.get[Option[String]]("swagger.filter") + filterClass = configuration.get[Option[String]]("swagger.filter"), + vendorExtensions = configuration.get[Option[Config]]("swagger.api.info").toList.map(_.entrySet()).flatMap { entries => + entries.asScala.filter(_.getKey.startsWith("x-")).map { entry => + Extension(entry.getKey, entry.getValue.unwrapped()) + }.toList.reverse + } ) } diff --git a/src/test/resources/reference.conf b/src/test/resources/reference.conf new file mode 100644 index 0000000..1d33c4a --- /dev/null +++ b/src/test/resources/reference.conf @@ -0,0 +1,21 @@ + +api.version = beta + +swagger.filter = null +swagger.api { + basepath = "/" + host = "localhost:9000" + title = "Test API" + schemes = [] + + info { + title = "Test" + description = "Test API endpoint" + termsOfServiceUrl = "" + contact = "test@test.com" + license = "Apache2" + licenseUrl = "http://licenseUrl" # needs to be a valid url to validate against schema + x-api-key: "test" + x-tags: ["test", "api"] + } +} diff --git a/src/test/scala/PlayApiInfoConfigParserSpec.scala b/src/test/scala/PlayApiInfoConfigParserSpec.scala new file mode 100644 index 0000000..7fe9aa3 --- /dev/null +++ b/src/test/scala/PlayApiInfoConfigParserSpec.scala @@ -0,0 +1,25 @@ +import com.typesafe.config.ConfigFactory +import org.specs2.mutable.Specification +import play.modules.swagger.PlaySwaggerConfig + +class PlayApiInfoConfigParserSpec extends Specification { + + private val config = ConfigFactory.load() + + "API Info " should { + "proper build Info object" in { + val probe = PlaySwaggerConfig(config) + probe.title === "Test" + probe.description === "Test API endpoint" + probe.termsOfServiceUrl.isEmpty === true + probe.contact === "test@test.com" + probe.license === "Apache2" + probe.licenseUrl === "http://licenseUrl" + probe.vendorExtensions.size shouldEqual(2) + probe.vendorExtensions.head.name === "x-api-key" + probe.vendorExtensions.head.value === "test" + probe.vendorExtensions.tail.head.name === "x-tags" + probe.vendorExtensions.tail.head.value === java.util.Arrays.asList("test", "api") + } + } +} diff --git a/src/test/scala/PlayApiListingCacheSpec.scala b/src/test/scala/PlayApiListingCacheSpec.scala index 1b2cf46..f92a038 100644 --- a/src/test/scala/PlayApiListingCacheSpec.scala +++ b/src/test/scala/PlayApiListingCacheSpec.scala @@ -1,5 +1,6 @@ import java.io.File +import com.typesafe.config.ConfigValueFactory import io.swagger.config.ScannerFactory import io.swagger.models.{HttpMethod, ModelImpl} import io.swagger.models.parameters.{BodyParameter, PathParameter, QueryParameter} @@ -57,7 +58,8 @@ PUT /api/dog/api/:id testdata.DogController.add0(id:String) license = "license", licenseUrl = "http://licenseUrl", filterClass = None, - schemes = Seq.empty + schemes = Seq.empty, + vendorExtensions = List(Extension("x-api-key","test"), Extension("x-tags", java.util.Arrays.asList("api", "secure","test"))) ) val env = Environment.simple() @@ -90,6 +92,7 @@ PUT /api/dog/api/:id testdata.DogController.add0(id:String) swagger.getInfo.getTermsOfService must beEqualTo(swaggerConfig.termsOfServiceUrl) swagger.getInfo.getLicense.getName must beEqualTo(swaggerConfig.license) swagger.getSecurityDefinitions.size() must beEqualTo(1) + swagger.getInfo.getVendorExtensions.size() must beEqualTo(2) val pathDoc = swagger.getPaths.get("/document/{settlementId}/files/{fileId}/accept") pathDoc.getOperations.size must beEqualTo(1) From 7ddfaa36a142f306842348d5590c54f15b464b68 Mon Sep 17 00:00:00 2001 From: Gabriel Ciuloaica Date: Fri, 27 Dec 2019 16:06:48 +0200 Subject: [PATCH 6/9] ref #214 - Vendor Extensions support in API Info --- src/main/resources/reference.conf | 2 ++ .../play/modules/swagger/PlayApiScanner.scala | 6 ++++++ .../play/modules/swagger/PlaySwaggerConfig.scala | 14 ++++++++++++-- src/test/scala/PlayApiListingCacheSpec.scala | 5 ++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index cafebac..9c9c361 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -15,5 +15,7 @@ swagger.api { contact = "" license = "" licenseUrl = "http://licenseUrl" # needs to be a valid url to validate against schema + x-api-key: "test" + x-tags: ["api", "secure"] } } diff --git a/src/main/scala/play/modules/swagger/PlayApiScanner.scala b/src/main/scala/play/modules/swagger/PlayApiScanner.scala index 2a430cf..a26edc5 100644 --- a/src/main/scala/play/modules/swagger/PlayApiScanner.scala +++ b/src/main/scala/play/modules/swagger/PlayApiScanner.scala @@ -52,6 +52,12 @@ class PlayApiScanner @Inject()(config: PlaySwaggerConfig, routes: RouteWrapper, .name(config.license) .url(config.licenseUrl)) } + + val vendorExtensions = config.vendorExtensions.map { extension => + extension.name -> extension.value + }.toMap.asJava + + info.setVendorExtensions(vendorExtensions) swagger.info(info) } diff --git a/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala b/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala index a5a11cb..2686242 100644 --- a/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala +++ b/src/main/scala/play/modules/swagger/PlaySwaggerConfig.scala @@ -4,6 +4,10 @@ import com.typesafe.config.Config import javax.annotation.Nullable import play.api.Configuration +import scala.collection.JavaConverters._ + +case class Extension(name: String, value: AnyRef) + case class PlaySwaggerConfig( title: String, version: String, @@ -15,7 +19,8 @@ case class PlaySwaggerConfig( host: String, basePath: String, schemes: Seq[String], - filterClass: Option[String] + filterClass: Option[String], + vendorExtensions: List[Extension] ) { // Java APIs for reading the configuration def getSchemes: Array[String] = schemes.toArray @@ -37,7 +42,12 @@ object PlaySwaggerConfig { termsOfServiceUrl = configuration.get[String]("swagger.api.info.termsOfServiceUrl"), license = configuration.get[String]("swagger.api.info.license"), licenseUrl = configuration.get[String]("swagger.api.info.licenseUrl"), - filterClass = configuration.get[Option[String]]("swagger.filter") + filterClass = configuration.get[Option[String]]("swagger.filter"), + vendorExtensions = configuration.get[Option[Config]]("swagger.api.info").toList.map(_.entrySet()).flatMap { entries => + entries.asScala.filter(_.getKey.startsWith("x-")).map { entry => + Extension(entry.getKey, entry.getValue.unwrapped()) + }.toList.reverse + } ) } diff --git a/src/test/scala/PlayApiListingCacheSpec.scala b/src/test/scala/PlayApiListingCacheSpec.scala index 1b2cf46..f92a038 100644 --- a/src/test/scala/PlayApiListingCacheSpec.scala +++ b/src/test/scala/PlayApiListingCacheSpec.scala @@ -1,5 +1,6 @@ import java.io.File +import com.typesafe.config.ConfigValueFactory import io.swagger.config.ScannerFactory import io.swagger.models.{HttpMethod, ModelImpl} import io.swagger.models.parameters.{BodyParameter, PathParameter, QueryParameter} @@ -57,7 +58,8 @@ PUT /api/dog/api/:id testdata.DogController.add0(id:String) license = "license", licenseUrl = "http://licenseUrl", filterClass = None, - schemes = Seq.empty + schemes = Seq.empty, + vendorExtensions = List(Extension("x-api-key","test"), Extension("x-tags", java.util.Arrays.asList("api", "secure","test"))) ) val env = Environment.simple() @@ -90,6 +92,7 @@ PUT /api/dog/api/:id testdata.DogController.add0(id:String) swagger.getInfo.getTermsOfService must beEqualTo(swaggerConfig.termsOfServiceUrl) swagger.getInfo.getLicense.getName must beEqualTo(swaggerConfig.license) swagger.getSecurityDefinitions.size() must beEqualTo(1) + swagger.getInfo.getVendorExtensions.size() must beEqualTo(2) val pathDoc = swagger.getPaths.get("/document/{settlementId}/files/{fileId}/accept") pathDoc.getOperations.size must beEqualTo(1) From 299a868737a7e4a6726a09c0c8d07593ef17f700 Mon Sep 17 00:00:00 2001 From: Gabriel Ciuloaica Date: Fri, 27 Dec 2019 16:46:59 +0200 Subject: [PATCH 7/9] ref #214 - Vendor Extensions support in API Info --- src/test/resources/reference.conf | 21 ++++++++++++++++ .../scala/PlayApiInfoConfigParserSpec.scala | 25 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/test/resources/reference.conf create mode 100644 src/test/scala/PlayApiInfoConfigParserSpec.scala diff --git a/src/test/resources/reference.conf b/src/test/resources/reference.conf new file mode 100644 index 0000000..1d33c4a --- /dev/null +++ b/src/test/resources/reference.conf @@ -0,0 +1,21 @@ + +api.version = beta + +swagger.filter = null +swagger.api { + basepath = "/" + host = "localhost:9000" + title = "Test API" + schemes = [] + + info { + title = "Test" + description = "Test API endpoint" + termsOfServiceUrl = "" + contact = "test@test.com" + license = "Apache2" + licenseUrl = "http://licenseUrl" # needs to be a valid url to validate against schema + x-api-key: "test" + x-tags: ["test", "api"] + } +} diff --git a/src/test/scala/PlayApiInfoConfigParserSpec.scala b/src/test/scala/PlayApiInfoConfigParserSpec.scala new file mode 100644 index 0000000..7fe9aa3 --- /dev/null +++ b/src/test/scala/PlayApiInfoConfigParserSpec.scala @@ -0,0 +1,25 @@ +import com.typesafe.config.ConfigFactory +import org.specs2.mutable.Specification +import play.modules.swagger.PlaySwaggerConfig + +class PlayApiInfoConfigParserSpec extends Specification { + + private val config = ConfigFactory.load() + + "API Info " should { + "proper build Info object" in { + val probe = PlaySwaggerConfig(config) + probe.title === "Test" + probe.description === "Test API endpoint" + probe.termsOfServiceUrl.isEmpty === true + probe.contact === "test@test.com" + probe.license === "Apache2" + probe.licenseUrl === "http://licenseUrl" + probe.vendorExtensions.size shouldEqual(2) + probe.vendorExtensions.head.name === "x-api-key" + probe.vendorExtensions.head.value === "test" + probe.vendorExtensions.tail.head.name === "x-tags" + probe.vendorExtensions.tail.head.value === java.util.Arrays.asList("test", "api") + } + } +} From 597b77dfc977fe05b42aca5df6f791dbf6883804 Mon Sep 17 00:00:00 2001 From: Gabriel Ciuloaica Date: Mon, 30 Dec 2019 09:40:34 +0200 Subject: [PATCH 8/9] removed vendor extensions from reference and downgreaded play-ebean to fix scala 2.11.x compilation --- build.sbt | 2 +- src/main/resources/reference.conf | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 873c279..42a6716 100644 --- a/build.sbt +++ b/build.sbt @@ -18,7 +18,7 @@ libraryDependencies ++= Seq( "org.scala-lang.modules" %% "scala-collection-compat" % "2.1.2", "org.slf4j" % "slf4j-api" % "1.7.21", - "com.typesafe.play" %% "play-ebean" % "5.0.2" % "test", + "com.typesafe.play" %% "play-ebean" % "5.0.1" % "test", "org.specs2" %% "specs2-core" % Specs2Version % "test", "org.specs2" %% "specs2-mock" % Specs2Version % "test", "org.specs2" %% "specs2-junit" % Specs2Version % "test", diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 9c9c361..cafebac 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -15,7 +15,5 @@ swagger.api { contact = "" license = "" licenseUrl = "http://licenseUrl" # needs to be a valid url to validate against schema - x-api-key: "test" - x-tags: ["api", "secure"] } } From 9eaeb99c4bab84754e05f7b240595f4ec2b66fbb Mon Sep 17 00:00:00 2001 From: Gabriel Ciuloaica Date: Mon, 30 Dec 2019 09:45:10 +0200 Subject: [PATCH 9/9] removed default vendor extensions from reference --- src/main/resources/reference.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index 9c9c361..cafebac 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -15,7 +15,5 @@ swagger.api { contact = "" license = "" licenseUrl = "http://licenseUrl" # needs to be a valid url to validate against schema - x-api-key: "test" - x-tags: ["api", "secure"] } }