-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Epic: Validation at Model/ORM level #1872
Comments
@David-Mulder could you be more specific please? What kind of validations do you have in mind? I acknowledge that the current set of validations offered by the data-access layer of LB4 is way too small. In LoopBack 3.x, it was possible to use one of the few built-in validation rules like "validatesPresenceOf", "validatesLengthOf", etc. In our experience, these rules were not sufficient enough and were difficult to use & extend anyways. Let's discuss the use cases and requirements for a better validation in LB4. |
(FWIW, the discussion in #1624 has some interesting bits to be carried over to this epic.) |
I was thinking about ORM-level validations in the past few days and want to post few ideas and opinions.
I am thinking about the following high-level design:
Additional ideas/requirements:
@raymondfeng @strongloop/loopback-maintainers what's your opinion? Do you agree with my proposal? Is there anything you would like to add? |
I would like to add a related issue to the mix. Performing a CRUD operation using a relation is also unnecessarily throwing validation errors. For example: |
Good catch! I think that we should modify the controller to remove the foreign-key property from the OpenAPI schema describing the input parameter. Let's make this improvement a part of #2653. |
Hi @bajtos, any visibility on when the model validation will be available? Or maybe you can point me towards an interim solution to achieve custom business validation, similar to that of LB3 Model.validateAsync which is applied every time the model is created/updated. |
Sorry to bump in again, however, it's important to have model validation. Is this being planned for the near future? If not, kindly suggest an interim approach to do custom business logic validation at the model level. |
I think one of the ways is to use interceptor. You can create a class level interceptor for the controller so that all requests need to go through your validation before further processing. I have a sample app in this blog post: https://strongloop.com/strongblog/loopback4-interceptors-part2/ |
Controller level validators work only for requests, however, model level validations work for every data-access on the model. As of now, I am thinking to use ajv in the repository for doing custom async validation for data-access methods of models. |
Yesterday in a Maintainers Call, @raymondfeng proposed to refactor the current AJV-based validation layer in REST to make it more flexible and allow us to use it at ORM level too.
|
@bajtos Do you believe that property value validation that adheres to some business logic is also valid for ORM level validation ? This required some async operations (querying the database) and also provided a proper invalid value message with I found this really useful and we used it extensively in our implentations, because we could easily provide feedback to the users by using the What are your thoughts on that?
|
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
Feel a bit guilty about asking this like this, but considering this is currently "released", how are we supposed to do validation?
As far as I can tell the model doesn't support any validation (per #1624) and frankly I am at a loss at how to use this without validation? Of course you could manually do the validation in the controller, but that destroys the point of an ORM 😅 . What am I missing?
Or is this not yet supposed to be used for CRUD API's?
The text was updated successfully, but these errors were encountered: