Skip to content

Commit

Permalink
Merge pull request #6 from electronicarts/tehzhed-bump-finagle-swagger
Browse files Browse the repository at this point in the history
Bump Finagle to 20.10.0; Bump Swagger UI to 3.38.0; Improve test coverage
  • Loading branch information
Daniele Riccardelli authored Jan 7, 2021
2 parents c779ac0 + c3b0326 commit 234ccbc
Show file tree
Hide file tree
Showing 70 changed files with 252 additions and 235 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 1.11
- name: Run tests
run: sbt -Dkara.isSnapshot=true coverage test scripted coverageAggregate coverageReport
- name: Publish coverage report
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
Copyright (C) 2021 Electronic Arts Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ And since a HTTP/JSON API is exposed, you don't necessarily have to deal with th

## Usage

- Add **kara** as a plugin to the sbt project adding a line containing `addSbtPlugin("com.ea.kara" % "kara" % "0.1.0")` in `project/plugins.sbt`.
- Add **kara** as a plugin to the sbt project adding a line containing `addSbtPlugin("com.ea.kara" % "kara" % "0.2.0")` in `project/plugins.sbt`.
- In your project settings in `build.sbt`:
- configure `karaServices = Seq("fully_qualified_service_1", "fully_qualified_service_2, ...)` to indicate the Thrift services Kara should generate Finagle services and Swagger UI for. Services should be listed in `<JAVA_NAMESPACE>.<SERVICE_NAME>` format.
- configure `karaServices := Seq("fully_qualified_service_1", "fully_qualified_service_2, ...)` to indicate the Thrift services Kara should generate Finagle services and Swagger UI for. Services should be listed in `<JAVA_NAMESPACE>.<SERVICE_NAME>` format.
- enable the the plugin with `.enablePlugins(Kara)` on the project that lists the Thrift sources and on which `ScroogeSBT` is enabled.

On compilation (`sbt compile`), a Finagle HTTP service named `Http<SERVICE_NAME>` is generated, which takes as input an instance of a [Scrooge](http://twitter.github.io/scrooge/)-generated Thrift service `<SERVICE_NAME>.MethodPerEndpoint`. All is left to do is to instantiate it in your app and bind it to a Finagle server on a port of your choice.
Expand All @@ -33,7 +33,7 @@ On compilation (`sbt compile`), a Finagle HTTP service named `Http<SERVICE_NAME>
#### project/plugins.sbt

```scala
addSbtPlugin("com.ea.kara" % "kara" % "0.1.0")
addSbtPlugin("com.ea.kara" % "kara" % "0.2.0")
```

#### build.sbt
Expand Down Expand Up @@ -66,9 +66,12 @@ Http.server.serve(":8080", karaSvc)

[Scripted tests](./src/sbt-test/kara/) are a great way to see **kara** in action.

## Swagger UI
## Dependency Map

`kara` v.`0.1.0` employs Swagger UI v.`3.31.1`.
| **kara** | **Swagger UI** | **Finagle / Scrooge** |
|:--------:|:--------------:|:---------------------:|
| 0.2.0 | 3.38.0 | 20.10.0 |
| 0.1.0 | 3.31.1 | 20.5.0 |

## Testing

Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

import sbt._

val finagleVersion = "20.5.0"
val finagleVersion = "20.10.0"

credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")

Expand Down Expand Up @@ -39,10 +39,10 @@ lazy val root = (project in file("."))
publishSettings,
addSbtPlugin("com.twitter" % "scrooge-sbt-plugin" % finagleVersion),
libraryDependencies ++= Seq(
"commons-io" % "commons-io" % "2.7",
"commons-io" % "commons-io" % "2.8.0",
"org.scalatra.scalate" %% "scalate-core" % "1.9.6",
"com.twitter" %% "finagle-http" % finagleVersion % Test,
"io.circe" %% "circe-yaml" % "0.13.0",
"io.circe" %% "circe-yaml" % "0.13.1",
"com.github.pathikrit" %% "better-files" % "3.9.1",
"io.swagger.parser.v3" % "swagger-parser" % "2.0.21" % Test,
"org.scalatest" %% "scalatest" % "3.2.1" % Test
Expand Down
10 changes: 7 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ And since a HTTP/JSON API is exposed, you don't necessarily have to deal with th
## Usage
- Add **kara** as a plugin to the sbt project adding a line containing `addSbtPlugin("com.ea.kara" % "kara" % "@VERSION@")` in `project/plugins.sbt`.
- In your project settings in `build.sbt`:
- configure `karaServices = Seq("fully_qualified_service_1", "fully_qualified_service_2, ...)` to indicate the Thrift services Kara should generate Finagle services and Swagger UI for. Services should be listed in `<JAVA_NAMESPACE>.<SERVICE_NAME>` format.
- configure `karaServices := Seq("fully_qualified_service_1", "fully_qualified_service_2, ...)` to indicate the Thrift services Kara should generate Finagle services and Swagger UI for. Services should be listed in `<JAVA_NAMESPACE>.<SERVICE_NAME>` format.
- enable the the plugin with `.enablePlugins(Kara)` on the project that lists the Thrift sources and on which `ScroogeSBT` is enabled.

On compilation (`sbt compile`), a Finagle HTTP service named `Http<SERVICE_NAME>` is generated, which takes as input an instance of a [Scrooge](http://twitter.github.io/scrooge/)-generated Thrift service `<SERVICE_NAME>.MethodPerEndpoint`. All is left to do is to instantiate it in your app and bind it to a Finagle server on a port of your choice.
Expand Down Expand Up @@ -62,8 +62,12 @@ Http.server.serve(":8080", karaSvc)

[Scripted tests](./src/sbt-test/kara/) are a great way to see **kara** in action.

## Swagger UI
`kara` v.`@VERSION@` employs Swagger UI v.`3.31.1`.
## Dependency Map

| **kara** | **Swagger UI** | **Finagle / Scrooge** |
|:--------:|:--------------:|:---------------------:|
| 0.2.0 | 3.38.0 | 20.10.0 |
| 0.1.0 | 3.31.1 | 20.5.0 |

## Testing
**kara** features two modes of testing:
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.12
sbt.version=1.4.6
2 changes: 1 addition & 1 deletion project/metals.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// DO NOT EDIT! This file is auto-generated.
// This file enables sbt-bloop to create bloop config files.

addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.4-13-408f4d80")
addSbtPlugin("ch.epfl.scala" % "sbt-bloop" % "1.4.6-15-209c2a5c")
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value
Expand Down
10 changes: 8 additions & 2 deletions src/main/resources/swagger/oauth2-redirect.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<!doctype html>
<html lang="en-US">
<title>Swagger UI: OAuth2 Redirect</title>
<body onload="run()">
<head>
<title>Swagger UI: OAuth2 Redirect</title>
</head>
<body>
</body>
</html>
<script>
Expand Down Expand Up @@ -65,4 +67,8 @@
}
window.close();
}

window.addEventListener('DOMContentLoaded', function () {
run();
});
</script>
93 changes: 2 additions & 91 deletions src/main/resources/swagger/swagger-ui-bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/swagger/swagger-ui-bundle.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/resources/swagger/swagger-ui-es-bundle-core.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/main/resources/swagger/swagger-ui-es-bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/swagger/swagger-ui-es-bundle.js.map

Large diffs are not rendered by default.

23 changes: 2 additions & 21 deletions src/main/resources/swagger/swagger-ui-standalone-preset.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/swagger/swagger-ui.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/swagger/swagger-ui.css.map

Large diffs are not rendered by default.

10 changes: 2 additions & 8 deletions src/main/resources/swagger/swagger-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/swagger/swagger-ui.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/resources/templates/package.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

// This file is autogenerated by kara. Do not edit.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/service.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

// This file is autogenerated by kara. Do not edit.
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/Constants.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara
Expand Down
40 changes: 25 additions & 15 deletions src/main/scala/com/ea/kara/Context.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara
Expand Down Expand Up @@ -49,29 +49,39 @@ case class CodegenContext(
val servicePackageAndName: Map[String, Seq[String]] = serviceNames
.map { serviceName =>
serviceName.lastIndexOf(".") match {
case -1 => ("", serviceName)
case index => serviceName.splitAt(index)
case -1 =>
throw new RuntimeException("Provided service names should be qualified by packages.")
case index =>
serviceName.splitAt(index)
}
}
.groupBy(_._1)
.map {
case (k, v) => (k, v.map(_._2.tail))
}

val servicesByDocument = thriftFiles
.flatMap(file =>
file.document.services.map(service => (file.document, service)).filter {
case (document, service) =>
servicePackageAndName
.get(document.javaNamespace)
.exists { serviceNames =>
serviceNames.contains(service.sid.name)
}
}
)
val docToSvc = thriftFiles
.flatMap(file => file.document.services.map(service => (file.document, service)))

val pkgToSvc = servicePackageAndName.flatMap {
case (pkg, names) => names.map((pkg, _))
}
val servicesByDocument: Map[Document, Seq[String]] = pkgToSvc
.map {
case (pkg, name) =>
docToSvc
.find {
case (doc, docSvc) =>
doc.javaNamespace == pkg &&
docSvc.sid.name == name
}
.getOrElse {
throw new RuntimeException(s"No service '$name' found in package '$pkg'.")
}
}
.groupBy(_._1)
.map {
case (k, v) => (k, v.map(_._2.sid.name))
case (k, v) => (k, v.map(_._2.sid.name).toSeq)
}

servicesByDocument
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/Generator.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara
Expand Down
16 changes: 12 additions & 4 deletions src/main/scala/com/ea/kara/Kara.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ object Kara extends AutoPlugin {
}
generator.generateSources()
val sources = listSources()
logger.success(s"Generated Kara sources: ${sources.map(_.name).mkString(", ")}")
logger.success(
s"Generated Kara sources: " +
sources.map(_.getPath()).mkString(", ")
)
sources
} else {
logger.info(
s"Kara sources won't be generated, already existing and up to date: ${oldSources.map(_.name)}"
s"Kara sources won't be generated, already existing and up to date: " +
oldSources.map(_.getPath()).mkString(", ")
)
oldSources
}
Expand All @@ -118,11 +122,15 @@ object Kara extends AutoPlugin {
}
generator.generateResources()
val resources = listResources()
logger.success(s"Generated Kara resources: ${resources.map(_.name).mkString(", ")}")
logger.success(
s"Generated Kara resources: " +
resources.map(_.getPath()).mkString(", ")
)
resources
} else {
logger.info(
s"Kara resources won't be generated, already existing and up to date: ${oldResources.map(_.name)}"
s"Kara resources won't be generated, already existing and up to date: " +
oldResources.map(_.getPath()).mkString(", ")
)
oldResources
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.bindings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.bindings
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/extensions/package.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara
Expand Down
3 changes: 1 addition & 2 deletions src/main/scala/com/ea/kara/oas/OAS.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.oas
Expand All @@ -12,6 +12,5 @@ object OAS {
}

case class OAS(json: Json) {
def asJsonString(): String = json.toString
def asYamlString(): String = json.asYaml.spaces2.toString
}
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/oas/OASBuilder.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.oas
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/parse/ThriftParser.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.parse
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/write/ResourceWriter.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.write
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/ea/kara/write/SourceWriter.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

package com.ea.kara.write
Expand Down
18 changes: 9 additions & 9 deletions src/sbt-test/kara/declaration_order/build.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

import sbt._

val twitterVersion = "19.8.0"
val circeVersion = "0.11.1"
val twitterVersion = "20.10.0"
val circeVersion = "0.13.0"

lazy val root = (project in file("."))
.settings(
scalaVersion := "2.12.8",
scalaVersion := "2.12.12",
libraryDependencies ++= Seq(
"com.twitter" %% "twitter-server" % twitterVersion,
"com.twitter" %% "scrooge-core" % twitterVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion
"com.twitter" %% "twitter-server" % twitterVersion,
"com.twitter" %% "scrooge-core" % twitterVersion,
"io.circe" %% "circe-generic" % circeVersion,
"io.circe" %% "circe-parser" % circeVersion
),
karaServices := Seq(
"com.dirty.StubService"
"com.example.StubService"
)
)
.enablePlugins(Kara)
4 changes: 2 additions & 2 deletions src/sbt-test/kara/declaration_order/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.ea.kara" % "kara" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
* Copyright (C) 2021 Electronic Arts Inc. All rights reserved.
*/

namespace java com.example
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/kara/declaration_order/test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2020 Electronic Arts Inc. All rights reserved.
# Copyright (C) 2021 Electronic Arts Inc. All rights reserved.

# Make sure the generated sources compile
> compile
Loading

0 comments on commit 234ccbc

Please sign in to comment.