Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 03:28
    sammy-da edited #1647
  • 03:27
    sammy-da edited #1647
  • 03:26
    sammy-da edited #1647
  • Nov 29 17:40
    sammy-da opened #1647
  • Nov 29 15:46
    ArinRayAtCornerStoneFS commented #195
  • Nov 29 15:45
    ArinRayAtCornerStoneFS commented #195
  • Nov 28 16:46
    github-actions[bot] labeled #1646
  • Nov 28 16:46
    github-actions[bot] labeled #1646
  • Nov 28 16:40
    scala-steward opened #1646
  • Nov 26 16:41
    github-actions[bot] labeled #1645
  • Nov 26 16:30
    scala-steward closed #1636
  • Nov 26 16:30
    scala-steward commented #1636
  • Nov 26 16:30
    scala-steward opened #1645
  • Nov 24 16:43
    github-actions[bot] labeled #1644
  • Nov 24 16:43
    github-actions[bot] labeled #1644
  • Nov 24 16:41
    scala-steward closed #1625
  • Nov 24 16:41
    scala-steward commented #1625
  • Nov 24 16:41
    scala-steward opened #1644
  • Nov 23 17:49
    er1c commented #1643
  • Nov 23 17:45
    er1c opened #1643
Lorenzo Gabriele
@lolgab
👏👏👏
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
@lolgab: OK. It's a little messy, but it is now possible to override built-in functionality in the source generators.
https://gist.github.com/blast-hardcheese/4e0037332eb606330b90c3b19650e874 is a gist to explain how to do it, with a link to a branch in the sample-sbt-http4s repo where it is used.
The reason I think this is useful is it permits new feature development, alternately better fitment to custom internal idioms.
iterating in this way ends up being way faster than modifying the main guardrail repository, as well as working in your existing repository, so you can see what kind of impact it would have on your real-world code
Each of the *Generator classes has a .copy method that takes all parameters, so you can just open a file, copy the entire function you want to modify, then modify and re-inject it via https://github.com/guardrail-dev/guardrail-sample-sbt-http4s/blob/a3c270dc2ef340ed7f980b6e866c9c1d2cafb3b4/custom-circe/src/main/scala/CustomCirce.scala#L120-L122
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
please let me know how the experience is, and if there are any obvious improvements that could be made.
(I actually anticipated it would be possible to do by defining the extension directly inside projects/, but I got bit by sbt/sbt#3498 )
Lorenzo Gabriele
@lolgab
Thank you very much @blast_hardcheese:matrix.org ! This is wonderful! Every great software has a plug-in system, and now also Guardrail has it (which was already great software :) )!
I'm going to try it and let you know :)
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
sbt-guardrail 0.72.0 released, with some significant improvements. Pretty excited.
blast_hardcheese
@blast_hardcheese:matrix.org
[m]

Latest version of guardrail published to coursier contrib apps,

cs install --contrib guardrail

to get the CLI runner

Devon Stewart
@blast-hardcheese

Thanks to @stanislav-chetvertkov for adding support for refined to the circe generator! guardrail-dev/guardrail#1508 is merged, to be released shortly.

For those interested in trying it out, you can use modules=Seq("http4s", "circe-refined") or modules=Seq("akka-http", "circe-refined") in your sbt-guardrail configuration

1 reply
Lorenzo Gabriele
@lolgab

Hello!
I have a question about default values..
If I have a query parameter with:

required: false
default = 100

Guardrail generates limit: Option[Int] = Option(100) where I wanted it to generate limit: Int = 100.
Is that possible?
I tried with:

required: true
default = 100

and it seems to generate what I want, but it is not what the spec says to do, in fact it is in the "Common Mistakes"

blast_hardcheese
@blast_hardcheese:matrix.org
[m]
We don't currently do any consideration to think of optional values with defaults as non-optional types, this is definitely a bug as you've identified
@lolgab: Would you mind opening an issue?
Lorenzo Gabriele
@lolgab
@blast_hardcheese:matrix.org Sure! I can
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
Thanks!
Lorenzo Gabriele
@lolgab

I wanted also to ask if in the meantime I could rely on using

required: false
default: 100

or I am signing for other problems?

blast_hardcheese
@blast_hardcheese:matrix.org
[m]
lolgab (Lorenzo Gabriele): It permits the caller to send None, which violates the MUST in the specification, but there are no other implications
Lorenzo Gabriele
@lolgab
Opened the issue here: guardrail-dev/guardrail#1532
Sorry @blast_hardcheese:matrix.org, I sent the wrong snippet of code. When you use required: false it generates an Option while if you do use required: true it seems to do what I want
But let's see if this can be solved properly
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
I would use required: true, and eventually the required: false construction will also generate the same signature.
Lorenzo Gabriele
@lolgab
Perfect thank you very much 🙏
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
@lolgab: Pretty sure this is correct. Bummer that both core and $lang-support need changes, probably an opportunity to unify. guardrail-dev/guardrail#1534
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
@stanislav-chetvertkov: I think guardrail-dev/guardrail#1510 is ready for merge
very exciting
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
actually, just realized one question
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
Alright. Merged. 🎉 pattern support for Refined strings! Excellent work!
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
New module releases getting cut...
Lorenzo Gabriele
@lolgab
😍
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
maven bug...? https://search.maven.org/search?q=a:guardrail-core_2.12 says the latest version is 0.74.0, but clicking All Versions shows 0.75.0 supercedes it
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
Ok. sbt-guardrail 0.74.0 is out, with more refined support and removing more ..._ imports
It also has the fix for optional+default being a non-optional type
Lorenzo Gabriele
@lolgab
👏 👏 👏 Congrats
1 reply
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
the default value never appears in function arguments.
this becomes a problem in DTOs, as it requires different objects for clients and servers.
blast_hardcheese
@blast_hardcheese:matrix.org
[m]

perhaps something like:

case class Foo[F[_]](x: F[String])

where in clients, Option is expected, as in doFoo(x: Foo[Option]): ..., and in servers the deserializer supplies a Foo[cats.Id], removing the optionality for the servers only

blast_hardcheese
@blast_hardcheese:matrix.org
[m]
What's nice about this is that nested objects can pass the F through to child objects.
What's not great is that even if you never use optional values, the type parameter would need to be there.
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
The more I think about this, the more I think this is the key to solving guardrail-dev/guardrail#84
Lorenzo Gabriele
@lolgab
@blast_hardcheese:matrix.org Updated to sbt-guardrail 0.74.0 but it made the required: false + default: 100 query parameters mandatory, which ended up breaking the API and we needed to revert it. Either I didn't understand completely the solution or it is not working as intended.
2 replies
Martijn Hoekstra
@martijn.z:matrix.org
[m]
I'm trying out guardrail to generate a dropwizard scala service, and I'm not sure what I'm seeing is what's expected -- a handler is created that should create an otherwise untyped json node, rather than generating some dto and a serializer
is that expected, or am I doing it wrong?
I did the generation with the cli from the sbt console of the guardrail project cli --server --specPath myPath --outPath my/target/path --packageName my.experimental.package --framework dropwizard
Martijn Hoekstra
@martijn.z:matrix.org
[m]
I see the same when I try to create an http4s server
Martijn Hoekstra
@martijn.z:matrix.org
[m]
Ah, figured it out. I created the server from a spec bundled with swagger-cli, which creates inline types that don't seem supported as entity types. Running from the raw path, things work better
having swagger-cli create the definitions as components would be cool, but it doesn't work that way
blast_hardcheese
@blast_hardcheese:matrix.org
[m]
Yeah, the inline types are kind of a problem, trying to deduplicate known object types to create top level types with bogus names would work, but if there was even a slight difference between two type literals you'd get another, incompatible type (and another and another).
I'm glad to see you figured it out though!
Martijn Hoekstra
@martijn.z:matrix.org
[m]
it's annoying that when you follow the workflow if separating things into different files, then bundling with swagger-cli, then building the bundle with guardrail leaves you with an untyped API