feat: add standard schema support and associated tests#2588
feat: add standard schema support and associated tests#2588GregoireBellon wants to merge 1 commit intotypestack:developfrom
Conversation
|
@braaar @NoNameProvided This would be massive if this can be supported. See discussion here nestjs/nest#14539 for possible rework? |
|
@braaar @NoNameProvided Any updates would be greatly appreciated and or appointing some new maintainers. |
|
What's left on this? Can we get this merged? |
|
Hello @niemyjski, sorry for not responding earlier, I kinda lost interest in this PR since I don't think it will ever be merged. This is not fully ready. Making class validator compliant will require adding a new API. Citing my comment on the Nest compatibility with standard schema issue :
Since nobody is currently governing the project, I don't believe that any significant change in the API will be approved. |
|
Thanks for your reply, I really like this library at this point I think I might have to fork or move to zod :( |
|
I doubt this will be making it to class-validator. I think there is a fundamental incompatibility between class decorator based validation and schema based validation. Schema based validation was intentionally dropped from the project, not because schema based validation is a bad idea, but because there are other projects that do that (I use zod myself in all my projects and love it). |
|
I was a little harsh earier. This seems like it could be good for the project and would be greatly appreciated by those who like this library. |
Description
This PR adds the support for standard schema, by copying their interface, extending the validator with it, and mapping class validator's "Validation Error" type to standard schema's "Issue".
I also wrote some tests, which are the same as the "nested validation" ones.
Since this function would be in the hot path, I tried to make it optimized, by avoiding recursion and preferring mutation to copy.
Supporting the Standard Schema interface is important, since it's blocking the adoption of it by NestJs (see related nestjs/nest/#14539)
edit: by itself, the PR in its current form would not be enough. We need to add a wrapper function, that takes a schema as input, and that outputs a validator containing the schema. Let me know if it sounds good to you.
Disclosure
I had to ignore the ESLint warning when copying the standard schema interface.
Checklist
Update index.md)develop)npm run prettier:checkpassesnpm run lint:checkpassesFixes
addresses #2577