I need to type and generate a config that contains string enum values. I've managed to define the following lines. In the end I need to convert the union to a string value.
let ParameterLocation = < Query : {}
| Header : {}
| Path : {}
| Cookie : {}
>
let ParameterObject = {
name : Text,
`in` : ParameterLocation,
required : Bool
}
let locationToText = \(loc : ParameterLocation) -> merge {
Query = \(_ : {}) -> "query",
Header = \(_ : {}) -> "header",
Path = \(_ : {}) -> "path",
Cookie = \(_ : {}) -> "cookie"
} loc
let t : ParameterObject = {
name = "organisation_id",
`in` = ParameterLocation.Query {=},
required = False
}
in t // { `in` = locationToText t.`in` }
Here the record containing the union/enum is at top so I can quite easily access it, but in the final configuration, the ParameterObject si quite deeply nested.
Is there a way
- to "traverse" an arbitrary record structure and apply locationToText wherever it is applicable ?
- or to feed dhall-to-json/dhall-to-yaml with printer for such value ?
- or a better way to define my enum to achieve my goal more easily ?