Skip to content
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

Compatibility with standard-schema #14539

Open
1 task done
BrunnerLivio opened this issue Jan 30, 2025 · 10 comments
Open
1 task done

Compatibility with standard-schema #14539

BrunnerLivio opened this issue Jan 30, 2025 · 10 comments

Comments

@BrunnerLivio
Copy link
Member

BrunnerLivio commented Jan 30, 2025

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

There are numerous schema validators out there. This has spawned an ecosystem around NestJS with various integrations such as nestjs-valibot and many others.

Describe the solution you'd like

NestJS could support stanadard-schema which recently hit 1.0.0:

Standard Schema is a common interface designed to be implemented by JavaScript and TypeScript schema libraries.

With that a commonly shared ValidationPipe could be offered directly from the framework instead of copy/pasting the integrations from the docs site.

Teachability, documentation, adoption, migration strategy

Guide on how to accept Standard Schema: https://standardschema.dev/#how-do-i-accept-standard-schemas-in-my-library

  • Offer a general ValidationPipe that is compatible with standard-schema
  • Update the docs how the ValidationPipe can be utilised with different schema libraries

What is the motivation / use case for changing the behavior?

I think it makes NestJS more future-proof with any future schema/validation library that might come

@BrunnerLivio BrunnerLivio added needs triage This issue has not been looked into type: enhancement 🐺 labels Jan 30, 2025
@BrunnerLivio
Copy link
Member Author

Notably, there is an issue open on class-validator side around this topic as well:
typestack/class-validator#2577

@micalevisk
Copy link
Member

I like the ideia but I think this should start as a 3rd-party lib to see community's adoption

@kamilmysliwiec
Copy link
Member

I guess there's nothing we can do until class-validator supports the standard schema too (to avoid breaking changes)

@micalevisk micalevisk removed the needs triage This issue has not been looked into label Jan 30, 2025
@0x0bit
Copy link

0x0bit commented Feb 21, 2025

Unfortunately, the class-validator isn't updated much anymore。typestack/class-validator#1775

@micalevisk
Copy link
Member

@0x0bit well

Image

@0x0bit
Copy link

0x0bit commented Feb 24, 2025

@0x0bit出色地

Image

But he didn't spend any more time in the repository; the latest update was only a month ago.

@niemyjski
Copy link

Would be nice to get standard-schema across the finish line and some resources added to class-validator. PR: typestack/class-validator#2588

@GregoireBellon
Copy link

GregoireBellon commented Mar 12, 2025

I initiated a PR for class-validator to support the Standard Schema, and it led me to think that NestJs should not wait for it to be merged before adding support for standard-schema.

Standard Schema assumes that the validator is closely tied to the schema it uses to validate a DTO, and that a DTO can be a standard JavaScript object.

Class-validator's validator stores all validation constraints in a singleton context called "ValidationMetadata" and it relies on the DTO's constructor to identify the validation constraints related to the DTO. This means a DTO must be an instance of a class.

This difference in philosophy means that class-validator will need additional APIs to support Standard Schema's approach.

I think that building a new Validation Pipe, or adapting the current pipe to support standard-schema would be easier to maintain and faster to implement (especially since class-validator's repository does not seem not very active).

The nest-zod package basically contains all the logic we need; we just need to replace "zod" with "standard schema".

@niemyjski
Copy link

Thanks for your pr! I think it would be extremely beneficial to be apart of the core library. I think new maintainers is key and simplifying the library possibly for easier maintenance and scope.

@0x0bit
Copy link

0x0bit commented Mar 13, 2025

I think that building a new Validation Pipe, or adapting the current pipe to support standard-schema would be easier to maintain and faster to implement (especially since class-validator's repository does not seem not very active).

Absolutely!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants