zio-config
zio-config copied to clipboard
`generateReport` does not contain the `value`
It seems with Scala 2.13.8 (with -Xsource:3
and ZIO config 3.0.0-RC1) the generateReport
does not contain any part of the config values passed as value
parameter.
Example code:
import zio.config.*
import zio.config.magnolia.descriptor
import zio.config.typesafe.TypesafeConfigSource
import zio.config.{ReadError, generateReport}
import zio.{Console, System, ZEnv, ZIO, ZIOAppArgs, ZIOAppDefault, config}
object GenerateReportFailure extends ZIOAppDefault {
override def run: ZIO[ZEnv & ZIOAppArgs, Any, Any] = application
final case class Config(username: String , password: String)
val getDesc: ZIO[System, ReadError[String], ConfigDescriptor[Config]] =
for {
hoconFile <- ZIO.from(TypesafeConfigSource.fromHoconString(
"""
|username = postgres
|password = postgres
|""".stripMargin)).mapError(t => ReadError.SourceError(t.getMessage))
env <- ZIO.from(ConfigSource.fromSystemEnv()).mapError(t => ReadError.SourceError(t.getMessage))
sysProp <- ZIO.from(ConfigSource.fromSystemProps()).mapError(t => ReadError.SourceError(t.getMessage))
source = hoconFile <> env <> sysProp
} yield (descriptor[Config] from source)
val application: ZIO[Console & System, String, Unit] =
for {
desc <- getDesc.mapError(_.prettyPrint())
configValue <- config.read(desc).mapError(t => ReadError.SourceError(t.getMessage)).mapError(_.prettyPrint())
_ <- Console.printLine(configValue).orDie
_ <- Console.printLine(generateReport(desc, configValue).map(docs => docs.toTable)).orDie
} yield ()
}
Output with Java17:
going to calculate tree Config(postgres,postgres) Right(Table(List(TableRow(List(),Some(AllOf),List(),Some(Table(List(TableRow(List(Key(username)),Some(Primitive),List(Description(Some(username),value of type string)),None,Set(hocon, system environment, system properties)), TableRow(List(Key(password)),Some(Primitive),List(Description(Some(password),value of type string)),None,Set(hocon, system environment, system properties))))),Set()))))
As you can see there are no postgres
values in the table. (There are no tests for this method yet.)
generateReport
need to have some more love, and hasn't been quite publicised yet. We will be taking care of it going forward.
The main reason being, if report should be part of the read
or not, and have some good design decisions to make instead of jumping in and fixing things. Anyway thanks for raising this issue