-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
json schema validation: enforce lowerCamelCase keys #987
Comments
Is this a good idea?
|
I'd not say that parsing is easier or harder, but usage. In some languages keys are transformed in a way that we can use the keys name as an accessor of a struct/object/record like thing (eg. I'm not affected by that in erlang anyway. But I have to match on the keys using atoms, and usually atoms in erlang are alphanumerics + underscore, beginning with lowercase alpha. I can though construct atoms that contain all kind of characters (in modern erlang even unicode characters) as long as they do not exceed 256 (or was it 255) bytes in their UTF8 representation. But I have to quote them then using single-quote character: ( So even here I'd prefer a way that avoids quoting the key. |
Agreed. I'm also in favor of enforcing |
@Insti Are you still interested in working on this issue? |
Looking at the current canonical-data schema, it looks like this has been implemented. |
As you can see in #1925, what has been asked for in this issue has not been implemented, because #1925 passed CI. So if this issue is to be closed, the reason can't be "it has already been implemented" (because it hasn't); the reason has to be "we chose not to implement it". This comment is neither a recommendation for or against closing this issue. |
I misread the issue and assumed this was about the property key, and not the input/expected keys. for file in exercises/*/canonical-data.json; do
if [ $(jq -e -r '[paths | join(".") | select(. | contains(" "))] | length > 0' $file) == "true" ]; then
echo $file
fi
done This did not output any file, so it looks like we don't yet have any keys with spaces. |
Hi, @ErikSchierboom . I think you could use {
"type": "object",
"propertyNames": {
"pattern": "^[a-z]+([A-Z][a-z]+)*[A-Z]?$"
}
} ...but that would not enforce the pattern inside nested objects automatically, so the following would be valid: {
"validKey": {
"Invalid Key": null
}
} Edit - Below is the simplest solution I was able to write to restrict all keys to a regexp. I divided it in three definions, instead of just one, to make usage more flexible: $defs:
lowerCamelCaseArray:
type: array
items:
$ref: "#/$defs/lowerCamelCaseValue"
lowerCamelCaseObject:
type: object
patternProperties:
"^[a-z]+([A-Z][a-z]+)*[A-Z]?$":
$ref: "#/$defs/lowerCamelCaseValue"
additionalProperties: false
lowerCamelCaseValue:
anyOf:
- type: "boolean"
- type: "null"
- type: "number"
- type: "string"
- $ref: "#/$defs/lowerCamelCaseArray"
- $ref: "#/$defs/lowerCamelCaseObject"
$ref: "#/$defs/lowerCamelCaseObject" Please, check if it works as expected! Right now, I don't have the time to write the PR, but I hope this helps. 😄 |
I just wrote #1929 to check the possible impact of the change. The following exercises have nonLowerCamelCase keys:
At first sight, there are different problems:
ps: We should probably consider upgrading Edit: I just saw the
It's been a while since the time I was active here, so maybe I'm getting something wrong, but I think this design rules out enforcing new schema restrictions on |
Wow, so many keys in a different format. That is problematic.
You are totally correct. The only option we have is to add new test cases that reimplement existing ones, but such a change shouldn't change the actual keys as it will still break things that way. I think we'll have to consider not enforcing lowerCamelCase for |
Ah, right, because in What is the minimum we could do? Something like: Only enforce the first level of keys under Would that still have value? |
I think so, as the keys on the first level of @rbasso Could you check to see if there are any first-level |
@ErikSchierboom , changing the schema to enforce
Anyway, I think this PR should be closed for now, because the inability to enforce new schema rules is a limitation implied by design choices, which cannot be simply fixed without a new design. If I remember correctly, when the schema was created (#602) - after a long and heated discussion (#336) I partially regret 😬 - we allowed nested groups of tests forming a tree-like structure, to model the existing data, and the entire file was versioned to allow test generators to detect API-breaking and content-only changes. If I understand correctly #1674, test cases now have UUIDs and are treated as immutable entities, which tracks may implement. I think #602 and #1674 have underlying conflicting views, because, in #602, the I think the current
I didn't read all the discussion behind #1674, so take anything I wrote with a grain of salt, but I guess this is a "design smell" |
Thanks for the writeup. We'll need to consider these things in more detail. |
There is a json schema definition for the
canoncial-data.json
file.https://github.com/exercism/problem-specifications/blob/master/canonical-schema.json
However this still allows for arbitrary keys containing spaces.
These keys are often used for specifying test input arguments.
problem-specifications/exercises/food-chain/canonical-data.json
Line 21 in 637cca6
Task
Update the https://github.com/exercism/problem-specifications/blob/master/canonical-schema.json to require all keys to be lowerCamelCase
The text was updated successfully, but these errors were encountered: