-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Mappings editor] Use Avj schema validator instead of io-ts #56272
Comments
Pinging @elastic/es-ui (Team:Elasticsearch UI) |
@sebelga Thanks for creating this issue for discussion! I really appreciate it 🙂. Some of my thoughts:
Overall I think we should go with the tool that doesn't incur too much tech debt in using it while not hampering productivity as you've illustrated. If [UPDATE] One other thing to consider is that we do want to keep the list of dependencies as short/secure/clean as possible so auditing the dependencies of |
Yes indeed About documentation: it is indeed very complex and poorly written for people not so familiar with advanced Typescript concepts and functional programming. We finally "get" it more by trial and error than understanding the docs.
See my answer above but I could think of many. Like I said we not only need to validate that a value is a certain type, we should be able to validate that the value is also valid according to our business rules. My opinion is that we should have a tool that does not limit ourselves. Looking at AVJ doc it seems that string can be validated as Also, I am proposing
Great point, I also think we should keep the list of deps short. This is why the first thing I asked you when the To answer your question, it has 4 dependencies
None as we have a fix (hack 😊 ) for the mappings editor validation in place. But as I said above, if we do find value in |
I think the closest we have to a default validation library is There seems to be better typescript support coming for AJV ajv-validator/ajv#736 (comment) One benefit of io-ts is that so many teams are already using it, so before we would make a recommendation for a new default we also need to weight up the effort to convert any existing validation vs the potential benefits. |
Currently, we use the
io-ts
lib to validate the configuration of the mapping (the complete object without theproperties
anddynamic_templates
parameters).As I was working on the fix to support mappings type in index template I struggled to make the
io-ts
schema strict, not allowing unknown properties to be declared. I realized it was not possible and had to use a hack to make it work.If we validate the following mappings
To make it fail with
io-ts
we need toIf we compare with
avj
, this is how we would do it (if this looks like ES mappings declaration... it is pure coincidence ! 😄 )avj
goes much further when it comes to schema validation, I let you look at its features. The strength ofio-ts
lies in the fact that we can retrieve Typescript Types out of its schema, but in practice, we don't need that feature.We do need a robust validation schema declaration (like Joi gave us) that runs in the browser and allows us to validate our JSON simply.
cc @cjcenizal @jloleysens
The text was updated successfully, but these errors were encountered: