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

feat(docs): add validation docs #4874

Merged
merged 1 commit into from
Mar 27, 2020
Merged

feat(docs): add validation docs #4874

merged 1 commit into from
Mar 27, 2020

Conversation

dhmlau
Copy link
Member

@dhmlau dhmlau commented Mar 12, 2020

Add more documentation on how to add validation to a LoopBack application.

Propose to add the validation docs under "Usage scenarios"
Screen Shot 2020-03-13 at 11 25 40 AM

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

Copy link
Contributor

@agnes512 agnes512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, just have some nitpicks 😄

calling a service to check if an address is valid. You can also create global,
class-level or method-level interceptors.

You can create interceptors using the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a tiny nitpick: You can create interceptors using the.. -> Interceptors can be created by... as we have ' You can also create global...' above.

docs/site/Validation.md Outdated Show resolved Hide resolved
docs/site/Validation.md Outdated Show resolved Hide resolved
The validation in the ORM layer is to make sure the data being added or updated
to the database is valid.

There is validation coming from the legacy juggler. The validation is enforced
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps provide a link to legacy juggler?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is validation coming from the legacy juggler

There is some validation done in legacy juggler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation is enforced at the database level, there is not much additional constraints we can set
beyond the database ones

The validation is enforced at the database level, so there aren't many additional constraints we can set
beyond the database ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can mention schema constraints enforced by specific DBs, such as unique index.

For preprocessing against CRUD operations, we can refer to https://loopback.io/doc/en/lb4/migration-models-operation-hooks.html.

docs/site/Validation-REST-layer.md Outdated Show resolved Hide resolved
docs/site/Validation-REST-layer.md Outdated Show resolved Hide resolved
docs/site/Validation-REST-layer.md Outdated Show resolved Hide resolved
## Add validation function in the Controller method

The simplest way is to apply the validation function in the controller method,
that is:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is

is

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe like this?

The simplest way is to apply the validation function in the controller method.
For example:

docs/site/Validation-controller-layer.md Outdated Show resolved Hide resolved
docs/site/Validation-controller-layer.md Outdated Show resolved Hide resolved
docs/site/Validation-controller-layer.md Outdated Show resolved Hide resolved
docs/site/Validation-controller-layer.md Outdated Show resolved Hide resolved
@dhmlau
Copy link
Member Author

dhmlau commented Mar 13, 2020

@strongloop/loopback-maintainers, regarding the discussion around adding an example repo for validation, I have my app in https://github.com/dhmlau/loopback4-validation-example. Any objection to create another example in loopback-next? I don't mind either way, just don't know if it worths a separate example for that. Thanks!

@raymondfeng
Copy link
Contributor

@dhmlau Maybe we can add some information about using 3rd party validation libraries, such as:

@dhmlau dhmlau force-pushed the validation2 branch 2 times, most recently from dfc5d08 to 5820df2 Compare March 24, 2020 18:00
@dhmlau
Copy link
Member Author

dhmlau commented Mar 24, 2020

@raymondfeng @emonddr @agnes512 @achrinza, I've updated the PR based on the changes in the validation-app. PTAL again. Thanks!

Copy link
Contributor

@agnes512 agnes512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 nice work!

docs/site/Validation.md Show resolved Hide resolved
Copy link
Contributor

@nabdelgadir nabdelgadir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

docs/site/Validation-REST-layer.md Outdated Show resolved Hide resolved
docs/site/Validation-REST-layer.md Outdated Show resolved Hide resolved
Copy link
Contributor

@jannyHou jannyHou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏

docs/site/Validation-controller-layer.md Show resolved Hide resolved
Let's take a closer look at how validation can be added in the following layers:

- [REST layer](Validation-REST-layer.md)
- [Controller layer](Validation-controller-layer.md)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe have the description consistent with the url and title?

Validation in the Controller, Repository and Service Layer

Copy link
Member Author

@dhmlau dhmlau Mar 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be your suggested change?
If I understand your comment correctly, since the sentence before the bullets are “… look at how validation can be added in the following layers:“, so it won’t make sense to make the bullet:
from REST layer to validation in REST layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh let me clarify, I meant using "Controller, Repository and Service layer"

@dhmlau dhmlau force-pushed the validation2 branch 2 times, most recently from 8429463 to dc7ed3b Compare March 27, 2020 01:40
@dhmlau dhmlau merged commit 3506e5d into master Mar 27, 2020
@dhmlau dhmlau deleted the validation2 branch March 27, 2020 12:55
Copy link
Contributor

@hacksparrow hacksparrow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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

Successfully merging this pull request may close these issues.

8 participants