Skip to content

provide defaults for all keywords and subschemas that lacked them #1006

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

Merged
9 changes: 4 additions & 5 deletions meta/applicator.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"items": { "$dynamicRef": "#meta" },
"contains": { "$dynamicRef": "#meta" },
"additionalProperties": {
"$dynamicRef": "#meta",
"default": {}
"$dynamicRef": "#meta"
},
"properties": {
"type": "object",
Expand All @@ -33,8 +32,7 @@
"default": {}
},
"propertyNames": {
"$dynamicRef": "#meta",
"default": {}
"$dynamicRef": "#meta"
},
"if": { "$dynamicRef": "#meta" },
"then": { "$dynamicRef": "#meta" },
Expand All @@ -50,5 +48,6 @@
"minItems": 1,
"items": { "$dynamicRef": "#meta" }
}
}
},
"default": true
}
3 changes: 2 additions & 1 deletion meta/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"contentEncoding": { "type": "string" },
"contentMediaType": { "type": "string" },
"contentSchema": { "$dynamicRef": "#meta" }
}
},
"default": true
}
3 changes: 2 additions & 1 deletion meta/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"type": "string",
"format": "uri-reference"
}
}
},
"default": true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree with having defaults in the roots of the meta-schemas. What's the motivation for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that the motivation is to avoid putting "default": true everywhere we reference a schema, but the default isn't always "true" for all references.

Traditionally, in our meta-schemas, default has meant something like: if this doesn't exist, the validation result would be the same as if it did exist and had this default value. For example, the default of properties is {}. Therefore, {} has the same result as { "properties": {} }.

So, now consider the not keyword. It references the top-level meta-schema. If the top-level meta-schema has "default": true that says the default of not is true. Therefore, {} has the same result as { "not": true }, which is not correct. That means each time something references the top-level meta-schema it needs to define a default that makes sense in its context.

... or just get rid of default in meta-schemas altogether because it doesn't provide any real value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdesrosiers I think we're arguing the same side of the coin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are. Bottom line is that default doesn't belong at the root of meta-schemas.

Copy link
Member Author

@karenetheridge karenetheridge Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, now consider the not keyword. It references the top-level meta-schema. If the top-level meta-schema has "default": true that says the default of not is true. Therefore, {} has the same result as { "not": true }, which is not correct. That means each time something references the top-level meta-schema it needs to define a default that makes sense in its context.

Or, we can add a default for not -- which should be false. that is, ..., "not": { "$dynamicRef": "#meta", "default": false }, ...

So, how about we remove all uses of default where it's just the obvious thing ({} for objects, [] for arrays, or trueor {} for schemas), and keep them only when they're non-standard -- which is, I believe, just "not", "deprecated", "readOnly", "writeOnly", "uniqueItems", and "minContains".)

If that's amenable to all I can amend this PR.

}
3 changes: 2 additions & 1 deletion meta/format-annotation.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"type": ["object", "boolean"],
"properties": {
"format": { "type": "string" }
}
},
"default": true
}
3 changes: 2 additions & 1 deletion meta/format-assertion.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"type": ["object", "boolean"],
"properties": {
"format": { "type": "string" }
}
},
"default": true
}
3 changes: 2 additions & 1 deletion meta/meta-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"type": "array",
"items": true
}
}
},
"default": true
}
3 changes: 2 additions & 1 deletion meta/unevaluated.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"properties": {
"unevaluatedItems": { "$dynamicRef": "#meta" },
"unevaluatedProperties": { "$dynamicRef": "#meta" }
}
},
"default": true
}
6 changes: 4 additions & 2 deletions meta/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"type": "object",
"additionalProperties": {
"$ref": "#/$defs/stringArray"
}
},
"default": {}
}
},
"$defs": {
Expand Down Expand Up @@ -94,5 +95,6 @@
"uniqueItems": true,
"default": []
}
}
},
"default": true
}
3 changes: 2 additions & 1 deletion schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
"$ref": "meta/core#/$defs/uriReferenceString",
"deprecated": true
}
}
},
"default": true
}