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

Optional attributes with null values #16

Closed
andrejserafim opened this issue Nov 25, 2015 · 2 comments
Closed

Optional attributes with null values #16

andrejserafim opened this issue Nov 25, 2015 · 2 comments

Comments

@andrejserafim
Copy link
Contributor

If I have an optional field, for exapmle of type string, to be valid a document can either have the string, have the field missing or have null instead of the string. Are my expectations incorrect?

Currently the null case errors with a ValidationException.

@erosb
Copy link
Contributor

erosb commented Nov 25, 2015

or have null instead of the string

Thats incorrect. An optional field with type "string" can be a string or the key can be omitted from the document. But having the key with the null value it will be valid by this schema:

{
    "properties": {
        "myStringProp": {
            "anyOf": [
                { "type": "null"},
                {"type": "string"}
            ]
        }
    }
}

@andrejserafim
Copy link
Contributor Author

Fair enough - thank you for clarifying.

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