-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
v6 validation: "constant" #58
Comments
I personally find |
Personally, I get the most use out of constant when combining it with $data, but you bring up an excellent point I hadn't considered with regards to ambiguity when you use enum. While I'm still pushing for $data, I think constant could stand on its own if it really needed to. |
Maybe "const" instead of "constant". Seems more natural/widely spread as a keyword, and trounces the "enum" form in character count ;-) |
It is useful, particularly in combination with $data keyword - it allows to validate joins in objects from ORM systems. |
If you're really concerned about character count, you could always use
|
This addresses issue json-schema-org#58, which got quite a few upvotes and has a "draft 6" milestone. I used the shorter "const" that several people suggested rather than "constant", but obviously that's easy to change if the longer form is preferred. The wording was pretty much directly lifted from "enum".
This addresses issue json-schema-org#58, which got quite a few upvotes and has a "draft 6" milestone. I used the shorter "const" that several people suggested rather than "constant", but obviously that's easy to change if the longer form is preferred. The wording was pretty much directly lifted from "enum".
This addresses issue json-schema-org#58, which got quite a few upvotes and has a "draft 6" milestone. I used the shorter "const" that several people suggested rather than "constant", but obviously that's easy to change if the longer form is preferred. The wording was pretty much directly lifted from "enum".
It's been over a week and no one has objected to the PR so I'm closing this as fixed. Obviously can be re-opened if someone gets back from vacation or something and wants to raise it. |
Originally written by @geraintluff at https://github.com/json-schema/json-schema/wiki/constant-(v5-proposal)
Proposed keywords
constant
Purpose
For ordinary use, this would be equivalent to a single-valued
enum
, simply tidier.The only real difference comes in its behaviour with
$data
-substitution.$data
-subsitution would be allowed for this keyword, which means that this keyword is not capable of specifying literal values of the form:{"$data":...}
, because these would be interpreted as$data
-substitutions.However, literal values of this form can still be specified using
enum
, so there is no loss of functionality.Values
The value of this keyword would be any value - however, it would be subject to
$data
-substitution.Validation
Instances are only valid if they are exactly equal to the value of this keyword.
Example
Simple constant
Valid:
{}
,{"five": 5}
Invalid:
{"five": 0}
,{"five": "5"}
Using
$data
to specify equalityValid:
{"a": "foo", "b": "foo"}
,{"a": "bar", "b": "bar"}
Invalid:
{"a": "foo", "b": "bar"}
Concerns
Similarity to
enum
Unless
$data
is being used, the same effect can be obtained using fewer actual characters:{"constant":"whatever"}
- 23 characters{"enum":["whatever"]}
- 21 charactersHowever, when used in combination with
$data
, it opens up possibilities that are not otherwise available.The text was updated successfully, but these errors were encountered: