-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate enum values as uppercase types for better Scala 3 compat
- Update dependencies Co-authored-by: Andreas Drobisch <[email protected]> Co-authored-by: Saskia Gennrich <[email protected]>
- Loading branch information
1 parent
a624771
commit 22800bd
Showing
33 changed files
with
185 additions
and
128 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 |
---|---|---|
|
@@ -25,7 +25,7 @@ jobs: | |
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
scala: [2.12.19] | ||
scala: [2.12.20] | ||
java: [[email protected]+7] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
|
@@ -63,7 +63,7 @@ jobs: | |
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
scala: [2.12.19] | ||
scala: [2.12.20] | ||
java: [[email protected]+7] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
|
@@ -80,12 +80,12 @@ jobs: | |
java-version: 15.0.2+7 | ||
cache: sbt | ||
|
||
- name: Download target directories (2.12.19) | ||
- name: Download target directories (2.12.20) | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: target-${{ matrix.os }}-2.12.19-${{ matrix.java }} | ||
name: target-${{ matrix.os }}-2.12.20-${{ matrix.java }} | ||
|
||
- name: Inflate target directories (2.12.19) | ||
- name: Inflate target directories (2.12.20) | ||
run: | | ||
tar xf targets.tar | ||
rm targets.tar | ||
|
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=1.6.2 | ||
sbt.version=1.10.5 |
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 |
---|---|---|
@@ -1,84 +1,84 @@ | ||
package examples | ||
|
||
import akka.actor.ActorSystem | ||
import akka.http.scaladsl.Http | ||
import cats.effect.{ExitCode, IO, IOApp} | ||
import scraml.examples.{DataType, Endpoints, SomeEnum} | ||
import scraml.examples.Endpoints.Greeting.GetGreetingParams | ||
import sttp.client3.SttpBackend | ||
import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend | ||
import sttp.model.{Header, StatusCode} | ||
import sttp.tapir.DecodeResult.{Failure, Value} | ||
import sttp.tapir.client.sttp.WebSocketToPipe | ||
|
||
import scala.concurrent.Future | ||
|
||
class GreetingClient(apiUrl: String)(backend: SttpBackend[IO, Any])(implicit wsToPipe: WebSocketToPipe[Any]) { | ||
import sttp.client3._ | ||
import sttp.tapir._ | ||
import sttp.tapir.client.sttp.SttpClientInterpreter | ||
|
||
private lazy val client = SttpClientInterpreter() | ||
private def authenticate: IO[String] = IO.pure("sometoken") | ||
|
||
def getGreeting(params: GetGreetingParams): IO[DataType] = for { | ||
accessToken <- authenticate | ||
// adding an input and output to the endpoint to access headers and to provide an access token (checking not implemented) | ||
response <- client.toClient(Endpoints.Greeting.getGreeting.in(auth.bearer[String]()).out(headers), Some(uri"$apiUrl"), backend)(wsToPipe)(params, accessToken) | ||
result <- response match { | ||
case Value(value) => IO.fromEither(value.left.map(error => new RuntimeException(s"error in $response: $error"))) | ||
case error: Failure => IO.raiseError(new RuntimeException(s"error while getting greeting: $error")) | ||
} | ||
(data, headers) = result | ||
_ <- IO(println(s"got headers: $headers")) | ||
} yield data | ||
} | ||
|
||
object GreetingClient { | ||
def apply(apiUrl: String): IO[(GreetingClient, SttpBackend[IO, Any])] = | ||
AsyncHttpClientCatsBackend[IO]().flatMap(backend => IO((new GreetingClient(apiUrl)(backend), backend))) | ||
} | ||
|
||
object GreetingServer { | ||
import sttp.tapir._ | ||
import sttp.tapir.server.akkahttp.AkkaHttpServerInterpreter | ||
import scala.concurrent.Future | ||
import akka.http.scaladsl.server.Route | ||
|
||
def getGreeting(params: GetGreetingParams): Future[Either[Unit, (DataType, StatusCode, List[Header])]] = | ||
Future.successful(Right((DataType(params.name.getOrElse("no input"), customTypeProp = BigDecimal(42)), StatusCode.Ok, List(Header("custom-header", "value"))))) | ||
|
||
implicit val httpSystem: ActorSystem = ActorSystem("http") | ||
|
||
import httpSystem.dispatcher | ||
|
||
// adding outputs to provide statusCode and headers in the implementation | ||
val greetingWithStatusAndHeaders = Endpoints.Greeting.getGreeting.out(statusCode and sttp.tapir.headers) | ||
|
||
val greetingRoute: Route = | ||
AkkaHttpServerInterpreter().toRoute(greetingWithStatusAndHeaders.serverLogic(getGreeting)) | ||
|
||
def startServer: IO[Http.ServerBinding] = | ||
IO.fromFuture(IO(Http().newServerAt("localhost", 8080).bind(greetingRoute))) | ||
} | ||
|
||
object GreetingApp extends IOApp { | ||
implicit class FutureOps[T](future: => Future[T]) { | ||
def toIO: IO[T] = IO.fromFuture(IO(future)) | ||
} | ||
|
||
override def run(args: List[String]): IO[ExitCode] = for { | ||
binding <- GreetingServer.startServer | ||
(clientWithBackend) <- GreetingClient( | ||
apiUrl = s"http://${binding.localAddress.getHostName}:${binding.localAddress.getPort}" | ||
) | ||
(client, clientBackend) = clientWithBackend | ||
result <- client.getGreeting(GetGreetingParams(enum_type = SomeEnum.A, name = Some("world"))).attempt | ||
_ <- IO(println(result)) | ||
_ <- | ||
clientBackend | ||
.close() | ||
.guarantee(binding.unbind().toIO.void) | ||
.guarantee(GreetingServer.httpSystem.terminate().toIO.void) | ||
} yield ExitCode.Success | ||
} | ||
//package examples | ||
// | ||
//import org.apache.pekko.actor.ActorSystem | ||
//import org.apache.pekko.http.scaladsl.Http | ||
//import cats.effect.{ExitCode, IO, IOApp} | ||
//import scraml.examples.{DataType, Endpoints, SomeEnum} | ||
//import scraml.examples.Endpoints.Greeting.GetGreetingParams | ||
//import sttp.client3.SttpBackend | ||
//import sttp.client3.asynchttpclient.cats.AsyncHttpClientCatsBackend | ||
//import sttp.model.{Header, StatusCode} | ||
//import sttp.tapir.DecodeResult.{Failure, Value} | ||
//import sttp.tapir.client.sttp.WebSocketToPipe | ||
// | ||
//import scala.concurrent.Future | ||
// | ||
//class GreetingClient(apiUrl: String)(backend: SttpBackend[IO, Any])(implicit wsToPipe: WebSocketToPipe[Any]) { | ||
// import sttp.client3._ | ||
// import sttp.tapir._ | ||
// import sttp.tapir.client.sttp.SttpClientInterpreter | ||
// | ||
// private lazy val client = SttpClientInterpreter() | ||
// private def authenticate: IO[String] = IO.pure("sometoken") | ||
// | ||
// def getGreeting(params: GetGreetingParams): IO[DataType] = for { | ||
// accessToken <- authenticate | ||
// // adding an input and output to the endpoint to access headers and to provide an access token (checking not implemented) | ||
// response <- client.toClient(Endpoints.Greeting.getGreeting.in(auth.bearer[String]()).out(headers), Some(uri"$apiUrl"), backend)(wsToPipe)(params, accessToken) | ||
// result <- response match { | ||
// case Value(value) => IO.fromEither(value.left.map(error => new RuntimeException(s"error in $response: $error"))) | ||
// case error: Failure => IO.raiseError(new RuntimeException(s"error while getting greeting: $error")) | ||
// } | ||
// (data, headers) = result | ||
// _ <- IO(println(s"got headers: $headers")) | ||
// } yield data | ||
//} | ||
// | ||
//object GreetingClient { | ||
// def apply(apiUrl: String): IO[(GreetingClient, SttpBackend[IO, Any])] = | ||
// AsyncHttpClientCatsBackend[IO]().flatMap(backend => IO((new GreetingClient(apiUrl)(backend), backend))) | ||
//} | ||
// | ||
//object GreetingServer { | ||
// import sttp.tapir._ | ||
// import sttp.tapir.server.pekkohttp.PekkoHttpServerInterpreter | ||
// import scala.concurrent.Future | ||
// import org.apache.pekko.http.scaladsl.server.Route | ||
// | ||
// def getGreeting(params: GetGreetingParams): Future[Either[Unit, (DataType, StatusCode, List[Header])]] = | ||
// Future.successful(Right((DataType(params.name.getOrElse("no input"), customTypeProp = BigDecimal(42)), StatusCode.Ok, List(Header("custom-header", "value"))))) | ||
// | ||
// implicit val httpSystem: ActorSystem = ActorSystem("http") | ||
// | ||
// import httpSystem.dispatcher | ||
// | ||
// // adding outputs to provide statusCode and headers in the implementation | ||
// val greetingWithStatusAndHeaders = Endpoints.Greeting.getGreeting.out(statusCode and sttp.tapir.headers) | ||
// | ||
// val greetingRoute: Route = | ||
// PekkoHttpServerInterpreter().toRoute(greetingWithStatusAndHeaders.serverLogic(getGreeting)) | ||
// | ||
// def startServer: IO[Http.ServerBinding] = | ||
// IO.fromFuture(IO(Http().newServerAt("localhost", 8080).bind(greetingRoute))) | ||
//} | ||
// | ||
//object GreetingApp extends IOApp { | ||
// implicit class FutureOps[T](future: => Future[T]) { | ||
// def toIO: IO[T] = IO.fromFuture(IO(future)) | ||
// } | ||
// | ||
// override def run(args: List[String]): IO[ExitCode] = for { | ||
// binding <- GreetingServer.startServer | ||
// (clientWithBackend) <- GreetingClient( | ||
// apiUrl = s"http://${binding.localAddress.getHostName}:${binding.localAddress.getPort}" | ||
// ) | ||
// (client, clientBackend) = clientWithBackend | ||
// result <- client.getGreeting(GetGreetingParams(enum_type = SomeEnum.A, name = Some("world"))).attempt | ||
// _ <- IO(println(result)) | ||
// _ <- | ||
// clientBackend | ||
// .close() | ||
// .guarantee(binding.unbind().toIO.void) | ||
// .guarantee(GreetingServer.httpSystem.terminate().toIO.void) | ||
// } yield ExitCode.Success | ||
//} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.10.0 | ||
sbt.version = 1.10.5 |
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
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
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.6.1 | ||
sbt.version = 1.10.5 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.6.1 | ||
sbt.version = 1.10.5 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.6.1 | ||
sbt.version = 1.10.5 |
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 |
---|---|---|
|
@@ -5,3 +5,5 @@ type: string | |
enum: | ||
- A | ||
- B | ||
- enum | ||
- type |
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 |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version = 1.6.1 | ||
sbt.version = 1.10.5 |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
> compile | ||
$ exists target/scala-2.12/src_managed/main/scraml/datatypes.scala | ||
$ exists target/scala-2.12/src_managed/main/scraml/package.scala | ||
$ exists target/scala-2.13/src_managed/main/scraml/datatypes.scala | ||
$ exists target/scala-2.13/src_managed/main/scraml/package.scala | ||
> run |
Oops, something went wrong.