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
OlegYch
@OlegYch
eg it says which field is missing an instance
Julien Richard-Foy
@julienrf
Awesome!
megri
@megri
@OlegYch I have a few questions regarding the magnolia derivation, if you have time :)
  1. Why is the "base deriver" using Openapi?
  2. It seems automatic derivation of "container" types like Option/List doesn't work. So if I have defined a MagnoliaSchema.Derived[MyType], it won't automatically derive Derived[List[MyType]] when requested like jsonResponse[List[MyType]]
Maybe it would be nice to have a separate module for magnolia made to work like endpoints.generic. At the moment, using both scala-refined, generic (shapeless) derivation and doobie-derivation of Meta and family, makes compile times pretty insane, even with bloop. I'm up to about 5 seconds for a simple query and auto completion breaks all the time in VS Code/metals.
OlegYch
@OlegYch
@megri 1. do you mean MagnoliaDeriver? 2. that was a conscious decision to force endpoints to use case classes, you can change MagnoliaSchema.Derived to MagnoliaSchema.Typeclass in JsonEndpoints if you don't want that
megri
@megri
@OlegYch For 1., the part I'm curious about is
object Openapi extends endpoints.openapi.JsonSchemas {
…
}

trait MagnoliaSchema[T] extends MagnoliaSchema.Input[T] {
…
}

object MagnoliaSchema extends MagnoliaDeriver {
  type Input[T]     = Openapi.JsonSchema[T]
  …
OlegYch
@OlegYch
Openapi part is just for making schema instances path-independent
so that you can move them to companions and reuse in 'services'
megri
@megri
Sorry, I'm not being clear. What I'm wondering about is why it's extending endpoints.openapi.JsonSchemas. It seems to me that this "couples" all derived schemas to openapi, but it may well be my ongoing confusion with the "cakiness" of Endpoints (the library)
I've been coding—enthusiastically—Scala for well over five years and I'm still dumbfounded by all varieties of abstraction :P
OlegYch
@OlegYch
yeah cakiness can be confusing
coupling to openapi/whatever else interpreter is inevitable if you don't go with it
i just think coherence and better incremental recompilation behaviour is a better tradeoff
megri
@megri
So basically what's done up there is coupling to the "lowest common denominator", ie having usable schemas that can also generate openapi documentation?
OlegYch
@OlegYch
that could work, but we also derive play codecs at the same time and use them in server interpreter
megri
@megri
You don't use the ujson-parts?
OlegYch
@OlegYch
no
megri
@megri
I see. Thanks for taking your time explaining this :)
OlegYch
@OlegYch
np
Dominic Egger
@GrafBlutwurst

I still have a bit of a hard time figuring out in what order and how to exactly mix the different traits and where to define endpoints. e.g. I now use all of these

endpoints.http4s.server.Endpoints[M]
endpoints.http4s.server.JsonEntitiesFromCodecs
endpoints.circe.JsonSchemas
endpoints.generic.JsonSchemas
endpoints.algebra.JsonEntitiesFromSchemas

over a couple different files so the scala compiler isn't yelling at me. but i got to that point more by trial and error and it's now getting hard to get openapi into the mix. Does anyone have a good read on trait mixin for this type of composition?

Julien Richard-Foy
@julienrf
@GrafBlutwurst I was hoping that http://julienrf.github.io/endpoints/algebras/json-entities.html would clarify how to mix compatible things together, but maybe it’s not detailed enough?
Dominic Egger
@GrafBlutwurst
I'll have another read. maybe i was just going through it too quick
Josip Grgurica
@jkobejs

here is implementation of basic algebras for uzhttp lib
https://github.com/jkobejs/endpoints-uzhttp
can some take a look at it and see if something can be improved? :)

I think that it would be good to create Gitter8 template that will have everything setup so that we can easily create libs that will be inside endpoints org, something like https://github.com/alexandru/typelevel-library.g8

Rustam Sultanov
@RustamSultanov
Hi all, I try to introduce endpoints in my scala.js client, and I have some problem. for local development I need set base address of my server REST API like https://github.com/julienrf/endpoints/blob/408d50fb596abd8bf739fbbdd310dcf85f24e541/scalaj/client/src/main/scala/endpoints/scalaj/client/Urls.scala or sttp client, no matter. But in xhr client I doesnt find this (
Julien Richard-Foy
@julienrf
hello, this is a limitation of the current xhr client interpreter. We should clearly add a base URL as a setting. In the meantime, a workaround could be to override the request operation to prefix the URL produced by url.encode with your base URL.
Konstantin Alifanov
@Telpenair
@julienrf
Good day!
Can you please tell me more about overriding request operation?
What i find - that staticPathSegment function somehow make path value (that is baseUrl in fact as i considered).
But how it can be overriden? Or i find wrong way? Can you show some tricks with it? (tricks as it looks like for me).
Julien Richard-Foy
@julienrf
At the place where you apply your xhr.Endpoints interpreter, override the request method like this:
class ClientWithBaseUrl(baseUrl: String) extends MyEndpoints with xhr.future.Endpoints {
  override def request[A, B, C, AB, Out](
      method: Method,
      url: Url[A],
      entity: RequestEntity[B],
      docs: Documentation,
      headers: RequestHeaders[C]
  )(
      implicit tuplerAB: Tupler.Aux[A, B, AB],
      tuplerABC: Tupler.Aux[AB, C, Out]
  ): Request[Out] =
    new Request[Out] {
      def apply(abc: Out) = {
        val (ab, c) = tuplerABC.unapply(abc)
        val (a, b) = tuplerAB.unapply(ab)
        val xhr = makeXhr(method, baseUrl + url, a, headers, c)
        (xhr, Some(entity(b, xhr)))
      }
}
Rustam Sultanov
@RustamSultanov
@julienrf How it work? makeXhr is a private and requre Url[A], but String found. It is fail on compile
Julien Richard-Foy
@julienrf
@RustamSultanov you’re right, sorry you’ll have to inline the content of makeXhr to concatenate the baseUrl to the result of calling url.encode
(but we should really have this baseUrl setting in endpoints)
Konstantin Alifanov
@Telpenair
Thank you for help! It's works.
Dominic Egger
@GrafBlutwurst
so I'm revisiting the OpenApi thing. but I'm a bit confused. My endpoints are specified using jsonRequest and jsonResponse which come from JsonEntitiesFromSchema if i understand correctly. Now if i inherit the trait where all my endpoint defs live together with OpenApi it blows up because there's abstract members missing
Dominic Egger
@GrafBlutwurst
object OpenApiDoc extends DomainEndpoints with endpoints.openapi.JsonEntitiesFromSchemas with endpoints.openapi.Endpoints I think this does the trick.
Dominic Egger
@GrafBlutwurst
that indeed was the issue, now I just have to figure out how to get the http4s server to play ball and host this
Rustam Sultanov
@RustamSultanov
@GrafBlutwurst in my http4s app I use tapir swagger endpoint. It is simple integration
import sttp.tapir.swagger.http4s.SwaggerHttp4s
docRoutes = new SwaggerHttp4s(
        OpenApi.stringEncoder.encode(api),
        "docs",
        "docs.json",
      ).routes[IO]
Julien Richard-Foy
@julienrf
@GrafBlutwurst The modules used by your interpreters should match the algebra modules that you use to define your endpoints. If you use the algebra modules algebra.Endpoints with algebra.JsonEntitiesFromSchemas, then your interpreters should have the same modules (e.g., openapi.Endpoints with openapi.JsonEntitiesFromSchemas, or http4s.server.Endpoints with http4s.server.JsonEntitiesFromSchemas). Does that help?
Rustam Sultanov
@RustamSultanov
@GrafBlutwurst if you have problems until, you can look on my app on http4s and scala.js with OutWatch https://github.com/RustamSultanov/camachine
Dominic Egger
@GrafBlutwurst
@julienrf yep thanks. i wrapped my head around that now. Composition by trait mix-in is just not very intuitive for me. I think my current issue with hosting the openapi is that with server.JsonEntitiesFromEncodersAndDecoders doesn't exist for http4s from what i see?
@RustamSultanov thanks i'll have a look for sure! though I'd like to avoid to pull more dependencies for that
Dominic Egger
@GrafBlutwurst
@RustamSultanov ah i see you generate a second set of HTTPRoutes through another dep and add them to the ones generated by endpoints. I might go that route as well
or if I start properly understanding endpoints, start contributing. e.g. i have a working snippet for http4s mutlipart form fileupload but haven't quite figured out how to formulate an algebra for this, though there is an open issue julienrf/endpoints#418
Rustam Sultanov
@RustamSultanov
If you doesnt need Swagger UI, you can serve static json from OpenApi like in examples in docs https://github.com/julienrf/endpoints/blob/master/documentation/examples/documented/src/main/scala/counter/Counter.scala#L144
If you want Swagger UI anyway you need dependancy from web jar Swagger UI
OlegYch
@OlegYch
i'd recommend redoc instead of swagger io
ui
Rustam Sultanov
@RustamSultanov
It`s also good variant
You can use tapir-redoc-http4s endpoint. It's very simple
OlegYch
@OlegYch
did i miss something? is tapir related to endpoints at all
Julien Richard-Foy
@julienrf
@GrafBlutwurst True, JsonEntitiesFromEncodersAndDecoders interpreter is missing for http4s. We should add it so that the examples translate nicely to http4s. In the meantime, you can implement a regular http4s endpoint that serves the content of OpenApi.stringEncoder.encode(your_openapi_documentation)
Julien Richard-Foy
@julienrf

@OlegYch No, but Tapir does provide a handy endpoint implementation for http4s that serves a nice HTML UI for playing with an OpenAPI documentation:

@GrafBlutwurst in my http4s app I use tapir swagger endpoint. It is simple integration

import sttp.tapir.swagger.http4s.SwaggerHttp4s
docRoutes = new SwaggerHttp4s(
        OpenApi.stringEncoder.encode(api),
        "docs",
        "docs.json",
      ).routes[IO]

Here, OpenApi.stringEncoder.encode(api) comes from endpoints, although SwaggerHttp4s comes from Tapir.