zio-config
zio-config copied to clipboard
Document yaml source
We have support for yaml source. Let's update this in website.
@afsalthaj I can pick it up, if you can give me few hints on where to start, as I'm new zio-config.
@shankarshastri
Missed out about this story. Considering its been long running issue, would you still consider giving a hand? It's going to be a simple addition here:
https://zio.github.io/zio-config/docs/sources/sources_index
@afsalthaj , I was going through this one: https://github.com/zio/zio-config/blob/master/yaml/shared/src/main/scala/zio/config/yaml/YamlConfigSource.scala Should I document using this as reference?
import zio.config.ConfigDescriptor._
import zio.config._
import zio.config.yaml._
import java.io.File
import java.nio.file.Path
case class MyConfig(i: Int, b: Boolean, s: String)
val yamlString =
"""
|top:
| child:
| - i: 1
| b: true
| s: "str"
|""".stripMargin
val myConfig: ConfigDescriptor[MyConfig] =
ConfigDescriptor.nested("top")(
ConfigDescriptor.nested("child")(
(int("i") |@| boolean("b") |@| string("s"))(
MyConfig.apply,
MyConfig.unapply
)
)
)
// String Based Yaml Read
YamlConfigSource
.fromYamlString(yamlString)
.flatMap(source => read(myConfig from source))
// File Based Yaml Read
val filePath = "/path/to/file"
YamlConfigSource
.fromYamlFile(new File(filePath))
.flatMap(source => read(myConfig from source))
// Path Based Yaml Read
YamlConfigSource
.fromYamlPath(Path.of(filePath))
.flatMap(source => read(myConfig from source))
Will this example suffice?