Validate contribution docs against schema #92
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/contribution_schema"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently requires an open PR branch for the schemas, which is adding date and time for contributions.
refs #30
yay, and wow such regexp! :D
@ -3,0 +13,4 @@
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : "A valid ISO 8601 full-time string is expected";
}
})
afaik we use the same format for the proposals and a proposal once accepted creates a contribution.
So we should probably add this also in the proposal wrapper.
does this work? thought the callback should get an error object.
@ -3,0 +13,4 @@
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : "A valid ISO 8601 full-time string is expected";
}
})
Yeah, but proposals aren't really part of MVP.
We need to reject with the tv4 error object either way. It does show the error and doesn't stall. So it works well enough to be usable, yes.
@ -3,0 +13,4 @@
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : "A valid ISO 8601 full-time string is expected";
}
})
yeah, though it might be worth to move this into a separate file that exports validator
and then do a
const validator = require('validator')
?I somewhat dislike that we do a
JSON.stringify
in the ContributionSerializer and then do aJSON.parse
again to validate it.maybe we can have two function in the ContributionSerializer?
of even do the validation in the ContributionSerializer?
something like:
but we can refactor that later I guess.
Yes, makes sense! We can refactor it when adding validation for contributor details.
(I also thought about adding it to the schemas library, but decided against it, because I think it shouldn't prescribe what to do with the schemas and then load that additional code.)
Maybe something like:
.validate
should use_serialize()
to do the work andserialize()
can use the private method as well but returns the JSON string...I think the overhead of
_serialize()
is not much so we can do it twice.@ -3,0 +13,4 @@
const timeRegexp = /^([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))$/;
return timeRegexp.test(value) ? null : "A valid ISO 8601 full-time string is expected";
}
})
I think it makes a lot of sense to have everything in the serializers. Still not sure how best to implement the validation in the serializer...
Already came up with an even cleaner solution. Promisify ALL THE THINGS. ;)
d953141f52/lib/contracts/contribution.js (L51-L54)