xebia-functional / poc-scala-data-streaming

Apache License 2.0
9 stars 0 forks source link

Uses pureconfig for type config #55

Closed fedefernandez closed 1 year ago

fedefernandez commented 1 year ago

This library is helpful and can save tons of work. In Scala 3, you need to manually create the readers if you don't want to mix the models with the codecs. If not, you can easily extend your case classes with ConfigReader and that's it (see https://pureconfig.github.io/docs/scala-3-derivation.html).

I have added a test to check that everything it's working.

dagmendez commented 1 year ago

The main (03-main) fails because there are no optional configuration defined inside the KafkaConfiguration (producer missing). The both optional fields are set to None. In the test, the configuration seems to load properly. Any hints?

dagmendez commented 1 year ago

I have tried with this:

given opConsumer: ConfigReader[Option[ConsumerConfiguration]] = ConfigReader.optionReader[ConsumerConfiguration]

but it doesn't load.

There are some other option in the library, but I don't know how to use them:

  def fromStringTry[A](fromF: String => Try[A])(implicit ct: ClassTag[A]): ConfigReader[A] = {
    fromString[A](tryF(fromF))
  }

def fromStringOpt[A](fromF: String => Option[A])(implicit ct: ClassTag[A]): ConfigReader[A] = {
    fromString[A](optF(fromF))
  }
dagmendez commented 1 year ago

[X] Compile [X] Test [X] Integration Test [X] Main

Approved and merged.