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

A less strict mode of MapYaml.AndRequireFullProjection #17

Open
pkese opened this issue Sep 27, 2019 · 4 comments
Open

A less strict mode of MapYaml.AndRequireFullProjection #17

pkese opened this issue Sep 27, 2019 · 4 comments

Comments

@pkese
Copy link

pkese commented Sep 27, 2019

In MapYaml.AndRequireFullProjection with Schema:

type Schema = {
    dict: Map<string,string>
    number: int
    items: int list
}

and an empty document:

# empty document

There is an expected deserialization error due to full projection not being satisfied. They way to remedy that is to redefine the schema as:

type Schema2 = {
    dict: Map<string,string> option
    number: int option
    items: int list option
}

The question here is:

It is unambiguous that a missing int should always be reported. Yet for dictionaries, lists and arrays, there is an interpretation, that a missing item might mean an empty dictionary, list or array (maybe someone had their yaml serializer configured to omit serialization of empty dictionaries to save some space).

My issue is that the only way to parse such document is to define lists and dictionaries as in Schema2. But then each time I'm accessing items in such a dictionary, I have to go through an option first and there is a lot of unnecessary and hard to read code.

Maybe there could be an option to have another less strict version of AndRequireFullProjection that would allow to instantiate empty complex structures that have default initializers (lists, dictionaries, arrays, but not strings or typed structures).

As a user, if I'd be interested whether the array was there or not, I could still define my schema as this and still get full control over deserialization results:

type Schema = {
    dict: Map<string,string> // I don't care, just create an empty map if the key doesn't exist
    number: int // must be present or deserialization will fail
    items: int list option // here I'm, interested if the key was present in yaml document so give me the option
}

This was intended for discussion. I can live with what we have right now, but it gets a bit annoying and verbose.

@fjoppe
Copy link
Owner

fjoppe commented Sep 29, 2019

Did you try to parse Schema option type? An empty document suggests that the whole thing is optional.

@pkese
Copy link
Author

pkese commented Sep 30, 2019

Yeah, yeah, except it is not just the top level...
It's turtles all the way down. :)

@pkese
Copy link
Author

pkese commented Sep 30, 2019

I'll just close this - it's probably too much effort for a somewhat obscure use-case.

@pkese pkese closed this as completed Sep 30, 2019
@fjoppe fjoppe reopened this Nov 11, 2019
@fjoppe
Copy link
Owner

fjoppe commented Nov 11, 2019

I'm reopening this one. Because of all the other stuff going on, I've had not taken the time to read your question well enough and to understand it. But I wanted to return to this one when I had some more time.

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