Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 04 20:27
    http4s-steward[bot] opened #720
  • Aug 04 20:27

    http4s-steward[bot] on swagger-ui-4.13.2

    Update swagger-ui to 4.13.2 (compare)

  • Jul 29 19:33

    FrancescoSerra on scala-collection-compat-2.8.1

    (compare)

  • Jul 29 19:33

    FrancescoSerra on main

    Update scala-collection-compat … Merge pull request #718 from ht… (compare)

  • Jul 29 19:33
    FrancescoSerra closed #718
  • Jul 29 16:41

    http4s-steward[bot] on swagger-ui-4.11.1

    (compare)

  • Jul 29 16:41

    http4s-steward[bot] on munit-cats-effect-3-1.0.7

    (compare)

  • Jul 29 16:41

    http4s-steward[bot] on scalafmt-core-3.5.8

    (compare)

  • Jul 29 16:41

    http4s-steward[bot] on sbt-scalafmt-2.4.6

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on munit-0.7.29

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on sbt-1.5.8

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on scala-xml-2.1.0

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on scala-library-2.13.8

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on scala-library-2.12.16

    (compare)

  • Jul 29 16:40
    http4s-steward[bot] opened #719
  • Jul 29 16:40

    http4s-steward[bot] on http4s-blaze-server-0.23.12

    Update http4s-blaze-server, ...… (compare)

  • Jul 29 16:40

    http4s-steward[bot] on swagger-core-1.6.6

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on sbt-tpolecat-0.1.22

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on circe-core-0.14.2

    (compare)

  • Jul 29 16:40

    http4s-steward[bot] on sbt-mima-plugin-1.1.0

    (compare)

meloniasty
@meloniasty

Hi, how can I mix query parameters with json body in rho (I'm using 0.18.4)

"List items" **
    POST / "items" +? paramD[Option[Int]]("limit", "page size") ^jsonOf[IO,Filters] |>> { (limit:Int, filters:Filters) => ... }

Above does not work.

Darren Gibson
@zarthross
@meloniasty Sorry for the late reply... I believe the issue you are having is limit in your paramD is an Option[Int] but in your function its a Int. https://scastie.scala-lang.org/O1sSylChRVmGFYj3mZShjA <- this seems to work fine.
@meloniasty Next time, if you provide an error message it will make it easier for someone to render assistance.
Gabriel Asman
@Qthunder

Hey everyone. Don't know if this has been asked before: Is it possible to have a rho service, behind TLS and authentication and have generated swagger for it (not behind TLS & auth)

Current attempt giving me :{"schemaValidationMessages":[{"level":"error","message":"Can't read from file /api-docs/swagger.json"}]}

Roman
@raven0w_twitter

Hi, guys, i wanted ask is it possible to group get request params as case class? like

case class Param(a: String, b: String, c: String)
GET / "list" +? extractParamsInto(Param) |>> { (p: Param) => ??? }

Guillaume Balaine
@Igosuki
Hi guys, I’m trying to migrate to 2.13, and code that compiled fine in 2.12 breaks, specifically related to Rho
import org.http4s.rho.{RhoRoutes}
import com.me.Dao
import cats.effect.Effect
class AnEndpoint[F[+ _] : Effect](dao: Dao[F]) extends RhoRoutes[F] {
"Create an a" **
    POST / “a" ^ EntityDecoder[F, A] |>> { a: A =>
    dao.insert(a).flatMap {
      case Left(err) => BadRequest(err)
      case Right(created) => Created(created)
    }
  }
}
dao.insert(a) returns an F[Either[Error, A]]
the upper of BadRequest and Created then get resolved to Any (at least in my IDE), but this used to work fine in 2.12
While entity encoders are resolved fine for both entities, a diverging expansion occurs
Guillaume Balaine
@Igosuki
The function return type gets resolved as Any instead of F[NotInfered] by intellij, but that used to compile in 2.12 anyways
Cory Parent
@goedelsoup
i wonder if it's some sort of lib conflict, but i may be jumping to that after a few days terrorized by such things
Guillaume Balaine
@Igosuki
The diverging expansion happens because of upcast, it even says :
Error:(33, 57) diverging implicit expansion for type org.http4s.rho.bits.HListToFunc[F,com.a.A :: shapeless.HNil,com.a.A => F[org.http4s.rho.Result[F,Nothing,Nothing,Nothing,Nothing,Nothing,com.a.A,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,com.adikteev.audience.persist.InsertionError,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing]]]
starting with lazy value unrelatedModelToAEncoder in trait ModelSerdes
    POST / “a" ^ EntityDecoder[F, A] |>> { a: A =>
unrelatedModelEncoder is just the first one in ModelSerdes
There’s another method above in that class that encodes a List[A] just fine, because it’s just F[OK[A]]
not F[NotInfered]
but again, that used to work in 2.12
Eric Meisel
@etspaceman

Hello there.

I've been playing around with Rho lately and have run into a couple of issues:

  • I see no model definitions
  • My POST routes do not show possible response codes / responses
  • I get an error stating that one of my models is not defined: <span class="strong">BuildInfo is not defined!</span>

My responses are an ADT that have encoders, decoders and entityencoders defined:

@deriving(Encoder, Decoder, Eq)
sealed trait ValidationServiceResult

object ValidationServiceResult {
  implicit def validationServiceResultEntityEncoder[
      F[_]: Applicative
    ]: EntityEncoder[F, ValidationServiceResult] = jsonEncoderOf

  implicit def listValidationServiceResultEntityEncoder[
      F[_]: Applicative
    ]: EntityEncoder[F, List[ValidationServiceResult]] = jsonEncoderOf
}

@deriving(Encoder, Decoder, Eq)
case class UnknownTypeError(tpe: String Refined NonEmpty)
  extends ValidationServiceResult

object UnknownTypeError {
  implicit def unknownTypeErrorEntityEncoder[
      F[_]: Applicative
    ]: EntityEncoder[F, UnknownTypeError] = jsonEncoderOf
}

@deriving(Encoder, Decoder, Eq)
case class JsonDecodeError(errors: NonEmptyList[DecodingFailure])
  extends ValidationServiceResult

object JsonDecodeError {
  implicit def jsonDecodeErrorEntityEncoder[
      F[_]: Applicative
    ]: EntityEncoder[F, JsonDecodeError] = jsonEncoderOf
}

@deriving(Encoder, Decoder, Eq)
case object Success extends ValidationServiceResult {
  implicit def successEntityEncoder[
      F[_]: Applicative
    ]: EntityEncoder[F, Success.type] = jsonEncoderOf
}

And I return responses like so:

  def response(
      res: ValidationServiceResult
    ): F[Result.BaseResult[F]] = res match {
    case x: Success.type => Ok(res)
    case x: UnknownTypeError => BadRequest(res)
    case x: JsonDecodeError => BadRequest(res)

I'm not quite sure what I'm doing wrong, and if all / any of these issues are expected.

This is w/ version 0.19.0
Eric Meisel
@etspaceman
One interesting note is that if i move the logic out of the response function, and directly in each of the routes, I start to get better model support.
but not by much :/
image.png
Eric Meisel
@etspaceman
I think i see the issue

http4s/rho@7944593

This isn't in 0.19.0 :(

Of course that wouldn't explain why my BuildInfo behaves the same way... that is not an ADT
Eric Meisel
@etspaceman
converting the Success to a case class works
Eric Meisel
@etspaceman
same w/ the BuildInfo (was a case object w/ a custom circe encoder)
Mikkel Storgaard Knudsen
@MikkelStorgaard
Hello everyone! I'm really really new at Scala, and I'm trying to solve a case.
is it possible to add http4s authentication middleware to RhoRoutes and still also use SwaggerMiddleware?
Guillaume Balaine
@Igosuki
@MikkelStorgaard
class SwaggerSpecEndpoint[F[+ _] : Effect](swaggerSpec: Swagger)(implicit F: Monad[F]) extends Http4sDsl[F] {

  lazy val response: F[Response[F]] = {
    val fOk = Ok.apply(
      Json
        .mapper()
        .writerWithDefaultPrettyPrinter()
        .writeValueAsString(swaggerSpec.toJModel)
    )

    F.map(fOk) { ok =>
      ok.copy(headers = ok.headers.put(`Content-Type`(MediaType.application.json)))
    }
  }

  val service: HttpRoutes[F] = HttpRoutes.of[F] {
    case _ @GET -> Root / "swagger.json" => response
  }
}

object SwaggerSpecEndpoint {
  def endpoint[F[+ _] : Effect](swagger: SwaggerSupport[F], swaggerFormats: SwaggerFormats)(
    routes: Seq[RhoRoute[F, _]]
  ): SwaggerSpecEndpoint[F] = {
    import swagger._
    val swaggerSpec: Swagger = createSwagger(
      swaggerFormats,
      security = List(SecurityRequirement("JWT", Nil)),
      securityDefinitions = Map("JWT" -> ApiKeyAuthDefinition(auth.JWT_AUTH_HEADER, In.HEADER, "JWT".some))
    )(routes)
    new SwaggerSpecEndpoint[F](swaggerSpec)
  }
}
Here’s how I mounted my endpoints
rootServices = Metrics[F](metricsOps)(
        GZip(
          CORS(authEndpoint.service, corsConfig) <+> snsService.routes <+>
            authService.authenticated(authContext.toService(CORS(coreApi, corsConfig))) <+>
            swaggerSpecEndpoint.service <+> CORS(home.service, corsConfig) <+> home.noop
        )
      )
And in AuthService :
val authenticated: AuthMiddleware[F, User] =
    AuthMiddleware.withFallThrough(authUser)
with
val authUser: Kleisli[OptionT[F, ?], Request[F], User]
have fun
Henry
@hygt
Hi, I'm new to rho (and http4s) and I'm trying to implement some custom error handling like this:
class Routes[F[+_]: Sync](service: FooService[F]) extends RhoRoutes[F] {

  private def handleError(t: Throwable): F[BaseResult[F]] = t match {
    case e: CustomError =>
      BadGateway(e)
    case _ =>
      InternalServerError(UnexpectedError)
  }

  GET / "api" +? param[Int]("id") |>> { id: Int =>
    service
      .getFoo(id)
      .flatMap { foo =>
        Ok(foo).widen[BaseResult[F]]
      }
      .handleErrorWith(handleError)
  }
}
I couldn't find a way to make it work without the widen
and of course, this messes up with the Swagger documentation
do I need some single ADT for all my API response types, including errors I want to encode?
I tried to return something like InternalServerError(someEmptyFooInstance) but it wouldn't compile either
Henry
@hygt
Ok... I moved the error handling to the service and it seems to work as expected
Magrahi haikal
@JMagrahiHaikal_twitter
Hello any Ideas on how to make a route deprecated please
Magrahi haikal
@JMagrahiHaikal_twitter
I discovered that deprecated feature not supported
0.20.0-M2 rho still using swagger 1.6 which don't support deprecation
Guillaume Balaine
@Igosuki
@hygt thanks for that, you actually solved my problem with scala 2.13, assigning every result in the Rho Kleislis to a F[BaseResult[F]] when the upper bound is F[A >:> Ok | BadRequest] for instance just works
now I can use foldF on EitherT and it all works
@hygt do you also have code that returns multiple response types and still works ?
in line 39 there is an example of how to return multiple response type
Guillaume Balaine
@Igosuki
ha! interesting
Ray Eldath
@Ray-Eldath
val authUser: Kleisli[IO, Request[IO], Either[String, User]] = Kleisli { req =>
  IO(Right(User("Bob", UUID.randomUUID())))
}

val onFailure: AuthedRoutes[String, IO] = Kleisli(req => OptionT.liftF(Forbidden(req.authInfo)))


val middleware = AuthMiddleware(authUser, onFailure)

object Auth extends AuthedContext[IO, User]

object BobRoutes extends RhoRoutes[IO] {
  GET +? param("foo", "bar") >>> Auth.auth |>> { (foo: String, user: User) =>
    Ok(s"Bob with id ${user.id}, foo $foo")
  }
}

val service = middleware.apply(Auth.toService(BobRoutes.toRoutes()))

This code is copied from AuthedContext.scala. But the Forbidden part is still "not found" after import bulk of things to make other part of code works... By the way, how to make service available for BlazeServerBuilder, or convert to HttpApp...?

Many thx!

Ray Eldath
@Ray-Eldath
And... is it possible to integrate rho with TSec...?
Guillaume Balaine
@Igosuki
Yes it is
Easily