-
-
Notifications
You must be signed in to change notification settings - Fork 752
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat(schema): Make schemas validation library independent and add TypeBox support #2772
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
daffl
changed the title
feat(schema): Make schemas validation library independent and update CLI generator
feat(schema): Make schemas validation library independent and add TypeBox option
Oct 4, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking so good!
What else is left? It looks like we still need to generate TypeBox schemas?
Ahh!! @daffl @marshallswain thanks 💯 for this! |
This was referenced Oct 5, 2022
daffl
changed the title
feat(schema): Make schemas validation library independent and add TypeBox option
feat(schema): Make schemas validation library independent and add TypeBox support
Oct 5, 2022
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request allows for the schema validation hooks to take a generic
validator
function. This was the only change necessary to allow making resolvers schema validation library independent. This means resolvers and validation hooks can also be used with most other validation libraries.It also adds support for TypeBox (see the initial suggestion in #2762) as an option and the new default since it is much more intuitive to use for declaring JSON schemas.
Default application configurations schemas for both, JSON schema and Typebox have been added as well to further reduce the initial application boilerplate.
This also updates the CLI to create schemas without the now unnecessary
schema
wrapper and with separate hooks for validation and resolving. It also significantly reduces the generated code for new services and only generates aname.ts
(with hooks and registration), aname.class.ts
(with database class, related types and options) andname.schema.ts
file (with schemas and resolvers) as discussed in #2760 and with @marshallswain.A
<name>.ts
file with a schema now looks like this:The
<name>.class.ts
file (for e.g. MongoDB) like this:And the
<name>.schema.ts
file using TypeBox looks like this:A
<name>.ts
file without a schema (use at your own risk) looks like this:And the
<name>.class.ts
file like this: