Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] zio-http support #1615

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ scala-http4s:
- modules/scala-http4s/src/main/**/*
- project/src/main/scala/modules/scalaHttp4s.scala

scala-zio-http:
- modules/scala-zio-http/*
- modules/scala-zio-http/**/*
- project/src/main/scala/modules/scalaZioHttp.scala

scala-support:
- modules/scala-support/src/main/*
- modules/scala-support/src/main/**/*
Expand Down
7 changes: 7 additions & 0 deletions .github/release-drafter-scala-zio-http.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
_extends: guardrail:.github/release-drafter.yml
name-template: 'scala-zio-http-v$RESOLVED_VERSION'
tag-template: 'scala-zio-http-v$RESOLVED_VERSION'
tag-prefix: scala-zio-http-v
include-paths:
- "modules/scala-zio-http/src/main/"
- "project/src/main/scala/modules/scalaZioHttp.scala"
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
{ framework: 'akka-http', project: 'sample-akkaHttp' },
{ framework: 'http4s', project: 'sample-http4s' },
{ framework: 'http4s-v0.22', project: 'sample-http4s-v0_22' },
{ framework: 'zio-http', project: 'sample-zio-http' },
{ framework: 'akka-http-jackson', project: 'sample-akkaHttpJackson' },
{ framework: 'dropwizard', project: 'sample-dropwizardScala' }
]
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ jobs:
config-name: release-drafter-scala-http4s.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
scala-zio-http:
name: '[scala-zio-http] Draft release'
runs-on: ubuntu-20.04
steps:
- uses: blast-hardcheese/[email protected]
with:
config-name: release-drafter-scala-zio-http.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
scala-support:
name: '[scala-support] Draft release'
runs-on: ubuntu-20.04
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ jobs:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GUARDRAIL_RELEASE_MODULE: ${{ steps.set-project-from-tag.outputs.module }}
- name: 'Publish artifacts [scala-zio-http]'
if: ${{ steps.set-project-from-tag.outputs.module == 'scala-zio-http' }}
run: sbt 'show version' "project guardrail-scala-zio-http" clean compile versionCheck test ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GUARDRAIL_RELEASE_MODULE: ${{ steps.set-project-from-tag.outputs.module }}
- name: 'Publish artifacts [scala-support]'
if: ${{ steps.set-project-from-tag.outputs.module == 'scala-support' }}
run: sbt 'show version' "project guardrail-scala-support" clean compile versionCheck test ci-release
Expand Down
1 change: 1 addition & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ project.includeFilters = [
"modules/scala-akka-http/src/.*\\.scala"
"modules/scala-dropwizard/src/.*\\.scala"
"modules/scala-http4s/src/.*\\.scala"
"modules/scala-zio-http/src/.*\\.scala"
"modules/scala-support/src/.*\\.scala"
]

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project structure
- `scala-akka-http`: Generators for [`akka-http`](https://doc.akka.io/docs/akka-http/current/index.html) clients and servers
- `scala-dropwizard`: Generators for [dropwizard](https://www.dropwizard.io/)
- `scala-http4s`: Generators for [`http4s`](https://http4s.org/) clients and servers
- `scala-zio-http`: Generators for [`zio-http`](https://zio.github.io/zio-http/) clients and servers
- `scala-support`: Language definitions for Scala, as well as circe and Jackson generators

Coding guidelines
Expand Down
12 changes: 10 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ lazy val root = modules.root.project
.dependsOn(core % "compile->compile;test->test")
.dependsOn(javaSupport, scalaSupport)
.dependsOn(javaAsyncHttp, javaDropwizard, javaSpringMvc)
.dependsOn(scalaAkkaHttp, scalaDropwizard, scalaHttp4s)
.dependsOn(scalaAkkaHttp, scalaDropwizard, scalaHttp4s, scalaZioHttp)
.dependsOn(cli)
.aggregate(allDeps, microsite)
.aggregate(
Expand All @@ -113,6 +113,7 @@ lazy val root = modules.root.project
scalaSupport,
scalaAkkaHttp,
scalaHttp4s,
scalaZioHttp,
scalaDropwizard,
)

Expand All @@ -130,7 +131,8 @@ lazy val samples = (project in file("modules/samples"))
scalaAkkaHttpSample,
scalaDropwizardSample,
scalaHttp4sSample,
scalaHttp4sSampleV0_22
scalaHttp4sSampleV0_22,
scalaZioHttpSample,
)

lazy val core = modules.core.project
Expand All @@ -144,6 +146,7 @@ lazy val cli = modules.cli.project
.dependsOn(scalaSupport % "test->compile")
.dependsOn(scalaAkkaHttp % "test->compile")
.dependsOn(scalaHttp4s % "test->compile")
.dependsOn(scalaZioHttp % "test->compile")

lazy val javaSupport = modules.javaSupport.project
.customDependsOn("java-support", core)
Expand Down Expand Up @@ -177,6 +180,10 @@ lazy val scalaHttp4sSample = modules.scalaHttp4s.sample
lazy val scalaHttp4s = modules.scalaHttp4s.project
.customDependsOn("scala-support", scalaSupport)

lazy val scalaZioHttpSample = modules.scalaZioHttp.sample
lazy val scalaZioHttp = modules.scalaZioHttp.project
.customDependsOn("scala-support", scalaSupport)

lazy val scalaDropwizardSample = modules.scalaDropwizard.sample
lazy val scalaDropwizard = modules.scalaDropwizard.project
.customDependsOn("scala-support", scalaSupport)
Expand All @@ -189,6 +196,7 @@ lazy val microsite = baseModule("microsite", "microsite", file("modules/microsit
)
.dependsOn(scalaAkkaHttp)
.dependsOn(scalaHttp4s)
.dependsOn(scalaZioHttp)

watchSources ++= (baseDirectory.value / "modules/sample/src/test" ** "*.scala").get
watchSources ++= (baseDirectory.value / "modules/sample/src/test" ** "*.java").get
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package examples.support

import examples.client.http4s.Implicits
import io.circe.Decoder

class PositiveLong private (val value: Long) extends AnyVal
object PositiveLong {
def apply(value: Long): Option[PositiveLong] = if (value >= 0) Some(new PositiveLong(value)) else None
implicit val showable = Implicits.Show.build[PositiveLong](_.value.toString())
implicit val decodePositiveLong = Decoder.decodeLong.emap(num => PositiveLong.apply(num).toRight(s"${num} is not positive"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package tests.scalatest

import cats.Functor
import cats.data.EitherT
import org.scalactic.source
import org.scalatest._
import org.scalatest.exceptions.{ StackDepthException, TestFailedException }
import scala.language.higherKinds
import scala.language.implicitConversions

trait EitherTValues {

implicit def convertEitherTToValuable[F[_]: Functor, L, R](eitherT: EitherT[F, L, R]) = new EitherTValuable(eitherT)

class EitherTValuable[F[_]: Functor, L, R](eitherT: EitherT[F, L, R]) {
def leftValue(implicit pos: source.Position): F[L] =
eitherT.fold(identity, { _ =>
throw new TestFailedException((_: StackDepthException) => Option.empty[String], Option.empty[Throwable], pos)
})

def rightValue(implicit pos: source.Position): F[R] =
eitherT.fold({ _ =>
throw new TestFailedException((_: StackDepthException) => Option.empty[String], Option.empty[Throwable], pos)
}, identity)
}
}
14 changes: 14 additions & 0 deletions modules/sample-zioHttp/src/test/scala/swagger/Escaping.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package swagger

import org.scalatest.matchers.should.Matchers
import org.scalatest.funsuite.AnyFunSuite
import examples.client.http4s.Implicits
import examples.client.http4s.Http4sImplicits._

class EscapingTest extends AnyFunSuite with Matchers {
test("Properly escape parameters") {
Implicits.Formatter.addPath("foo bar baz") shouldEqual "foo%20bar%20baz"
Implicits.Formatter.addPath("foo/bar") shouldEqual "foo%2Fbar"
Implicits.Formatter.addArg("my key", "3=foo/bar baz!") shouldEqual "&my%20key=3%3Dfoo/bar%20baz%21"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ScalaModuleMapper extends ModuleMapperLoader {
case "http4s" => Some(Set("circe", "http4s"))
case "http4s-v0.23" => Some(Set("circe", "http4s-v0.23"))
case "http4s-v0.22" => Some(Set("circe", "http4s-v0.22"))
case "zio-http" => Some(Set("circe", "zio-http")) // TODO: add and use zio-json instead of circe
case "akka-http-jackson" => Some(Set("akka-http", "jackson"))
case "dropwizard" => Some(Set("dropwizard", "jackson"))
case _ => None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev.guardrail.generators.scala.zio.http.ZioHttpClientGeneratorLoader
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev.guardrail.generators.scala.zio.http.ZioHttpGeneratorLoader
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev.guardrail.generators.scala.zio.http.ZioHttpServerGeneratorLoader
Loading