Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get optional fields to work #126

Closed
jfilby opened this issue Dec 9, 2022 · 3 comments
Closed

Can't get optional fields to work #126

jfilby opened this issue Dec 9, 2022 · 3 comments

Comments

@jfilby
Copy link

jfilby commented Dec 9, 2022

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
Copy link
Owner

flyx commented Dec 9, 2022

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
Copy link
Owner

flyx commented Mar 10, 2023

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

@flyx flyx closed this as completed Mar 10, 2023
@jfilby
Copy link
Author

jfilby commented Mar 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants