Open ari-becker opened 4 years ago
@ari-becker: There's not a way to do this that I'm aware of. The reason why reordering the union types does not help is because the schema is interpreted (including normalization) and normalizing a union type sorts the alternatives.
@Gabriel439 I understand how the normalization process sorts the alternatives, I think my question was more about whether it was possible to parse Foo: 20
as < Bar : Natural | Foo : Natural >.Foo 20
, as then the YAML is trying to be deterministic.
You can see (linked to this issue) how I'm working around this.
@ari-becker: Yeah, I think that should be possible to implement a feature like that. I think the main guidance I need from others is if we should do this by default or if this behavior should be guarded behind a flag
@Gabriel439: From my POV there should be a flag for this feature.
I have several questions, regarding the implementation details.
< Bar: { Foo: Natural } | Foo : Natural >
should the flag make the tool go by the second alternative? Currently yaml-to-dhall
, given Foo: 1
as an expression, returns < Bar: { Foo: Natural } | Foo: Natural >.Bar { Foo = 1}>
.The flag names I'm thinking of are:
--union-force
--force-alternative
I probably won't be able to get to this soon, but I'd accept a pull request adding support for this if somebody were interested in implementing this
Running:
Results in:
while running:
Results in:
I understand that I can use
--unions-strict
to turn the second case into an error, but is there a way that I can getyaml-to-dhall
to reliably return< Bar : Natural | Foo : Natural >.Foo 20
?Discovered while trying to parse into this type: https://github.com/coralogix/dhall-utility-library/blob/8ad768e4a7ab313b5ee1b01c093ffdd1fef379c7/kubernetes/Space.dhall