forked from broadinstitute/cromwell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swagger CodeGen for WaaS [BA-5746] (broadinstitute#5038)
* Swagger CodeGen for WaaS * addressed PR feedback * more PR feedback * instructions for generating and publishing swagger client libraries
- Loading branch information
Showing
8 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Publishing._ | ||
import Version._ | ||
|
||
lazy val root = (project in file(".")). | ||
settings( | ||
Seq(organization := "org.broadinstitute.cromwell", | ||
name := "cromwell-client", | ||
version := createVersion("0.1"), | ||
scalaVersion := "2.12.8", | ||
scalacOptions ++= Seq("-feature"), | ||
javacOptions in compile ++= Seq("-Xlint:deprecation"), | ||
publishArtifact in (Compile, packageDoc) := false, | ||
resolvers += Resolver.mavenLocal, | ||
updateOptions := updateOptions.value.withGigahorse(false), | ||
libraryDependencies ++= Seq( | ||
"io.swagger" % "swagger-annotations" % "1.5.21", | ||
"com.squareup.okhttp3" % "okhttp" % "3.12.1", | ||
"com.squareup.okhttp3" % "logging-interceptor" % "3.12.1", | ||
"com.google.code.gson" % "gson" % "2.8.5", | ||
"org.apache.commons" % "commons-lang3" % "3.8.1", | ||
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.1", | ||
"org.threeten" % "threetenbp" % "1.3.5" % "compile", | ||
"io.gsonfire" % "gson-fire" % "1.8.0" % "compile", | ||
"junit" % "junit" % "4.12" % "test", | ||
"com.novocode" % "junit-interface" % "0.10" % "test" | ||
)) ++ publishSettings:_* | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
object Artifactory { | ||
val artifactoryHost = "broadinstitute.jfrog.io" | ||
val artifactory = s"https://$artifactoryHost/broadinstitute/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import sbt.Keys._ | ||
import sbt._ | ||
import Artifactory._ | ||
|
||
object Publishing { | ||
private val buildTimestamp = System.currentTimeMillis() / 1000 | ||
|
||
private def artifactoryResolver(isSnapshot: Boolean): Resolver = { | ||
val repoType = if (isSnapshot) "snapshot" else "release" | ||
val repoUrl = | ||
s"${artifactory}libs-$repoType-local;build.timestamp=$buildTimestamp" | ||
val repoName = "artifactory-publish" | ||
repoName at repoUrl | ||
} | ||
|
||
private val artifactoryCredentials: Credentials = { | ||
val username = sys.env.getOrElse("ARTIFACTORY_USERNAME", "") | ||
val password = sys.env.getOrElse("ARTIFACTORY_PASSWORD", "") | ||
Credentials("Artifactory Realm", artifactoryHost, username, password) | ||
} | ||
|
||
val publishSettings: Seq[Setting[_]] = | ||
//we only publish to libs-release-local because of a bug in sbt that makes snapshots take | ||
//priority over the local package cache. see here: https://github.com/sbt/sbt/issues/2687#issuecomment-236586241 | ||
Seq( | ||
publishTo := Option(artifactoryResolver(false)), | ||
publishArtifact in Compile := true, | ||
publishArtifact in Test := true, | ||
credentials += artifactoryCredentials | ||
) | ||
|
||
val noPublishSettings: Seq[Setting[_]] = | ||
Seq( | ||
publish := {}, | ||
publishLocal := {} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import scala.sys.process._ | ||
|
||
object Version { | ||
|
||
def createVersion(baseVersion: String) = { | ||
def getLastCommitFromGit = { s"""git rev-parse --short HEAD""" !! } | ||
|
||
// either specify git hash as an env var or derive it | ||
// if building from the broadinstitute/scala-baseimage docker image use env var | ||
// (scala-baseimage doesn't have git in it) | ||
val lastCommit = sys.env.getOrElse("GIT_HASH", getLastCommitFromGit ).trim() | ||
val version = baseVersion + "-" + lastCommit | ||
|
||
// The project isSnapshot string passed in via command line settings, if desired. | ||
val isSnapshot = sys.props.getOrElse("project.isSnapshot", "true").toBoolean | ||
|
||
// For now, obfuscate SNAPSHOTs from sbt's developers: https://github.com/sbt/sbt/issues/2687#issuecomment-236586241 | ||
if (isSnapshot) s"$version-SNAP" else version | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.2.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
set -e | ||
|
||
BASE_PACKAGE="cromwell.client" | ||
|
||
ORIGINAL_API_YAML=engine/src/main/resources/swagger/cromwell.yaml | ||
API_YAML=codegen_java/cromwell.nofile.yaml | ||
|
||
# Cromwell doesn't specify the OAuth configuration in it's swagger, and | ||
# without it the client doesn't support authentication. | ||
cat << EOF > $API_YAML | ||
security: | ||
- googleoauth: | ||
- openid | ||
- profile | ||
securityDefinitions: | ||
googleoauth: | ||
type: oauth2 | ||
authorizationUrl: 'https://accounts.google.com/o/oauth2/auth' | ||
flow: implicit | ||
scopes: | ||
openid: open id authorization | ||
email: email authorization | ||
profile: profile authorization | ||
EOF | ||
|
||
# Swagger autogenerates clients that match the input types, and for File | ||
# that is less than useful because clients need to supply their inputs as | ||
# File, which means actually making a file. Replacing with 'string' has nearly | ||
# the same HTTP semantics, except for suppling the name of the client-side file | ||
# itself, but is much more usable to a client. | ||
cat $ORIGINAL_API_YAML | sed s/type:\ file/type:\ string/g >> $API_YAML | ||
|
||
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \ | ||
-i /local/$API_YAML \ | ||
-g java \ | ||
-o /local/codegen_java \ | ||
--skip-validate-spec \ | ||
--api-package ${BASE_PACKAGE}.api \ | ||
--model-package ${BASE_PACKAGE}.model | ||
|
||
cd codegen_java | ||
|
||
sbt test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# sbt publish publishes libs to Artifactory for the scala version sbt is running as. | ||
# sbt +publish publishes libs to Artifactory for all scala versions listed in crossScalaVersions. | ||
# We only do sbt publish here because Travis runs against 2.11 and 2.12 in separate jobs, so each one publishes its version to Artifactory. | ||
cd codegen_java | ||
if [[ "$TRAVIS_PULL_REQUEST" == "false" && "$TRAVIS_BRANCH" == "develop" ]]; then | ||
sbt -Dproject.isSnapshot=false "+ publish" | ||
else | ||
sbt -Dproject.isSnapshot=true "+ publish" | ||
fi |