Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 10:26

    julienrf on master

    Update scalacheck to 1.15.1 Merge branch 'master' into upda… Update scalacheck to 1.15.1 and 2 more (compare)

  • 10:26
    julienrf closed #674
  • 10:16
    codecov[bot] commented #674
  • 10:07
    codecov[bot] commented #674
  • 10:07
    julienrf synchronize #674
  • 10:04

    julienrf on master

    Update http4s-async-http-client… Merge pull request #690 from sc… (compare)

  • 10:04
    julienrf closed #690
  • 10:02
    codecov[bot] commented #690
  • 10:01

    julienrf on master

    Update sbt to 1.4.4 Merge pull request #688 from sc… (compare)

  • 10:01
    julienrf closed #688
  • 10:00

    julienrf on master

    Update scala-collection-compat … Merge pull request #689 from sc… (compare)

  • 10:00
    julienrf closed #689
  • 09:53
    scala-steward closed #686
  • 09:53
    scala-steward opened #690
  • 05:41
    codecov[bot] commented #689
  • 05:32
    scala-steward opened #689
  • Nov 24 09:48
    codecov[bot] commented #684
  • Nov 24 09:48
    bmeesters synchronize #684
  • Nov 24 08:22
    bmeesters edited #684
  • Nov 24 08:22
    bmeesters commented #684
Dominic Egger
@GrafBlutwurst
ah right we couldn't do traverse except we hardcode the other effect. so there'd be traverse overloaded over Option List etc. but that seems annoying
couldn't cats-extras also be it's own dependency a user may put into their buildfile?
Julien Richard-Foy
@julienrf
couldn't cats-extras also be it's own dependency a user may put into their buildfile?
sure
user753
@user753
Hi. How can I add description to each member of case class Foo(foo: String, bar: String) jsonResponse[Foo]?
Is it possible to add custom properties to OpenApi documentation like x-faker?
Julien Richard-Foy
@julienrf

@user753 We don’t support custom properties. You can add a documentation with the docs parameter of the field constructor:

field[String]("foo", docs = Some("A string…"))

In case you use generic derivation, you can use the @docs annotation:

case class Foo(@docs("A string…") foo: String, bar: String)
5 replies
Ryan Peters
@sloshy
Hello, I recently updated to the latest versions of endpoints & the circe/http4s support, and it seems that none of my endpoints are outputting JSON. Their error codes are correct, as are headers, but my browser and REST clients both are not returning any bodies. In fact Postman is giving me a parse error:
Error: Parse Error: Expected HTTP/
I'm using WSL2 on Windows but I can see that is not likely the problem as I was able to start an http4s quickstart g8 project and it seems to be working as expected
I feel like I must have misconfigured something since it does not seem anyone else has ran into this yet
Ryan Peters
@sloshy
Ahh I've reduced the problem to me using Ember as the server backend (vs the usual Blaze). I'll look into this w/ the http4s folks and see if maybe there's a known breakage
Luka Jacobowitz
@LukaJCB
I wonder if there should be a implicit def optionJsonSchema[A](jsonSchema: JsonSchema[A]): JsonSchema[Option[A]] in endpoints4s.algebra.JsonSchemas?
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 de Jong
@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 de Jong
@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?
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 de Jong
@Fristi
Thanks! :)