Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 24 19:44
    mleclercq commented #847
  • Jul 24 19:39
    codecov[bot] commented #847
  • Jul 24 19:29
    mleclercq synchronize #847
  • Jul 24 19:25
    mleclercq synchronize #847
  • Jul 23 12:28
    codecov[bot] commented #858
  • Jul 23 12:20
    codecov[bot] commented #858
  • Jul 23 12:20
    scala-steward synchronize #858
  • Jul 23 10:34
    codecov[bot] commented #850
  • Jul 23 10:33
    codecov[bot] commented #857
  • Jul 23 10:25
    codecov[bot] commented #850
  • Jul 23 10:25
    codecov[bot] commented #857
  • Jul 23 10:25
    scala-steward synchronize #850
  • Jul 23 10:25
    scala-steward synchronize #857
  • Jul 23 10:04

    julienrf on master

    Update shapeless3-deriving to 3… (compare)

  • Jul 23 10:04
    julienrf closed #859
  • Jul 23 10:03

    julienrf on master

    Update slf4j-simple to 1.7.32 Merge pull request #860 from sc… (compare)

  • Jul 23 10:03
    julienrf closed #860
  • Jul 23 09:15
    codecov[bot] commented #861
  • Jul 23 09:15
    julienrf synchronize #861
  • Jul 23 09:04
    ptrdom commented #510
Julien Richard-Foy
@julienrf
Why not, how would you model None values in JSON?
Julien Richard-Foy
@julienrf
We need to make sure it wouldn’t clash with the existing optField constructor
Luka Jacobowitz
@LukaJCB
I would expect it to be mapped to null?
Julien Richard-Foy
@julienrf
This is not a good idea because this would not be parametric
Problems start to appear when you consider Option[Option[A]]
If you serialize Some(None) to null, you may deserialize it to None
Also, we currently treat null in object properties as a possible value for an optional field (it is decoded as None)
So, we need to be careful about how else we would use null
Luka Jacobowitz
@LukaJCB
Hmm
I guess that makes sense
Luka Jacobowitz
@LukaJCB
I suppose if we made it not implicit it would still be easier than what we’d have right now?
i.e. some function def option[A: JsonSchema]: JsonSchema[Option[A]]?
Julien Richard-Foy
@julienrf
I think it’s fine to have such a function, even implicit, but I believe we should make it correct. One way to do it would be to use an empty JSON array to model None, and an array with exactly one element to model Some.

well, maybe it’d be better to have it non implicit at first :)
The risk, if it’s implicit, is that users write this:

case class User(name: String, email: Option[String])

val userSchema = (
  field[String]("name") zip
  field[Option[String]]("email")
).as[User]

Which would compile and work, but most probably we want to write the following instead?

case class User(name: String, email: Option[String])

val userSchema = (
  field[String]("name") zip
  optField[String]("email")
).as[User]

(ie, we would use optField[String] instead of field[Option[String]])

Luka Jacobowitz
@LukaJCB
right
Georgi Krastev
@joroKr21
Hmm, how does circe deal with this problem?
I think it has implicit Decoder for Option
Alec Theriault
@harpocrates
It falls victim to the problem @julienrf described:
Welcome to the Ammonite Repl 1.7.4
(Scala 2.13.1 Java 11.0.6)
If you like Ammonite, please support our development at www.patreon.com/lihaoyi
@ {
  import $ivy.`io.circe::circe-core:0.12.3`
  import $ivy.`io.circe::circe-parser:0.12.3`

  import io.circe._, io.circe.parser._, io.circe.syntax._

  def roundtrip[A : Encoder : Decoder](a: A): Unit =
    assert(
      Right(a) == decode[A](a.asJson.noSpaces),
      s"Could not round-trip $a"
    )

  roundtrip[Option[Option[Int]]](None)
  roundtrip[Option[Option[Int]]](Some(None))
  }
java.lang.AssertionError: assertion failed: Could not round-trip Some(None)
  scala.Predef$.assert(Predef.scala:282)
  ammonite.$sess.cmd0$.roundtrip(cmd0.sc:9)
  ammonite.$sess.cmd0$.<clinit>(cmd0.sc:13)
While we're on that topic, isn't that already a problem for QueryStringParam which has an instance implicit optionalQueryStringParam[A: QueryStringParam]: QueryStringParam[Option[A]] (which must suffer from the same round-tripping issues for nested options)?
Julien Richard-Foy
@julienrf
Yes, this is true. I have assumed that users would never use nested Option in query string params.
Alec Theriault
@harpocrates
I've wondered in the past if this category of problem makes it worth it to distinguish between an optional schema and a non-optional schema (so that no instance of Schema[Option[Option[A]]] could be implicitly summoned). The downside is that the Option instance would really be special.
Georgi Krastev
@joroKr21

Yes, this is true. I have assumed that users would never use nested Option in query string params.

I guess you could say the same about JsonSchema

Luka Jacobowitz
@LukaJCB
I wouldn’t have a problem at all using an explicit method
but I can’t even figure out how to generate a simple schema like this { "type": ["null", "string"] }
Ryan Peters
@sloshy
Hi, I popped in a little while back to get some help with using endpoints with http4s as my responses were empty and causing errors in some clients. Turns out, it's a combination of issues: the ember server in http4s was not defaulting to chunked encoding when Content-Length is not specified, and endpoints4s was not setting that header. Does this qualify as a bug of some sort, or should I be setting this header myself? The bug is "fixed" on my end by using Blaze as my http4s backend, which defaults to chunked encoding, but I believe endpoints4s should also be setting the content-length header.
Here's a link to the relevant part of the discussion on the http4s gitter from around that time: https://gitter.im/http4s/http4s?at=5f8de432eb82301c1a378008
Ryan Peters
@sloshy
Bonus question: I ran into this issue as well recently, setting the base url from the XHR scalajs client. This hasn't changed recently has it? Or is there another client that more easily allows to do this yet? https://gitter.im/endpoints4s/endpoints4s?at=5ecad4cb27513a72fbada57b
Rustam Sultanov
@RustamSultanov
Now for scalajs only XHR client withiout base url.
sttp have support scala.js backend but now endpoints4s support only jvm back endpoints4s/endpoints4s#571
Julien Richard-Foy
@julienrf
@sloshy We should change the API and add a parameter for the base URL in the xhr Scala.js client
Julien Richard-Foy
@julienrf
@sloshy Thanks for the investigation about Content-Length. My understanding is that we could set this header, but this should not be required for the http4s backend to work correctly.
Ryan Peters
@sloshy
@julienrf Right, it was partially a bug in the http4s Ember backend where a bad default was chosen. I think the bug should be fixed now, or at least on trunk. Now, I'm not exactly super HTTP-fluent so you'll have to excuse this stupid question: would setting the Content-Length header by default where possible be an undesirable change? Is there a reason it is not implemented now VS it just "not being there"? I'm wondering if it's something I could contribute, or if it's a matter of opinion
Julien Richard-Foy
@julienrf
@sloshy Such a contribution would be very welcome :) I see no reason to not set the Content-Length header, if we can. The fact that it is not currently set is an oversight. I think the Play server interpreter does set it, actually. I don’t know for the others.
Mark
@Fristi
@julienrf I've bumped sttp to 2.2.9 (latest stable 2.x release, I think 3.x is around the corner as well, yet I would like this one as I'm using it for projects atm) endpoints4s/endpoints4s#675
Julien Richard-Foy
@julienrf
:pray: thanks!
Mark
@Fristi
When would you able to release the sttp 2.0 module?
Julien Richard-Foy
@julienrf
@Fristi I wanted to make sure the support of optional fields with default values was well designed. I stumbled upon this problem: https://github.com/endpoints4s/endpoints4s/issues/660#issuecomment-722464040
@harpocrates did you make some progress on the support of optional query string parameters with default values?
1 reply
Julien Richard-Foy
@julienrf
@/all I’ve just released endpoints4s-1.2.0 :) See the release notes here: https://github.com/endpoints4s/endpoints4s/releases/tag/v1.2.0
Mark
@Fristi
Thanks! :)
Leif Warner
@LeifW
I've got a route that naturally wants to return a Option[Either[Future]] - it can return 404 or 400 or 200. - Though the implementedByAsync wants the Future to be on the outside.
Is there anything to be done for that? Seems I'll have to do some weird type stuff to swap those around. Thinking about using EitherT[OptionT[Future]] from cats...
Julien Richard-Foy
@julienrf
@LeifW maybe you’ll find an answer here: https://www.youtube.com/watch?v=yEYPf44rS2U
Leif Warner
@LeifW
I guess doing traverse + traverse works.
For some reason sequence on the result wasn't working at all, but traverse does work.
Leif Warner
@LeifW
It seems more common to be to have the Either on the outside - because I do some validation before deciding whether to immediately return 400 or kick off the Future IO action... but traverse works.
Georgi Krastev
@joroKr21
In that case you can do the traverse already in the validation step :thumbsup:
Leif Warner
@LeifW
If I have a lot of different response codes I might want to return, e.g. 200 or 201 or 204 or 400 - does that mean I just nest a bunch of Eithers?
Alec Theriault
@harpocrates
If you've got a lot of possible response codes, you can xmapover the ResponseEntity to turn your nested Either's into some more palatable sealed trait that better fits your domain. That way, the Either stuff shows up only in the body of the endpoint definition and the type of the whole endpoint is in terms of your domain.
Dominic Egger
@GrafBlutwurst
out of curiosity why is QueryString an invariant partial functor? when is there a need to translate from decoded params to query string?
Julien Richard-Foy
@julienrf
@GrafBlutwurst Client interpreters encode params into a query string
Dominic Egger
@GrafBlutwurst
ahhh right makes sense. thanks!