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
Support custom validation through comment tags #560
Comments
There had been lots of people who wanted custom validation tools. However, it was hard thing for me because In nowadays, @TheYarin had suggested me an idea about this custom validation tool supporting - #550. I couldn't accept the issue because cannot sure which file or statement (validate function call vs adding custom logic) would come earlier. However, I could determine custom validation spec by getting hints from his idea. I specially thanks to @TheYarin. |
Anyway, I repeat that, above design is just a plan and not fully determined. If you have any good idea about detailed interface, please let me know by writing a comment under here. |
The API you suggested feels really cumbersome compared to typia's clean API: nested function definitions and calls, hardcoded type name instead of properly referencing the type... My personal (biased) opinion is that a custom validator function that is attached to a type will be more useful. Now, you mentioned the problem is you need to know at compile time that a certain type has a custom validator, but you can't know that for sure because of the random order of the files being compiled - typia might be getting a validate call before it gets the custom validator definition. So how can we change that? In these files, we can have the validator definition, for example: We can avoid having to specify the custom validators locations by going over the codebase twice (first to find all references to (A more refactor-friendly approach to manually specifying all the different validators is to re-export them from a single file, something like |
Close #560 - support custom validation tags
The examples of custom tags you've written are examples that can be written sufficiently with the current "@pattern". And most of the examples are expected to be sufficiently replaced by @pattern. (If there is a case that is not like that, it would be nice if someone could tell me. ) Why don't you make a custom annotation written in @pattern so I can refer to it by another name? If we allow these attempts to contribute to typia, I think we can gradually increase the @pattern annotation with various references and increase the usability of typia. /**
* Custom feature composed with "$" + number
*
* @pattern ^\$?\d+(\.\d+)?$ dollar
*/
dolloar: string; It's an idea that I threw after thinking about a few minutes, so I hope you take it lightly. |
However, in the |
There is no immediate way to think of it. Maybe there's no answer even if I think about it for a long time. However, I wonder if the function that people are asking for is really adding customization functions in typia, and I think what people want is a variety of functions that have already been implemented. For example, there are validators such as @isemail() and @IsPhoneNumber() in class-validators. These can also be implemented as custom validators, but it is much easier for developers to bring and use pre-implemented in class-validators. Why are you developing custom features first instead of adding these features? Is this to keep typia lighter? ( I agree that customization is such a great thing! ) |
My answer is I need this feature for my project |
Complement #560 - determine custom validator spec
@samchon Have you considered my suggestions above? |
@TheYarin Tried to implement, but out of my ability. Will you challenge it? |
@samchon That'll require a deep dive into Typia's codebase. I'll give it a try when I have the chance. |
@samchon I think, a custom tag not work on typia.random. |
@industriously Yes, it is only for validation. |
@samchon will be supported in the future ? |
Have any idea about random generation utilizing comment tags, it is okay to suggest by writing a new issue |
@samchon did you drop |
https://typia.io/docs/validators/tags/#customization Changed to type safe way. |
Thank you. Special thanks for preserving comment tags.
Just FYI there are some projects (like ours) with a shared package with pure TypeScript types used all around the project, for instance, in |
Unfortunately, comment tags based custom validator and type tag based custom validator cannot be compatible. |
From v3.7 update,
typia
will support custom validation functions through comment tags.You can utilize the custom validation like below:
The text was updated successfully, but these errors were encountered: