From 2c136fefae18582b6a5152e9a97ac60822e167db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Thu, 6 Oct 2022 12:25:10 +0200 Subject: [PATCH 01/12] Support more HTTP methods, keep more details about HTTP matching failures --- .../aws/http4s/AwsHttp4sBackend.scala | 13 +++--- .../core/src/smithy4s/http/HttpEndpoint.scala | 32 +++++++++++--- modules/core/src/smithy4s/http/Method.scala | 29 ++++++++----- .../smithy4s/http/internals/PathSpec.scala | 3 +- modules/decline/src/Smithy4sCli.scala | 3 +- .../smithy4s/dynamic/OperationSpec.scala | 4 +- .../http4s/SmithyHttp4sReverseRouter.scala | 23 ++++++---- .../smithy4s/http4s/SmithyHttp4sRouter.scala | 4 +- .../SmithyHttp4sClientEndpoint.scala | 42 ++++++++++++++----- .../SmithyHttp4sServerEndpoint.scala | 24 ++++++++++- .../http4s/src/smithy4s/http4s/package.scala | 13 +++--- 11 files changed, 137 insertions(+), 53 deletions(-) diff --git a/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala b/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala index 9a31ec923..d48fb42e4 100644 --- a/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala +++ b/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala @@ -54,11 +54,14 @@ object AwsHttp4sBackend { for { endpoint <- Uri.fromString(request.uri).liftTo[F] method = request.httpMethod match { - case HttpMethod.POST => POST - case HttpMethod.GET => GET - case HttpMethod.PATCH => PATCH - case HttpMethod.PUT => PUT - case HttpMethod.DELETE => DELETE + case HttpMethod.POST => POST + case HttpMethod.GET => GET + case HttpMethod.PATCH => PATCH + case HttpMethod.PUT => PUT + case HttpMethod.DELETE => DELETE + case HttpMethod.HEAD => HEAD + case HttpMethod.OPTIONS => OPTIONS + case HttpMethod.TRACE => TRACE } req = request.body .foldLeft( diff --git a/modules/core/src/smithy4s/http/HttpEndpoint.scala b/modules/core/src/smithy4s/http/HttpEndpoint.scala index 54c0bf36d..35e773daa 100644 --- a/modules/core/src/smithy4s/http/HttpEndpoint.scala +++ b/modules/core/src/smithy4s/http/HttpEndpoint.scala @@ -38,18 +38,36 @@ object HttpEndpoint { def unapply[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO] - ): Option[HttpEndpoint[I]] = cast(endpoint) + ): Option[HttpEndpoint[I]] = castEither(endpoint).toOption - def cast[Op[_, _, _, _, _], I, E, O, SI, SO]( + @deprecated( + "Use `castEither` which returns more information about the error", + "0.16.3" + ) + private[smithy4s] def cast[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO] - ): Option[HttpEndpoint[I]] = { + ): Option[HttpEndpoint[I]] = castEither(endpoint).toOption + + def castEither[Op[_, _, _, _, _], I, E, O, SI, SO]( + endpoint: Endpoint[Op, I, E, O, SI, SO] + ): Either[HttpEndpointError, HttpEndpoint[I]] = { for { - http <- endpoint.hints.get(Http) - httpMethod <- HttpMethod.fromString(http.method.value) - httpPath <- internals.pathSegments(http.uri.value) + http <- endpoint.hints + .get(Http) + .toRight(HttpEndpointError("Operation doesn't have a @http trait")) + httpMethod <- HttpMethod + .fromString(http.method.value) + .toRight( + HttpEndpointError(s"Couldn't parse HTTP method: ${http.method.value}") + ) + httpPath <- internals + .pathSegments(http.uri.value) + .toRight(HttpEndpointError("Unable to parse HTTP path template")) encoder <- SchemaVisitorPathEncoder( endpoint.input .addHints(http) + ).toRight( + HttpEndpointError("Unable to encode operation input in HTTP path") ) } yield { @@ -62,4 +80,6 @@ object HttpEndpoint { } } + case class HttpEndpointError(message: String) extends Exception(message) + } diff --git a/modules/core/src/smithy4s/http/Method.scala b/modules/core/src/smithy4s/http/Method.scala index c48a15999..c6834b43d 100644 --- a/modules/core/src/smithy4s/http/Method.scala +++ b/modules/core/src/smithy4s/http/Method.scala @@ -18,19 +18,25 @@ package smithy4s.http sealed trait HttpMethod { def showUppercase = this match { - case HttpMethod.PUT => "PUT" - case HttpMethod.POST => "POST" - case HttpMethod.DELETE => "DELETE" - case HttpMethod.GET => "GET" - case HttpMethod.PATCH => "PATCH" + case HttpMethod.PUT => "PUT" + case HttpMethod.POST => "POST" + case HttpMethod.DELETE => "DELETE" + case HttpMethod.GET => "GET" + case HttpMethod.PATCH => "PATCH" + case HttpMethod.HEAD => "HEAD" + case HttpMethod.OPTIONS => "OPTIONS" + case HttpMethod.TRACE => "TRACE" } def showCapitalised = this match { - case HttpMethod.PUT => "Put" - case HttpMethod.POST => "Post" - case HttpMethod.DELETE => "Delete" - case HttpMethod.GET => "Get" - case HttpMethod.PATCH => "Patch" + case HttpMethod.PUT => "Put" + case HttpMethod.POST => "Post" + case HttpMethod.DELETE => "Delete" + case HttpMethod.GET => "Get" + case HttpMethod.PATCH => "Patch" + case HttpMethod.HEAD => "Head" + case HttpMethod.OPTIONS => "Options" + case HttpMethod.TRACE => "Trace" } } @@ -40,6 +46,9 @@ object HttpMethod { case object DELETE extends HttpMethod case object GET extends HttpMethod case object PATCH extends HttpMethod + case object HEAD extends HttpMethod + case object OPTIONS extends HttpMethod + case object TRACE extends HttpMethod val values = List(PUT, POST, DELETE, GET, PATCH) diff --git a/modules/core/test/src/smithy4s/http/internals/PathSpec.scala b/modules/core/test/src/smithy4s/http/internals/PathSpec.scala index 0cbecd44d..db3a59ade 100644 --- a/modules/core/test/src/smithy4s/http/internals/PathSpec.scala +++ b/modules/core/test/src/smithy4s/http/internals/PathSpec.scala @@ -60,9 +60,10 @@ class PathSpec() extends munit.FunSuite { test("Write PathParams for DummyPath") { val result = HttpEndpoint - .cast( + .castEither( DummyPath ) + .toTry .get .path( PathParams( diff --git a/modules/decline/src/Smithy4sCli.scala b/modules/decline/src/Smithy4sCli.scala index f16116287..5b9d79cbd 100644 --- a/modules/decline/src/Smithy4sCli.scala +++ b/modules/decline/src/Smithy4sCli.scala @@ -54,7 +54,8 @@ class Smithy4sCli[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _], F[_]: MonadThrow]( endpoint: Endpoint[Op, _, _, _, _, _] ): List[String] = HttpEndpoint - .cast(endpoint) + .castEither(endpoint) + .toOption .map { httpEndpoint => val path = endpoint.hints .get(Http) diff --git a/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala b/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala index c7700eb20..27425d2b9 100644 --- a/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala +++ b/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala @@ -94,10 +94,10 @@ class OperationSpec() extends munit.FunSuite { val compiled = DynamicSchemaIndex.load(model) val endpoints = compiled.allServices.head.service.endpoints - val httpEndpoints = endpoints.map(HttpEndpoint.cast(_)) + val httpEndpoints = endpoints.map(HttpEndpoint.castEither(_)) expect( - httpEndpoints.forall(_.isDefined) + httpEndpoints.forall(_.isRight) ) } } diff --git a/modules/http4s/src/smithy4s/http4s/SmithyHttp4sReverseRouter.scala b/modules/http4s/src/smithy4s/http4s/SmithyHttp4sReverseRouter.scala index 5724f9f7c..44ad050d6 100644 --- a/modules/http4s/src/smithy4s/http4s/SmithyHttp4sReverseRouter.scala +++ b/modules/http4s/src/smithy4s/http4s/SmithyHttp4sReverseRouter.scala @@ -47,15 +47,20 @@ class SmithyHttp4sReverseRouter[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _], F[_]]( def apply[I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO] ): SmithyHttp4sClientEndpoint[F, Op, I, E, O, SI, SO] = - SmithyHttp4sClientEndpoint( - baseUri, - client, - endpoint, - entityCompiler - ).getOrElse( - sys.error( - s"Operation ${endpoint.name} is not bound to http semantics" + SmithyHttp4sClientEndpoint + .make( + baseUri, + client, + endpoint, + entityCompiler ) - ) + .left + .map { e => + throw new Exception( + s"Operation ${endpoint.name} is not bound to http semantics", + e + ) + } + .merge }.precompute(service.endpoints.map(smithy4s.Kind5.existential(_))) } diff --git a/modules/http4s/src/smithy4s/http4s/SmithyHttp4sRouter.scala b/modules/http4s/src/smithy4s/http4s/SmithyHttp4sRouter.scala index 6192cf160..248994b2c 100644 --- a/modules/http4s/src/smithy4s/http4s/SmithyHttp4sRouter.scala +++ b/modules/http4s/src/smithy4s/http4s/SmithyHttp4sRouter.scala @@ -44,14 +44,14 @@ class SmithyHttp4sRouter[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _], F[_]]( private val http4sEndpoints: List[SmithyHttp4sServerEndpoint[F]] = service.endpoints .map { ep => - SmithyHttp4sServerEndpoint( + SmithyHttp4sServerEndpoint.make( impl, ep, codecs, errorTransformation ) } - .collect { case Some(http4sEndpoint) => + .collect { case Right(http4sEndpoint) => http4sEndpoint } diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala index 5bd88a527..3578f1f8b 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala @@ -40,21 +40,43 @@ private[smithy4s] trait SmithyHttp4sClientEndpoint[F[_], Op[_, _, _, _, _], I, E private[smithy4s] object SmithyHttp4sClientEndpoint { - def apply[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( + @deprecated("Use `make`", "0.16.3") + private[smithy4s] def apply[ + F[_]: EffectCompat, + Op[_, _, _, _, _], + I, + E, + O, + SI, + SO + ]( baseUri: Uri, client: Client[F], endpoint: Endpoint[Op, I, E, O, SI, SO], entityCompiler: EntityCompiler[F] ): Option[SmithyHttp4sClientEndpoint[F, Op, I, E, O, SI, SO]] = - HttpEndpoint.cast(endpoint).map { httpEndpoint => - new SmithyHttp4sClientEndpointImpl[F, Op, I, E, O, SI, SO]( - baseUri, - client, - endpoint, - httpEndpoint, - entityCompiler - ) - } + make(baseUri, client, endpoint, entityCompiler).toOption + + def make[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( + baseUri: Uri, + client: Client[F], + endpoint: Endpoint[Op, I, E, O, SI, SO], + entityCompiler: EntityCompiler[F] + ): Either[ + HttpEndpoint.HttpEndpointError, + SmithyHttp4sClientEndpoint[F, Op, I, E, O, SI, SO] + ] = + HttpEndpoint + .castEither(endpoint) + .map { httpEndpoint => + new SmithyHttp4sClientEndpointImpl[F, Op, I, E, O, SI, SO]( + baseUri, + client, + endpoint, + httpEndpoint, + entityCompiler + ) + } } diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala index 098555f96..6cf742a7c 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala @@ -50,13 +50,33 @@ private[smithy4s] trait SmithyHttp4sServerEndpoint[F[_]] { private[smithy4s] object SmithyHttp4sServerEndpoint { - def apply[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( + @deprecated("Use `make`", "0.16.3") + private[smithy4s] def apply[ + F[_]: EffectCompat, + Op[_, _, _, _, _], + I, + E, + O, + SI, + SO + ]( impl: Interpreter[Op, F], endpoint: Endpoint[Op, I, E, O, SI, SO], codecs: EntityCompiler[F], errorTransformation: PartialFunction[Throwable, F[Throwable]] ): Option[SmithyHttp4sServerEndpoint[F]] = - HttpEndpoint.cast(endpoint).map { httpEndpoint => + make(impl, endpoint, codecs, errorTransformation).toOption + + def make[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( + impl: Interpreter[Op, F], + endpoint: Endpoint[Op, I, E, O, SI, SO], + codecs: EntityCompiler[F], + errorTransformation: PartialFunction[Throwable, F[Throwable]] + ): Either[ + HttpEndpoint.HttpEndpointError, + SmithyHttp4sServerEndpoint[F] + ] = + HttpEndpoint.castEither(endpoint).map { httpEndpoint => new SmithyHttp4sServerEndpointImpl[F, Op, I, E, O, SI, SO]( impl, endpoint, diff --git a/modules/http4s/src/smithy4s/http4s/package.scala b/modules/http4s/src/smithy4s/http4s/package.scala index bfd8d9eba..e604dd54d 100644 --- a/modules/http4s/src/smithy4s/http4s/package.scala +++ b/modules/http4s/src/smithy4s/http4s/package.scala @@ -37,11 +37,14 @@ package object http4s extends Compat.Package { private[smithy4s] def toHttp4sMethod(method: SmithyMethod): Http4sMethod = method match { - case smithy4s.http.HttpMethod.PUT => Http4sMethod.PUT - case smithy4s.http.HttpMethod.POST => Http4sMethod.POST - case smithy4s.http.HttpMethod.DELETE => Http4sMethod.DELETE - case smithy4s.http.HttpMethod.GET => Http4sMethod.GET - case smithy4s.http.HttpMethod.PATCH => Http4sMethod.PATCH + case smithy4s.http.HttpMethod.PUT => Http4sMethod.PUT + case smithy4s.http.HttpMethod.POST => Http4sMethod.POST + case smithy4s.http.HttpMethod.DELETE => Http4sMethod.DELETE + case smithy4s.http.HttpMethod.GET => Http4sMethod.GET + case smithy4s.http.HttpMethod.PATCH => Http4sMethod.PATCH + case smithy4s.http.HttpMethod.HEAD => Http4sMethod.HEAD + case smithy4s.http.HttpMethod.OPTIONS => Http4sMethod.OPTIONS + case smithy4s.http.HttpMethod.TRACE => Http4sMethod.TRACE } private[smithy4s] def toHeaders(mp: Map[CaseInsensitive, Seq[String]]) = From 048d35769c9bb9e3e2f76531a63e597b71c17b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Thu, 6 Oct 2022 12:31:13 +0200 Subject: [PATCH 02/12] empty commit because why From eadbb3a49df9de40e06daed0f682f3bff98a5949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Thu, 6 Oct 2022 13:07:55 +0200 Subject: [PATCH 03/12] Fix bincompat on 2.12 --- modules/core/src/smithy4s/http/HttpEndpoint.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/core/src/smithy4s/http/HttpEndpoint.scala b/modules/core/src/smithy4s/http/HttpEndpoint.scala index 35e773daa..7adaaa8d4 100644 --- a/modules/core/src/smithy4s/http/HttpEndpoint.scala +++ b/modules/core/src/smithy4s/http/HttpEndpoint.scala @@ -44,7 +44,9 @@ object HttpEndpoint { "Use `castEither` which returns more information about the error", "0.16.3" ) - private[smithy4s] def cast[Op[_, _, _, _, _], I, E, O, SI, SO]( + // We can't make it private[smithy4s] because it breaks bincompat on Scala 2.12 + // due to removing a static forwarder. + def cast[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO] ): Option[HttpEndpoint[I]] = castEither(endpoint).toOption From 4d5a842040120d2f1456e5efaec71de36a9268e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Thu, 6 Oct 2022 13:09:41 +0200 Subject: [PATCH 04/12] More verbosity --- modules/core/src/smithy4s/http/HttpEndpoint.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/core/src/smithy4s/http/HttpEndpoint.scala b/modules/core/src/smithy4s/http/HttpEndpoint.scala index 7adaaa8d4..a3ec10e34 100644 --- a/modules/core/src/smithy4s/http/HttpEndpoint.scala +++ b/modules/core/src/smithy4s/http/HttpEndpoint.scala @@ -64,7 +64,11 @@ object HttpEndpoint { ) httpPath <- internals .pathSegments(http.uri.value) - .toRight(HttpEndpointError("Unable to parse HTTP path template")) + .toRight( + HttpEndpointError( + s"Unable to parse HTTP path template: ${http.uri.value}" + ) + ) encoder <- SchemaVisitorPathEncoder( endpoint.input .addHints(http) From 091e7aa30e9fbb5c98feb06bea6d5b35037e1285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Thu, 6 Oct 2022 19:08:53 +0200 Subject: [PATCH 05/12] Move unknown methods into catch-all --- .../aws/http4s/AwsHttp4sBackend.scala | 17 +++---- .../core/src/smithy4s/http/HttpEndpoint.scala | 6 +-- modules/core/src/smithy4s/http/Method.scala | 50 +++++++++++-------- .../SmithyHttp4sClientEndpoint.scala | 28 +++++++---- .../SmithyHttp4sServerEndpoint.scala | 28 +++++++---- .../http4s/src/smithy4s/http4s/package.scala | 20 ++++---- 6 files changed, 85 insertions(+), 64 deletions(-) diff --git a/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala b/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala index d48fb42e4..507efaa73 100644 --- a/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala +++ b/modules/aws-http4s/src/smithy4s/aws/http4s/AwsHttp4sBackend.scala @@ -32,6 +32,7 @@ import org.typelevel.ci.CIString import smithy4s.aws.SimpleHttpClient import smithy4s.http.CaseInsensitive import smithy4s.http.HttpMethod +import org.http4s.Method final class AwsHttp4sBackend[F[_]: Concurrent](client: Client[F]) extends SimpleHttpClient[F] { @@ -53,15 +54,13 @@ object AwsHttp4sBackend { for { endpoint <- Uri.fromString(request.uri).liftTo[F] - method = request.httpMethod match { - case HttpMethod.POST => POST - case HttpMethod.GET => GET - case HttpMethod.PATCH => PATCH - case HttpMethod.PUT => PUT - case HttpMethod.DELETE => DELETE - case HttpMethod.HEAD => HEAD - case HttpMethod.OPTIONS => OPTIONS - case HttpMethod.TRACE => TRACE + method <- request.httpMethod match { + case HttpMethod.POST => POST.pure[F] + case HttpMethod.GET => GET.pure[F] + case HttpMethod.PATCH => PATCH.pure[F] + case HttpMethod.PUT => PUT.pure[F] + case HttpMethod.DELETE => DELETE.pure[F] + case HttpMethod.OTHER(value) => Method.fromString(value).liftTo[F] } req = request.body .foldLeft( diff --git a/modules/core/src/smithy4s/http/HttpEndpoint.scala b/modules/core/src/smithy4s/http/HttpEndpoint.scala index a3ec10e34..8cfe7fa46 100644 --- a/modules/core/src/smithy4s/http/HttpEndpoint.scala +++ b/modules/core/src/smithy4s/http/HttpEndpoint.scala @@ -57,11 +57,7 @@ object HttpEndpoint { http <- endpoint.hints .get(Http) .toRight(HttpEndpointError("Operation doesn't have a @http trait")) - httpMethod <- HttpMethod - .fromString(http.method.value) - .toRight( - HttpEndpointError(s"Couldn't parse HTTP method: ${http.method.value}") - ) + httpMethod = HttpMethod.fromStringOrDefault(http.method.value) httpPath <- internals .pathSegments(http.uri.value) .toRight( diff --git a/modules/core/src/smithy4s/http/Method.scala b/modules/core/src/smithy4s/http/Method.scala index c6834b43d..0295d908d 100644 --- a/modules/core/src/smithy4s/http/Method.scala +++ b/modules/core/src/smithy4s/http/Method.scala @@ -18,25 +18,21 @@ package smithy4s.http sealed trait HttpMethod { def showUppercase = this match { - case HttpMethod.PUT => "PUT" - case HttpMethod.POST => "POST" - case HttpMethod.DELETE => "DELETE" - case HttpMethod.GET => "GET" - case HttpMethod.PATCH => "PATCH" - case HttpMethod.HEAD => "HEAD" - case HttpMethod.OPTIONS => "OPTIONS" - case HttpMethod.TRACE => "TRACE" + case HttpMethod.PUT => "PUT" + case HttpMethod.POST => "POST" + case HttpMethod.DELETE => "DELETE" + case HttpMethod.GET => "GET" + case HttpMethod.PATCH => "PATCH" + case HttpMethod.OTHER(value) => value.toUpperCase } def showCapitalised = this match { - case HttpMethod.PUT => "Put" - case HttpMethod.POST => "Post" - case HttpMethod.DELETE => "Delete" - case HttpMethod.GET => "Get" - case HttpMethod.PATCH => "Patch" - case HttpMethod.HEAD => "Head" - case HttpMethod.OPTIONS => "Options" - case HttpMethod.TRACE => "Trace" + case HttpMethod.PUT => "Put" + case HttpMethod.POST => "Post" + case HttpMethod.DELETE => "Delete" + case HttpMethod.GET => "Get" + case HttpMethod.PATCH => "Patch" + case HttpMethod.OTHER(value) => value.capitalize } } @@ -46,13 +42,25 @@ object HttpMethod { case object DELETE extends HttpMethod case object GET extends HttpMethod case object PATCH extends HttpMethod - case object HEAD extends HttpMethod - case object OPTIONS extends HttpMethod - case object TRACE extends HttpMethod + case class OTHER(value: String) extends HttpMethod val values = List(PUT, POST, DELETE, GET, PATCH) - def fromString(s: String): Option[HttpMethod] = values.find { m => - CaseInsensitive(s) == CaseInsensitive(m.showCapitalised) + @deprecated( + "Use fromStringOrDefault. This method will be removed in a future release.", + "0.16.3" + ) + def fromString(s: String): Option[HttpMethod] = fromStringOption(s) + + def fromStringOrDefault(s: String): HttpMethod = + fromStringOption(s).getOrElse(OTHER(s.toUpperCase)) + + private def fromStringOption(s: String): Option[HttpMethod] = { + val nameCI = CaseInsensitive(s) + + values + .find { m => + nameCI == CaseInsensitive(m.showCapitalised) + } } } diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala index 3578f1f8b..198ffd682 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala @@ -68,14 +68,23 @@ private[smithy4s] object SmithyHttp4sClientEndpoint { ] = HttpEndpoint .castEither(endpoint) - .map { httpEndpoint => - new SmithyHttp4sClientEndpointImpl[F, Op, I, E, O, SI, SO]( - baseUri, - client, - endpoint, - httpEndpoint, - entityCompiler - ) + .flatMap { httpEndpoint => + toHttp4sMethod(httpEndpoint.method) + .leftMap { e => + HttpEndpoint.HttpEndpointError( + "Couldn't parse HTTP method: " + e + ) + } + .map { method => + new SmithyHttp4sClientEndpointImpl[F, Op, I, E, O, SI, SO]( + baseUri, + method, + client, + endpoint, + httpEndpoint, + entityCompiler + ) + } } } @@ -83,6 +92,7 @@ private[smithy4s] object SmithyHttp4sClientEndpoint { // format: off private[smithy4s] class SmithyHttp4sClientEndpointImpl[F[_], Op[_, _, _, _, _], I, E, O, SI, SO]( baseUri: Uri, + method: org.http4s.Method, client: Client[F], endpoint: Endpoint[Op, I, E, O, SI, SO], httpEndpoint: HttpEndpoint[I], @@ -98,8 +108,6 @@ private[smithy4s] class SmithyHttp4sClientEndpointImpl[F[_], Op[_, _, _, _, _], } } - private val method: org.http4s.Method = toHttp4sMethod(httpEndpoint.method) - private val inputSchema: Schema[I] = endpoint.input private val outputSchema: Schema[O] = endpoint.output diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala index 6cf742a7c..a186c0282 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala @@ -76,14 +76,23 @@ private[smithy4s] object SmithyHttp4sServerEndpoint { HttpEndpoint.HttpEndpointError, SmithyHttp4sServerEndpoint[F] ] = - HttpEndpoint.castEither(endpoint).map { httpEndpoint => - new SmithyHttp4sServerEndpointImpl[F, Op, I, E, O, SI, SO]( - impl, - endpoint, - httpEndpoint, - codecs, - errorTransformation - ) + HttpEndpoint.castEither(endpoint).flatMap { httpEndpoint => + toHttp4sMethod(httpEndpoint.method) + .leftMap { e => + HttpEndpoint.HttpEndpointError( + "Couldn't parse HTTP method: " + e + ) + } + .map { method => + new SmithyHttp4sServerEndpointImpl[F, Op, I, E, O, SI, SO]( + impl, + endpoint, + method, + httpEndpoint, + codecs, + errorTransformation + ) + } } } @@ -92,6 +101,7 @@ private[smithy4s] object SmithyHttp4sServerEndpoint { private[smithy4s] class SmithyHttp4sServerEndpointImpl[F[_], Op[_, _, _, _, _], I, E, O, SI, SO]( impl: Interpreter[Op, F], endpoint: Endpoint[Op, I, E, O, SI, SO], + val method: Method, httpEndpoint: HttpEndpoint[I], codecs: EntityCompiler[F], errorTransformation: PartialFunction[Throwable, F[Throwable]] @@ -100,8 +110,6 @@ private[smithy4s] class SmithyHttp4sServerEndpointImpl[F[_], Op[_, _, _, _, _], type ==>[A, B] = Kleisli[F, A, B] - val method: Method = toHttp4sMethod(httpEndpoint.method) - def matches(path: Array[String]): Option[PathParams] = { httpEndpoint.matches(path) } diff --git a/modules/http4s/src/smithy4s/http4s/package.scala b/modules/http4s/src/smithy4s/http4s/package.scala index e604dd54d..0ba6a69ba 100644 --- a/modules/http4s/src/smithy4s/http4s/package.scala +++ b/modules/http4s/src/smithy4s/http4s/package.scala @@ -23,6 +23,8 @@ import org.http4s.{Method => Http4sMethod} import org.typelevel.ci.CIString import smithy4s.http.CaseInsensitive import smithy4s.http.{HttpMethod => SmithyMethod} +import org.http4s.ParseFailure +import cats.implicits._ package object http4s extends Compat.Package { @@ -35,16 +37,16 @@ package object http4s extends Compat.Package { } - private[smithy4s] def toHttp4sMethod(method: SmithyMethod): Http4sMethod = + private[smithy4s] def toHttp4sMethod( + method: SmithyMethod + ): Either[ParseFailure, Http4sMethod] = method match { - case smithy4s.http.HttpMethod.PUT => Http4sMethod.PUT - case smithy4s.http.HttpMethod.POST => Http4sMethod.POST - case smithy4s.http.HttpMethod.DELETE => Http4sMethod.DELETE - case smithy4s.http.HttpMethod.GET => Http4sMethod.GET - case smithy4s.http.HttpMethod.PATCH => Http4sMethod.PATCH - case smithy4s.http.HttpMethod.HEAD => Http4sMethod.HEAD - case smithy4s.http.HttpMethod.OPTIONS => Http4sMethod.OPTIONS - case smithy4s.http.HttpMethod.TRACE => Http4sMethod.TRACE + case smithy4s.http.HttpMethod.PUT => Http4sMethod.PUT.asRight + case smithy4s.http.HttpMethod.POST => Http4sMethod.POST.asRight + case smithy4s.http.HttpMethod.DELETE => Http4sMethod.DELETE.asRight + case smithy4s.http.HttpMethod.GET => Http4sMethod.GET.asRight + case smithy4s.http.HttpMethod.PATCH => Http4sMethod.PATCH.asRight + case smithy4s.http.HttpMethod.OTHER(v) => Http4sMethod.fromString(v) } private[smithy4s] def toHeaders(mp: Map[CaseInsensitive, Seq[String]]) = From 22f9e17db9a87682b2a595cb225e6be2454548ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Thu, 6 Oct 2022 19:19:08 +0200 Subject: [PATCH 06/12] Satisfy MiMa --- build.sbt | 2 +- project/MimaVersionPlugin.scala | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 8245f6cf3..fbcb4a439 100644 --- a/build.sbt +++ b/build.sbt @@ -7,7 +7,7 @@ ThisBuild / commands ++= createBuildCommands(allModules) ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.5.0" ThisBuild / dynverSeparator := "-" ThisBuild / versionScheme := Some("early-semver") -ThisBuild / mimaBaseVersion := "0.16.1" +ThisBuild / mimaBaseVersion := "0.16.2" ThisBuild / testFrameworks += new TestFramework("weaver.framework.CatsEffect") Global / onChangedBuildSource := ReloadOnSourceChanges diff --git a/project/MimaVersionPlugin.scala b/project/MimaVersionPlugin.scala index 78b83876e..41acd3c20 100644 --- a/project/MimaVersionPlugin.scala +++ b/project/MimaVersionPlugin.scala @@ -7,6 +7,8 @@ import scala.sys.process._ import com.github.sbt.git.GitPlugin import com.github.sbt.git.SbtGit.git import scala.util.Try +import com.typesafe.tools.mima.core.ProblemFilters +import com.typesafe.tools.mima.core.IncompatibleResultTypeProblem // Adapted from https://github.com/djspiewak/sbt-spiewak object MimaVersionPlugin extends AutoPlugin { @@ -136,6 +138,11 @@ object MimaVersionPlugin extends AutoPlugin { ) .toSet } - } + }, + mimaBinaryIssueFilters += + // this is private[smithy4s] + ProblemFilters.exclude[IncompatibleResultTypeProblem]( + "smithy4s.http4s.package.toHttp4sMethod" + ) ) } From f5430089c9425726ceeb8a7acf4bffec456387be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Fri, 7 Oct 2022 16:28:19 +0200 Subject: [PATCH 07/12] Remove internal deprecated methods --- .../internals/SmithyHttp4sClientEndpoint.scala | 17 ----------------- .../internals/SmithyHttp4sServerEndpoint.scala | 17 ----------------- 2 files changed, 34 deletions(-) diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala index 198ffd682..89b3fc3f3 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala @@ -40,23 +40,6 @@ private[smithy4s] trait SmithyHttp4sClientEndpoint[F[_], Op[_, _, _, _, _], I, E private[smithy4s] object SmithyHttp4sClientEndpoint { - @deprecated("Use `make`", "0.16.3") - private[smithy4s] def apply[ - F[_]: EffectCompat, - Op[_, _, _, _, _], - I, - E, - O, - SI, - SO - ]( - baseUri: Uri, - client: Client[F], - endpoint: Endpoint[Op, I, E, O, SI, SO], - entityCompiler: EntityCompiler[F] - ): Option[SmithyHttp4sClientEndpoint[F, Op, I, E, O, SI, SO]] = - make(baseUri, client, endpoint, entityCompiler).toOption - def make[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( baseUri: Uri, client: Client[F], diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala index a186c0282..3f3615770 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala @@ -50,23 +50,6 @@ private[smithy4s] trait SmithyHttp4sServerEndpoint[F[_]] { private[smithy4s] object SmithyHttp4sServerEndpoint { - @deprecated("Use `make`", "0.16.3") - private[smithy4s] def apply[ - F[_]: EffectCompat, - Op[_, _, _, _, _], - I, - E, - O, - SI, - SO - ]( - impl: Interpreter[Op, F], - endpoint: Endpoint[Op, I, E, O, SI, SO], - codecs: EntityCompiler[F], - errorTransformation: PartialFunction[Throwable, F[Throwable]] - ): Option[SmithyHttp4sServerEndpoint[F]] = - make(impl, endpoint, codecs, errorTransformation).toOption - def make[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( impl: Interpreter[Op, F], endpoint: Endpoint[Op, I, E, O, SI, SO], From b23d5fca4b282b760d71094f780b51ffb566bf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Fri, 7 Oct 2022 18:56:50 +0200 Subject: [PATCH 08/12] Break stuff --- modules/core/src/smithy4s/Refinement.scala | 3 --- .../core/src/smithy4s/http/HttpEndpoint.scala | 12 +----------- modules/core/src/smithy4s/http/Method.scala | 11 +++-------- .../http/internals/ErrorCodeSchemaVisitor.scala | 2 +- .../StringAndBlobCodecSchemaVisitor.scala | 4 ++-- .../http/internals/URIEncoderDecoder.scala | 1 + .../src/smithy4s/http/internals/package.scala | 2 +- .../src/smithy4s/http/internals/PathSpec.scala | 2 +- modules/decline/src/Smithy4sCli.scala | 2 +- .../src-jvm/smithy4s/dynamic/OperationSpec.scala | 2 +- .../smithy4s/http4s/SimpleProtocolBuilder.scala | 16 ---------------- .../internals/SmithyHttp4sClientEndpoint.scala | 8 ++++---- .../internals/SmithyHttp4sServerEndpoint.scala | 8 ++++---- project/MimaVersionPlugin.scala | 7 +------ 14 files changed, 21 insertions(+), 59 deletions(-) diff --git a/modules/core/src/smithy4s/Refinement.scala b/modules/core/src/smithy4s/Refinement.scala index 8cbd21d68..05c715b3a 100644 --- a/modules/core/src/smithy4s/Refinement.scala +++ b/modules/core/src/smithy4s/Refinement.scala @@ -40,9 +40,6 @@ trait Refinement[A, B] { self => */ def unsafe(a: A): B - @deprecated("use unsafe instead") - def unchecked(a: A): B = unsafe(a) - final val asFunction: A => Either[ConstraintError, B] = (a: A) => apply(a).left.map(msg => diff --git a/modules/core/src/smithy4s/http/HttpEndpoint.scala b/modules/core/src/smithy4s/http/HttpEndpoint.scala index 8cfe7fa46..203859a17 100644 --- a/modules/core/src/smithy4s/http/HttpEndpoint.scala +++ b/modules/core/src/smithy4s/http/HttpEndpoint.scala @@ -38,20 +38,10 @@ object HttpEndpoint { def unapply[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO] - ): Option[HttpEndpoint[I]] = castEither(endpoint).toOption + ): Option[HttpEndpoint[I]] = cast(endpoint).toOption - @deprecated( - "Use `castEither` which returns more information about the error", - "0.16.3" - ) - // We can't make it private[smithy4s] because it breaks bincompat on Scala 2.12 - // due to removing a static forwarder. def cast[Op[_, _, _, _, _], I, E, O, SI, SO]( endpoint: Endpoint[Op, I, E, O, SI, SO] - ): Option[HttpEndpoint[I]] = castEither(endpoint).toOption - - def castEither[Op[_, _, _, _, _], I, E, O, SI, SO]( - endpoint: Endpoint[Op, I, E, O, SI, SO] ): Either[HttpEndpointError, HttpEndpoint[I]] = { for { http <- endpoint.hints diff --git a/modules/core/src/smithy4s/http/Method.scala b/modules/core/src/smithy4s/http/Method.scala index 0295d908d..610e1b19c 100644 --- a/modules/core/src/smithy4s/http/Method.scala +++ b/modules/core/src/smithy4s/http/Method.scala @@ -16,7 +16,7 @@ package smithy4s.http -sealed trait HttpMethod { +sealed trait HttpMethod extends Product with Serializable { def showUppercase = this match { case HttpMethod.PUT => "PUT" case HttpMethod.POST => "POST" @@ -44,13 +44,8 @@ object HttpMethod { case object PATCH extends HttpMethod case class OTHER(value: String) extends HttpMethod - val values = List(PUT, POST, DELETE, GET, PATCH) - - @deprecated( - "Use fromStringOrDefault. This method will be removed in a future release.", - "0.16.3" - ) - def fromString(s: String): Option[HttpMethod] = fromStringOption(s) + val values: List[HttpMethod] = + List(PUT, POST, DELETE, GET, PATCH) def fromStringOrDefault(s: String): HttpMethod = fromStringOption(s).getOrElse(OTHER(s.toUpperCase)) diff --git a/modules/core/src/smithy4s/http/internals/ErrorCodeSchemaVisitor.scala b/modules/core/src/smithy4s/http/internals/ErrorCodeSchemaVisitor.scala index 7ce9f9b68..7d9c3b298 100644 --- a/modules/core/src/smithy4s/http/internals/ErrorCodeSchemaVisitor.scala +++ b/modules/core/src/smithy4s/http/internals/ErrorCodeSchemaVisitor.scala @@ -20,7 +20,7 @@ package internals import smithy4s.schema._ -private[smithy4s] object ErrorCodeSchemaVisitor +private[http] object ErrorCodeSchemaVisitor extends SchemaVisitor.Cached[HttpCode] with SchemaVisitor.Default[HttpCode] { def default[A]: A => Option[Int] = _ => None diff --git a/modules/core/src/smithy4s/http/internals/StringAndBlobCodecSchemaVisitor.scala b/modules/core/src/smithy4s/http/internals/StringAndBlobCodecSchemaVisitor.scala index e7de47c5b..3d71e8d1f 100644 --- a/modules/core/src/smithy4s/http/internals/StringAndBlobCodecSchemaVisitor.scala +++ b/modules/core/src/smithy4s/http/internals/StringAndBlobCodecSchemaVisitor.scala @@ -28,7 +28,7 @@ import StringAndBlobCodecSchemaVisitor._ import smithy.api.HttpPayload import java.nio.ByteBuffer -private[smithy4s] object StringAndBlobCodecSchemaVisitor { +private[http] object StringAndBlobCodecSchemaVisitor { trait SimpleCodec[A] { self => def mediaType: HttpMediaType @@ -89,7 +89,7 @@ private[smithy4s] object StringAndBlobCodecSchemaVisitor { } -private[smithy4s] class StringAndBlobCodecSchemaVisitor +private[http] class StringAndBlobCodecSchemaVisitor extends SchemaVisitor.Default[CodecResult] { override def default[A]: CodecResult[A] = noop diff --git a/modules/core/src/smithy4s/http/internals/URIEncoderDecoder.scala b/modules/core/src/smithy4s/http/internals/URIEncoderDecoder.scala index 8b2a457c7..247f0f56f 100644 --- a/modules/core/src/smithy4s/http/internals/URIEncoderDecoder.scala +++ b/modules/core/src/smithy4s/http/internals/URIEncoderDecoder.scala @@ -20,6 +20,7 @@ package internals import scala.annotation.tailrec +// note: this should be private[http] but it's used in the aws-kernel module too private[smithy4s] object URIEncoderDecoder { val digits: String = "0123456789ABCDEF" diff --git a/modules/core/src/smithy4s/http/internals/package.scala b/modules/core/src/smithy4s/http/internals/package.scala index 4be4f2e23..ddaaafa5f 100644 --- a/modules/core/src/smithy4s/http/internals/package.scala +++ b/modules/core/src/smithy4s/http/internals/package.scala @@ -52,7 +52,7 @@ package object internals { } } - private[smithy4s] def pathSegments( + private[http] def pathSegments( str: String ): Option[Vector[PathSegment]] = { str diff --git a/modules/core/test/src/smithy4s/http/internals/PathSpec.scala b/modules/core/test/src/smithy4s/http/internals/PathSpec.scala index db3a59ade..d56d8b7af 100644 --- a/modules/core/test/src/smithy4s/http/internals/PathSpec.scala +++ b/modules/core/test/src/smithy4s/http/internals/PathSpec.scala @@ -60,7 +60,7 @@ class PathSpec() extends munit.FunSuite { test("Write PathParams for DummyPath") { val result = HttpEndpoint - .castEither( + .cast( DummyPath ) .toTry diff --git a/modules/decline/src/Smithy4sCli.scala b/modules/decline/src/Smithy4sCli.scala index 5b9d79cbd..e07150edb 100644 --- a/modules/decline/src/Smithy4sCli.scala +++ b/modules/decline/src/Smithy4sCli.scala @@ -54,7 +54,7 @@ class Smithy4sCli[Alg[_[_, _, _, _, _]], Op[_, _, _, _, _], F[_]: MonadThrow]( endpoint: Endpoint[Op, _, _, _, _, _] ): List[String] = HttpEndpoint - .castEither(endpoint) + .cast(endpoint) .toOption .map { httpEndpoint => val path = endpoint.hints diff --git a/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala b/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala index 27425d2b9..ae767e6cb 100644 --- a/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala +++ b/modules/dynamic/test/src-jvm/smithy4s/dynamic/OperationSpec.scala @@ -94,7 +94,7 @@ class OperationSpec() extends munit.FunSuite { val compiled = DynamicSchemaIndex.load(model) val endpoints = compiled.allServices.head.service.endpoints - val httpEndpoints = endpoints.map(HttpEndpoint.castEither(_)) + val httpEndpoints = endpoints.map(HttpEndpoint.cast(_)) expect( httpEndpoints.forall(_.isRight) diff --git a/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala b/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala index d78aaf0d9..d96ba91fe 100644 --- a/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala +++ b/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala @@ -59,22 +59,6 @@ abstract class SimpleProtocolBuilder[P](val codecs: CodecAPI)(implicit def client[F[_]: EffectCompat](client: Client[F]) = new ClientBuilder[Alg, Op, F](client, service) - @deprecated( - "Use the ClientBuilder instead, client(client).uri(baseuri).use" - ) - def client[F[_]: EffectCompat]( - http4sClient: Client[F], - baseUri: Uri - ): Either[UnsupportedProtocolError, Monadic[Alg, F]] = - client(http4sClient).uri(baseUri).use - - @deprecated( - "Use the ClientBuilder instead , client(client).uri(baseuri).resource" - ) - def clientResource[F[_]: EffectCompat]( - http4sClient: Client[F], - baseUri: Uri - ): Resource[F, Monadic[Alg, F]] = client(http4sClient).uri(baseUri).resource def routes[F[_]: EffectCompat]( impl: Monadic[Alg, F] diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala index 89b3fc3f3..5cbf7f0e5 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sClientEndpoint.scala @@ -33,12 +33,12 @@ import smithy4s.schema.SchemaAlt * client into a high-level, domain specific function. */ // format: off -private[smithy4s] trait SmithyHttp4sClientEndpoint[F[_], Op[_, _, _, _, _], I, E, O, SI, SO] { +private[http4s] trait SmithyHttp4sClientEndpoint[F[_], Op[_, _, _, _, _], I, E, O, SI, SO] { def send(input: I): F[O] } // format: on -private[smithy4s] object SmithyHttp4sClientEndpoint { +private[http4s] object SmithyHttp4sClientEndpoint { def make[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( baseUri: Uri, @@ -50,7 +50,7 @@ private[smithy4s] object SmithyHttp4sClientEndpoint { SmithyHttp4sClientEndpoint[F, Op, I, E, O, SI, SO] ] = HttpEndpoint - .castEither(endpoint) + .cast(endpoint) .flatMap { httpEndpoint => toHttp4sMethod(httpEndpoint.method) .leftMap { e => @@ -73,7 +73,7 @@ private[smithy4s] object SmithyHttp4sClientEndpoint { } // format: off -private[smithy4s] class SmithyHttp4sClientEndpointImpl[F[_], Op[_, _, _, _, _], I, E, O, SI, SO]( +private[http4s] class SmithyHttp4sClientEndpointImpl[F[_], Op[_, _, _, _, _], I, E, O, SI, SO]( baseUri: Uri, method: org.http4s.Method, client: Client[F], diff --git a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala index 3f3615770..36f9f4a65 100644 --- a/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala +++ b/modules/http4s/src/smithy4s/http4s/internals/SmithyHttp4sServerEndpoint.scala @@ -37,7 +37,7 @@ import smithy4s.schema.Alt * A construct that encapsulates a smithy4s endpoint, and exposes * http4s specific semantics. */ -private[smithy4s] trait SmithyHttp4sServerEndpoint[F[_]] { +private[http4s] trait SmithyHttp4sServerEndpoint[F[_]] { def method: org.http4s.Method def matches(path: Array[String]): Option[PathParams] def run(pathParams: PathParams, request: Request[F]): F[Response[F]] @@ -48,7 +48,7 @@ private[smithy4s] trait SmithyHttp4sServerEndpoint[F[_]] { matches(path).map(this -> _) } -private[smithy4s] object SmithyHttp4sServerEndpoint { +private[http4s] object SmithyHttp4sServerEndpoint { def make[F[_]: EffectCompat, Op[_, _, _, _, _], I, E, O, SI, SO]( impl: Interpreter[Op, F], @@ -59,7 +59,7 @@ private[smithy4s] object SmithyHttp4sServerEndpoint { HttpEndpoint.HttpEndpointError, SmithyHttp4sServerEndpoint[F] ] = - HttpEndpoint.castEither(endpoint).flatMap { httpEndpoint => + HttpEndpoint.cast(endpoint).flatMap { httpEndpoint => toHttp4sMethod(httpEndpoint.method) .leftMap { e => HttpEndpoint.HttpEndpointError( @@ -81,7 +81,7 @@ private[smithy4s] object SmithyHttp4sServerEndpoint { } // format: off -private[smithy4s] class SmithyHttp4sServerEndpointImpl[F[_], Op[_, _, _, _, _], I, E, O, SI, SO]( +private[http4s] class SmithyHttp4sServerEndpointImpl[F[_], Op[_, _, _, _, _], I, E, O, SI, SO]( impl: Interpreter[Op, F], endpoint: Endpoint[Op, I, E, O, SI, SO], val method: Method, diff --git a/project/MimaVersionPlugin.scala b/project/MimaVersionPlugin.scala index 41acd3c20..474c43c0b 100644 --- a/project/MimaVersionPlugin.scala +++ b/project/MimaVersionPlugin.scala @@ -138,11 +138,6 @@ object MimaVersionPlugin extends AutoPlugin { ) .toSet } - }, - mimaBinaryIssueFilters += - // this is private[smithy4s] - ProblemFilters.exclude[IncompatibleResultTypeProblem]( - "smithy4s.http4s.package.toHttp4sMethod" - ) + } ) } From ede736d9c3da2647e828b605eee8845718e023e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 9 Nov 2022 02:47:33 +0100 Subject: [PATCH 09/12] Remove redundant line --- build.sbt | 1 - 1 file changed, 1 deletion(-) diff --git a/build.sbt b/build.sbt index 83c9b1912..8761eed9c 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,6 @@ ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" ThisBuild / dynverSeparator := "-" ThisBuild / versionScheme := Some("early-semver") ThisBuild / mimaBaseVersion := "0.17.0" -ThisBuild / testFrameworks += new TestFramework("weaver.framework.CatsEffect") Global / onChangedBuildSource := ReloadOnSourceChanges From a7a4b6d0b2a2dcacc17895d50ca1a2568b796e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 9 Nov 2022 02:52:02 +0100 Subject: [PATCH 10/12] Restore some deprecated methods --- .../http4s/SimpleProtocolBuilder.scala | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala b/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala index 75d610c9c..e85828ead 100644 --- a/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala +++ b/modules/http4s/src/smithy4s/http4s/SimpleProtocolBuilder.scala @@ -61,6 +61,24 @@ abstract class SimpleProtocolBuilder[P](val codecs: CodecAPI)(implicit def client[F[_]: EffectCompat](client: Client[F]) = new ClientBuilder[Alg, Op, F](client, service) + @deprecated( + "Use the ClientBuilder instead, client(client).uri(baseuri).use" + ) + def client[F[_]: EffectCompat]( + http4sClient: Client[F], + baseUri: Uri + ): Either[UnsupportedProtocolError, FunctorAlgebra[Alg, F]] = + client(http4sClient).uri(baseUri).use + + @deprecated( + "Use the ClientBuilder instead , client(client).uri(baseuri).resource" + ) + def clientResource[F[_]: EffectCompat]( + http4sClient: Client[F], + baseUri: Uri + ): Resource[F, FunctorAlgebra[Alg, F]] = + client(http4sClient).uri(baseUri).resource + def routes[F[_]: EffectCompat]( impl: FunctorAlgebra[Alg, F] ): RouterBuilder[Alg, Op, F] = From 94930a64550ee2b6d30670d3dabab1817825478a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 9 Nov 2022 02:55:33 +0100 Subject: [PATCH 11/12] Simplify heap setting --- .sbtopts | 2 +- build.sbt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.sbtopts b/.sbtopts index 9578b3464..a1c67b18c 100644 --- a/.sbtopts +++ b/.sbtopts @@ -3,4 +3,4 @@ -J-Xss2m -J-Xms512M -J-Xmx6G --J-XX:ReservedCodeCacheSize=256M \ No newline at end of file +-J-XX:ReservedCodeCacheSize=256M diff --git a/build.sbt b/build.sbt index 8761eed9c..18ccda624 100644 --- a/build.sbt +++ b/build.sbt @@ -400,7 +400,7 @@ lazy val codegenPlugin = (projectMatrix in file("modules/codegen-plugin")) sbtPlugin := true, scriptedLaunchOpts := { scriptedLaunchOpts.value ++ - Seq("-Xmx1024M", "-Dplugin.version=" + version.value) + Seq("-Xmx1G", "-Dplugin.version=" + version.value) }, Compile / unmanagedSources / excludeFilter := { f => Glob("**/sbt-test/**").matches(f.toPath) From 06bedfbb8092ebf0ce856e44f38a6d1f939e3271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Wed, 9 Nov 2022 19:13:58 +0100 Subject: [PATCH 12/12] Remove fromSchema exclusion --- project/MimaVersionPlugin.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/project/MimaVersionPlugin.scala b/project/MimaVersionPlugin.scala index 33251f6a5..fae0b0509 100644 --- a/project/MimaVersionPlugin.scala +++ b/project/MimaVersionPlugin.scala @@ -84,8 +84,7 @@ object MimaVersionPlugin extends AutoPlugin { mimaBinaryIssueFilters ++= Seq( // Focusing on backward compat as opposed to forward, for now. ProblemFilters.exclude[ReversedMissingMethodProblem]("smithy4s.*"), - ProblemFilters.exclude[Problem]("*.internals*"), - ProblemFilters.exclude[IncompatibleResultTypeProblem]("*fromSchema") + ProblemFilters.exclude[Problem]("*.internals*") ), mimaReportBinaryIssuesIfRelevant := filterTaskWhereRelevant( mimaReportBinaryIssues