Skip to content

Commit

Permalink
Merge branch 'master' into aws-cdk-support-poc
Browse files Browse the repository at this point in the history
  • Loading branch information
gzhk committed Feb 5, 2023
2 parents 7800777 + 837c994 commit 599a960
Show file tree
Hide file tree
Showing 141 changed files with 2,148 additions and 594 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ b2c641dce625096839305c65db550ac11c1be0e1

# Scala Steward: Reformat with scalafmt 3.6.1
9ed1c7512fcebb3d74089c275f9a66f9821a0060

# Scala Steward: Reformat with scalafmt 3.7.1
5629d39bd05c54bc957996ca4bf46c4bab1cbd67
23 changes: 5 additions & 18 deletions .github/workflows/scala-steward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ on:

jobs:
scala-steward:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier
key: sbt-cache-${{ runner.os }}-JVM-${{ hashFiles('project/build.properties') }}
cache: 'sbt'
- name: Launch Scala Steward
uses: scala-steward-org/scala-steward-action@v2
with:
Expand All @@ -32,10 +26,3 @@ jobs:
github-token: ${{ secrets.REPO_GITHUB_TOKEN }}
repo-config: .scala-steward.conf
ignore-opts-files: false
- name: Cleanup
run: |
rm -rf "$HOME/.ivy2/local" || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "*-LM-SNAPSHOT*" -delete || true
find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.sbt -name "*.lock" -delete || true
2 changes: 1 addition & 1 deletion .sbtopts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-J-Xmx3500M
-J-Xmx4G
-J-Xss2M
-Dsbt.task.timings=false
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.6.1
version = 3.7.1
maxColumn = 140
runner.dialect = scala3
fileOverride {
Expand Down
25 changes: 21 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
![tapir](https://github.com/softwaremill/tapir/raw/master/banner.png)

# Happy 1.0 birthday, tapir!
# Welcome!

[![Join the chat at https://gitter.im/softwaremill/tapir](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/softwaremill/tapir?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Ideas, suggestions, problems, questions](https://img.shields.io/badge/Discourse-ask%20question-blue)](https://softwaremill.community/c/tapir)
[![CI](https://github.com/softwaremill/tapir/workflows/CI/badge.svg)](https://github.com/softwaremill/tapir/actions?query=workflow%3A%22CI%22)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.softwaremill.sttp.tapir/tapir-core_2.13/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.softwaremill.sttp.tapir/tapir-core_2.13)

Expand Down Expand Up @@ -128,7 +128,7 @@ tapir documentation is available at [tapir.softwaremill.com](http://tapir.softwa
Add the following dependency:

```sbt
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.2.3"
"com.softwaremill.sttp.tapir" %% "tapir-core" % "1.2.7"
```

Then, import:
Expand Down Expand Up @@ -174,7 +174,7 @@ All suggestions welcome :)
See the list of [issues](https://github.com/softwaremill/tapir/issues) and pick one! Or report your own.

If you are having doubts on the *why* or *how* something works, don't hesitate to ask a question on
[gitter](https://gitter.im/softwaremill/tapir) or via github. This probably means that the documentation, scaladocs or
[discourse](https://softwaremill.community/c/tapir) or via github. This probably means that the documentation, scaladocs or
code is unclear and be improved for the benefit of all.

The `core` module needs to remain binary-compatible with earlier versions. To check if your changes meet this requirement,
Expand All @@ -194,6 +194,23 @@ You can test only server/client/doc/other projects using `testServers`, `testCli
To verify that the code snippet in docs compile, run `compileDocumentation`. A full mdoc run is done during a release
(when the documentation is generated).

### Importing into IntelliJ

By default, when importing to IntelliJ, only the Scala 2.13/JVM subprojects will be imported. This is controlled by the `ideSkipProject` setting in `build.sbt` (inside `commonSettings`).

If you'd like to work on a different platform or Scala version, simply change this setting temporarily so that the correct subprojects are imported. For example:

```
// import only Scala 2.13, JS projects
ideSkipProject := (scalaVersion.value != scala2_13) || !thisProjectRef.value.project.contains("JS")
// import only Scala 3, JVM projects
ideSkipProject := (scalaVersion.value != scala3) || thisProjectRef.value.project.contains("JS") || thisProjectRef.value.project.contains("Native"),
// import only Scala 2.13, Native projects
ideSkipProject := (scalaVersion.value != scala2_13) || !thisProjectRef.value.project.contains("Native")
```

## Commercial Support

We offer commercial support for tapir and related technologies, as well as development services. [Contact us](https://softwaremill.com) to learn more about our offer!
Expand Down
111 changes: 72 additions & 39 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.sys.process.Process

val scala2_12 = "2.12.17"
val scala2_13 = "2.13.10"
val scala3 = "3.2.1"
val scala3 = "3.2.2"

val scala2Versions = List(scala2_12, scala2_13)
val scala2_13and3Versions = List(scala2_13, scala3)
Expand Down Expand Up @@ -101,7 +101,13 @@ val enableMimaSettings = Seq(
val commonJvmSettings: Seq[Def.Setting[_]] = commonSettings ++ Seq(
Compile / unmanagedSourceDirectories ++= versionedScalaJvmSourceDirectories((Compile / sourceDirectory).value, scalaVersion.value),
Test / unmanagedSourceDirectories ++= versionedScalaJvmSourceDirectories((Test / sourceDirectory).value, scalaVersion.value),
Test / testOptions += Tests.Argument("-oD") // js has other options which conflict with timings
Test / testOptions += Tests.Argument("-oD"), // js has other options which conflict with timings
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Seq("-target:jvm-1.8") // some users are on java 8
case _ => Seq.empty[String]
}
}
)

// run JS tests inside Gecko, due to jsdom not supporting fetch and to avoid having to install node
Expand Down Expand Up @@ -179,6 +185,8 @@ lazy val rawAllAggregates = core.projectRefs ++
vertxServerZio1.projectRefs ++
nettyServer.projectRefs ++
nettyServerCats.projectRefs ++
nettyServerZio.projectRefs ++
nettyServerZio1.projectRefs ++
zio1HttpServer.projectRefs ++
zioHttpServer.projectRefs ++
awsLambda.projectRefs ++
Expand Down Expand Up @@ -350,7 +358,7 @@ lazy val core: ProjectMatrix = (projectMatrix in file("core"))
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq("com.softwaremill.magnolia1_3" %%% "magnolia" % "1.2.0")
Seq("com.softwaremill.magnolia1_3" %%% "magnolia" % "1.2.6")
case _ =>
Seq(
"com.softwaremill.magnolia1_2" %%% "magnolia" % "1.1.2",
Expand Down Expand Up @@ -448,7 +456,7 @@ lazy val perfTests: ProjectMatrix = (projectMatrix in file("perf-tests"))
name := "tapir-perf-tests",
libraryDependencies ++= Seq(
"io.gatling.highcharts" % "gatling-charts-highcharts" % "3.8.4" % "test",
"io.gatling" % "gatling-test-framework" % "3.8.4" % "test",
"io.gatling" % "gatling-test-framework" % "3.9.0" % "test",
"com.typesafe.akka" %% "akka-http" % Versions.akkaHttp,
"com.typesafe.akka" %% "akka-stream" % Versions.akkaStreams,
"org.http4s" %% "http4s-blaze-server" % Versions.http4sBlazeServer,
Expand Down Expand Up @@ -526,11 +534,17 @@ lazy val enumeratum: ProjectMatrix = (projectMatrix in file("integrations/enumer
libraryDependencies ++= Seq(
"com.beachape" %%% "enumeratum" % Versions.enumeratum,
scalaTest.value % Test
)
),
Test / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq("-Yretain-trees")
case _ => Seq()
}
}
)
.jvmPlatform(scalaVersions = scala2Versions)
.jvmPlatform(scalaVersions = scala2And3Versions)
.jsPlatform(
scalaVersions = scala2Versions,
scalaVersions = scala2And3Versions,
settings = commonJsSettings ++ Seq(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % Versions.jsScalaJavaTime % Test
Expand Down Expand Up @@ -566,14 +580,18 @@ lazy val zio1: ProjectMatrix = (projectMatrix in file("integrations/zio1"))
name := "tapir-zio1",
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % Versions.zio1,
"dev.zio" %% "zio-streams" % Versions.zio1,
"dev.zio" %% "zio-test" % Versions.zio1 % Test,
"dev.zio" %% "zio-test-sbt" % Versions.zio1 % Test,
"com.softwaremill.sttp.shared" %% "zio1" % Versions.sttpShared
"dev.zio" %%% "zio" % Versions.zio1,
"dev.zio" %%% "zio-streams" % Versions.zio1,
"dev.zio" %%% "zio-test" % Versions.zio1 % Test,
"dev.zio" %%% "zio-test-sbt" % Versions.zio1 % Test,
"com.softwaremill.sttp.shared" %%% "zio1" % Versions.sttpShared
)
)
.jvmPlatform(scalaVersions = scala2And3Versions)
.jsPlatform(
scalaVersions = scala2And3Versions,
settings = commonJsSettings
)
.dependsOn(core, serverCore % Test)

lazy val zio: ProjectMatrix = (projectMatrix in file("integrations/zio"))
Expand All @@ -582,14 +600,18 @@ lazy val zio: ProjectMatrix = (projectMatrix in file("integrations/zio"))
name := "tapir-zio",
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % Versions.zio,
"dev.zio" %% "zio-streams" % Versions.zio,
"dev.zio" %% "zio-test" % Versions.zio % Test,
"dev.zio" %% "zio-test-sbt" % Versions.zio % Test,
"com.softwaremill.sttp.shared" %% "zio" % Versions.sttpShared
"dev.zio" %%% "zio" % Versions.zio,
"dev.zio" %%% "zio-streams" % Versions.zio,
"dev.zio" %%% "zio-test" % Versions.zio % Test,
"dev.zio" %%% "zio-test-sbt" % Versions.zio % Test,
"com.softwaremill.sttp.shared" %%% "zio" % Versions.sttpShared
)
)
.jvmPlatform(scalaVersions = scala2And3Versions)
.jsPlatform(
scalaVersions = scala2And3Versions,
settings = commonJsSettings
)
.dependsOn(core, serverCore % Test)

lazy val derevo: ProjectMatrix = (projectMatrix in file("integrations/derevo"))
Expand Down Expand Up @@ -773,8 +795,8 @@ lazy val jsoniterScala: ProjectMatrix = (projectMatrix in file("json/jsoniter"))
.settings(
name := "tapir-jsoniter-scala",
libraryDependencies ++= Seq(
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.18.1",
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % "2.18.1" % Test,
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.20.2",
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % "2.20.2" % Test,
scalaTest.value % Test
)
)
Expand Down Expand Up @@ -1210,7 +1232,7 @@ lazy val finatraServer: ProjectMatrix = (projectMatrix in file("server/finatra-s
name := "tapir-finatra-server",
libraryDependencies ++= Seq(
"com.twitter" %% "finatra-http-server" % Versions.finatra,
"org.apache.httpcomponents" % "httpmime" % "4.5.13",
"org.apache.httpcomponents" % "httpmime" % "4.5.14",
// Testing
"com.twitter" %% "inject-server" % Versions.finatra % Test,
"com.twitter" %% "inject-app" % Versions.finatra % Test,
Expand Down Expand Up @@ -1252,28 +1274,34 @@ lazy val nettyServer: ProjectMatrix = (projectMatrix in file("server/netty-serve
.settings(commonJvmSettings)
.settings(
name := "tapir-netty-server",
libraryDependencies ++= Seq(
"io.netty" % "netty-all" % "4.1.82.Final"
) ++ loggerDependencies,
libraryDependencies ++= Seq("io.netty" % "netty-all" % Versions.nettyAll)
++ loggerDependencies,
// needed because of https://github.com/coursier/coursier/issues/2016
useCoursier := false
)
.jvmPlatform(scalaVersions = scala2And3Versions)
.dependsOn(serverCore, serverTests % Test)

lazy val nettyServerCats: ProjectMatrix = (projectMatrix in file("server/netty-server/cats"))
.settings(commonJvmSettings)
.settings(
name := "tapir-netty-server-cats",
libraryDependencies ++= Seq(
"io.netty" % "netty-all" % "4.1.82.Final",
"com.softwaremill.sttp.shared" %% "fs2" % Versions.sttpShared
) ++ loggerDependencies,
// needed because of https://github.com/coursier/coursier/issues/2016
useCoursier := false
)
.jvmPlatform(scalaVersions = scala2And3Versions)
.dependsOn(serverCore, nettyServer, cats, serverTests % Test)
lazy val nettyServerCats: ProjectMatrix = nettyServerProject("cats", cats)
.settings(libraryDependencies += "com.softwaremill.sttp.shared" %% "fs2" % Versions.sttpShared)

lazy val nettyServerZio: ProjectMatrix = nettyServerProject("zio", zio)
.settings(libraryDependencies += "dev.zio" %% "zio-interop-cats" % Versions.zioInteropCats)

lazy val nettyServerZio1: ProjectMatrix = nettyServerProject("zio1", zio1)
.settings(libraryDependencies += "dev.zio" %% "zio-interop-cats" % Versions.zio1InteropCats)

def nettyServerProject(proj: String, dependency: ProjectMatrix): ProjectMatrix =
ProjectMatrix(s"nettyServer${proj.capitalize}", file(s"server/netty-server/$proj"))
.settings(commonJvmSettings)
.settings(
name := s"tapir-netty-server-$proj",
libraryDependencies ++= loggerDependencies,
// needed because of https://github.com/coursier/coursier/issues/2016
useCoursier := false
)
.jvmPlatform(scalaVersions = scala2And3Versions)
.dependsOn(nettyServer, dependency, serverTests % Test)

lazy val vertxServer: ProjectMatrix = (projectMatrix in file("server/vertx-server"))
.settings(commonJvmSettings)
Expand Down Expand Up @@ -1333,7 +1361,7 @@ lazy val zioHttpServer: ProjectMatrix = (projectMatrix in file("server/zio-http-
.settings(commonJvmSettings)
.settings(
name := "tapir-zio-http-server",
libraryDependencies ++= Seq("dev.zio" %% "zio-interop-cats" % Versions.zioInteropCats % Test, "dev.zio" %% "zio-http" % "0.0.3")
libraryDependencies ++= Seq("dev.zio" %% "zio-interop-cats" % Versions.zioInteropCats % Test, "dev.zio" %% "zio-http" % "0.0.4")
)
.jvmPlatform(scalaVersions = scala2_13and3Versions)
.dependsOn(serverCore, zio, serverTests % Test)
Expand Down Expand Up @@ -1632,7 +1660,11 @@ lazy val sttpClient: ProjectMatrix = (projectMatrix in file("client/sttp-client"
scalaVersions = scala2And3Versions,
settings = commonJsSettings ++ Seq(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % Versions.jsScalaJavaTime % Test
"io.github.cquiroz" %%% "scala-java-time" % Versions.jsScalaJavaTime % Test,
"com.softwaremill.sttp.client3" %%% "fs2" % Versions.sttp % Test,
"com.softwaremill.sttp.client3" %%% "zio" % Versions.sttp % Test,
"com.softwaremill.sttp.shared" %%% "fs2" % Versions.sttpShared % Optional,
"com.softwaremill.sttp.shared" %%% "zio" % Versions.sttpShared % Optional
)
)
)
Expand Down Expand Up @@ -1752,7 +1784,7 @@ lazy val examples: ProjectMatrix = (projectMatrix in file("examples"))
"com.softwaremill.sttp.client3" %% "async-http-client-backend-zio" % Versions.sttp,
"com.softwaremill.sttp.client3" %% "async-http-client-backend-cats" % Versions.sttp,
"com.softwaremill.sttp.apispec" %% "asyncapi-circe-yaml" % Versions.sttpApispec,
"com.pauldijou" %% "jwt-circe" % Versions.jwtScala,
"com.github.jwt-scala" %% "jwt-circe" % Versions.jwtScala,
"org.mock-server" % "mockserver-netty" % Versions.mockServer,
"io.circe" %% "circe-generic-extras" % Versions.circeGenericExtras,
scalaTest.value
Expand All @@ -1776,6 +1808,7 @@ lazy val examples: ProjectMatrix = (projectMatrix in file("examples"))
zioHttpServer,
nettyServer,
nettyServerCats,
nettyServerZio,
sttpStubServer,
playJson,
prometheusMetrics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import java.io.ByteArrayInputStream
import java.nio.ByteBuffer
import scala.annotation.tailrec

private[sttp] class EndpointToSttpClient[R](clientOptions: SttpClientOptions, wsToPipe: WebSocketToPipe[R]) {
private[sttp] class EndpointToSttpClient[R](clientOptions: SttpClientOptions, wsToPipe: WebSocketToPipe[R])
extends EndpointToSttpClientExtensions {
def toSttpRequest[A, E, O, I](e: Endpoint[A, I, E, O, R], baseUri: Option[Uri]): A => I => Request[DecodeResult[Either[E, O]], R] = {
aParams => iParams =>
val (uri1, req1) =
Expand All @@ -40,7 +41,7 @@ private[sttp] class EndpointToSttpClient[R](clientOptions: SttpClientOptions, ws

val isWebSocket = bodyIsWebSocket(e.output)

def isSuccess(meta: ResponseMetadata) = if (isWebSocket) meta.code == StatusCode.SwitchingProtocols else meta.isSuccess
def isSuccess(meta: ResponseMetadata) = if (isWebSocket) meta.code == webSocketSuccessStatusCode else meta.isSuccess

val responseAs = fromMetadata(
responseAsFromOutputs(e.errorOutput, isWebSocket = false),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package sttp.tapir.client.sttp

import sttp.model.StatusCode

private[sttp] trait EndpointToSttpClientExtensions { this: EndpointToSttpClient[_] =>

/** This needs to be platform-specific due to #2663, as on JS we don't get access to the 101 status code. */
val webSocketSuccessStatusCode: StatusCode = StatusCode.Ok
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sttp.tapir.client.sttp.ws.fs2

import cats.effect.Concurrent
import sttp.capabilities.WebSockets
import sttp.capabilities.fs2.Fs2Streams
import sttp.tapir.client.sttp.WebSocketToPipe

trait TapirSttpClientFs2WebSockets {
implicit def webSocketsSupportedForFs2Streams[F[_]: Concurrent]: WebSocketToPipe[Fs2Streams[F] with WebSockets] =
new WebSocketToFs2Pipe[F, Fs2Streams[F] with WebSockets]
}
Loading

0 comments on commit 599a960

Please sign in to comment.