-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refactor codemeta validation code #43
Conversation
What is the reason for moving functions from
We need to handle that complex structure (value in object in array) either way, because that structure is also valid in compacted documents. The reason for expanding is that when working with the expanded version then documents only use that structure instead of allowing multiple variants (value, value in array, value in object, value in object in array) |
if (validator === undefined) { | ||
// TODO: find if it's a field that belongs to another type, | ||
// and suggest that to the user | ||
setError(`Unknown field "${fieldName}" in "${parentFieldName}".`) | ||
setError(`Unknown field "${compactedFieldName}".`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to keep the in <parent field>
part, it's very useful to debug when you have a document like this:
{
"description": "Foo",
"author": [
{
"description": "Bar"
}
]
}
so the user understands which instance of "description"
is invalid.
function switchCodemetaContext(codemetaJSON, contextUrl) { | ||
const previousCodemetaContext = codemetaJSON["@context"]; | ||
codemetaJSON["@context"] = contextUrl; | ||
return previousCodemetaContext; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of altering the argument and returning the previous context; could you return a new object with the new context, and not change the argument? I think it would be less confusing, and removes the need to switch it back.
The reason for moving code is for better readability. IMHO, the functions moved to
This PR might not fit the initial use case then, but I feel like I'm not comfortable enough with jsonld to be able to validate the expanded version (I feel like I will handle objects and arrays and |
I don't see the reason to make a distinction, describing the type of each field is as much business code as the rest.
We need to be able to handle them anyway, because they can also show up in the compacted version. Which one to expect should be precisely described in https://github.com/codemeta/codemeta/blob/master/codemeta.jsonld :
|
Not applicable anymore. |
Relates to #29.
This PR tries to improve the codemeta validation code, especially removing some hacks (e.g. coming from multi-version handling, like https://github.com/codemeta/codemeta-generator/pull/34/files/c2d17bd25f6924ea4a5fdab50a72250773b47d15#r1574302506).
After reviewing what's been done in other libraries (e.g. codemetar, eossr, caltech), I've noticed that:
Thus, validating the expanded version did not seem like the right way to do it contrary to what was stated in #29, as it would introduce a lot of complexity to handle the complex structure of that version.
However, what I could think of to answer #29, was to compact the codemeta document into our internal context (which contains all the fields from all the versions, already used for multi-version generation) so that it becomes possible to validate a multi-version document without having to deal with any specific case.