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

default annotation #120

Open
codalogic opened this issue Mar 20, 2018 · 3 comments
Open

default annotation #120

codalogic opened this issue Mar 20, 2018 · 3 comments

Comments

@codalogic
Copy link
Contributor

(Even lower priority?)

Similar to the situation with the minExclusive and maxExclusive issue (#119), JSON Schema (+ XSD, but not in the base of Relax NG) has a default property.

If this were thought useful for JCR, it could be another annotation. For example:

"required" : @{default false} boolean ?,
"country" : @{default "USA"} string ?,
"state" : @{default $closed} ( "open" | $closed ) ?
$closed = "closed"

I hope limiting the feature to primitive types would be sufficient, especially as braces can't go in annotations. If object default were thought to be necessary, we could do something like:

"address" : @{default $downing-street} $address ?,
$downing-street = { "number" : 10, "street" : "Downing Street", "town" : "London" }
@anewton1998
Copy link
Contributor

I don't understand the use case. What does it mean? If the value is not there then assume a default value? Why would a validator care? I think for XSD and JSON Schema, the want to address instances where tool chains are generating code. Is that where we want to go?

@codalogic
Copy link
Contributor Author

For the use-case...

In YANG (imagine it's actually JSON!), the leaf rule has an optional mandatory member saying whether the leaf is required or not in an instance:

leaf name {
    type string;
    description "Name of the product.";
    mandatory true;
}

If defined in JCR, the definition would be:

"mandatory" : boolean ?

But the question is, what happens when mandatory is absent? Should the leaf be present or not? Doing something similar to:

"mandatory" : @{default false} boolean ?

let's the spec reader and implementer readily know what the semantics are without having to scan through the text.

The following might also work:

"mandatory" : boolean ?, ; default: false

I agree that a validator wouldn't benefit from it, but I think humans might.

That said, I think we can wait on this one if we think there are more important things.

@anewton1998
Copy link
Contributor

Ok. As long as we are clear that is really for humans and not validators, I'm good with it. Your annotation approach is my preference.

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