flyx / NimYAML

YAML implementation for Nim
https://nimyaml.org
Other
191 stars 36 forks source link

Can't get optional fields to work #126

Closed jfilby closed 1 year ago

jfilby commented 1 year ago

I have tried the defaultVal pragma and make the type an Option, neither one works.

When using an option type:

    sqlName*: Option[string]

When running an the YAML field isn't specificed:

Error: unhandled exception: While constructing ModelYAML: Missing field: "sqlName" [YamlConstructionError]

When using the defaultVal pragma:

    sqlName* {.defaultVal: "".}: string

This fails to compile:

 Error: invalid pragma: defaultVal: ""

This is with Nim v.1.6.10.

flyx commented 1 year ago

You need the sparse pragma in order to automatically ignore Option types, see docs.

As for the defaultVal problem, please ensure that you have imported yaml (or yaml/annotations) before using it. If this doesn't help, could you give a minimal reproducible example, not just the one line?

flyx commented 1 year ago

Closing due to lack of feedback, assuming this is solved.

jfilby commented 1 year ago

This is likely solved, I haven't had time to retest. Thanks.