Custom validation rules have no documented way to reach the request
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- rust
- Domain
- backend-api-design, documentation
Research direction
Start with laravel-rust-http-0.2.0/src/validation/mod.rs around line 846 and the validation guide. Check the open pull request #877 to see how the work is progressing and whether the intended API is settled. Done means documenting Field::request, including request context and the error when validation runs outside a request.
Written by the indexing model from the issue text.
Description
A custom ValidationRule sometimes needs the request: its session, the client IP, or the logged-in user. Field::request(&self, rule: &str) -> Result<&Request> exists and works with Valid and request.validate(), but it is #[doc(hidden)], so packages can't rely on it staying public. The documented alternative is building the rule inside ValidatesRequest::rules, which receives &Request, but that doesn't work for a rule used inside #[validate(...)] attributes.
Example: a rule that checks a submitted answer against a value stored for the visitor's session:
impl ValidationRule for SessionAnswer {
async fn validate(&self, field: &Field<'_>) -> Result<(), RuleError> {
let request = field.request("session_answer")?; // hidden API today
let session = request.session()?;
// compare field.value with what the session expects
Ok(())
}
}
Suggestion
Make Field::request part of the documented API, with a short section in the validation guide on rules that need the request (session, IP, user), and on the error a rule gets when it's validated outside a request.
Seen on 0.2.0 (laravel-rust-http-0.2.0/src/validation/mod.rs:846); the same on 0.x at 6156f0e. I'm happy to send a docs PR if this is the intended API.
- Dominant language
- Rust
- Stars
- 847
- Forks
- 174
- Avg merge
- 5h 40m
- Merged PRs (30d)
- 167
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from laravel/rust-framework
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
laravel/rust-framework#864 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
laravel/rust-framework#876 ·
Maintainers usually reply within 1 day
-
Case-sensitive contains, starts_with and ends_with that match % and _ literally on every databaseOpen
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#874 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
laravel/rust-framework#873 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 58/100
laravel/rust-framework#872 ·
Maintainers usually reply within 1 day
All issues in laravel/rust-framework
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
neuralmagic/crucible#579 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
eclipse-score/kyron#249 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
seanmonstar/reqwest#3157 ·
Maintainers usually reply within 2 days