Document db::Json types as input fields, or add a public derive for them
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- rust
- Domain
- backend-api-design, documentation
Research direction
Read the validation guide’s “Nested objects” section and the JSON columns section in docs/models.md, then compare their descriptions with the behavior noted in macros/database/src/binding.rs around line 55. The issue offers documenting db::Json input fields or adding a public derive; an open pull request, #837, is already linked. Done means the chosen approach is documented or exposed publicly and its behavior is clear to package authors.
Written by the indexing model from the issue text.
Description
Problem
A package can give a type to an application, and the application puts the type in its own #[laravel::input] struct. For example, the type holds a signed payload that a browser API returns. The type wraps a type from another crate, so it cannot be a #[laravel::input] struct with rules on each field.
The only method that I found is to derive db::Json on a tuple struct:
#[derive(Debug, Clone, Serialize, Deserialize, db::Json)]
#[serde(transparent)]
pub struct SignedPayload(other_crate::Payload);
#[laravel::input]
pub struct Confirm {
payload: SignedPayload,
}
The method works because the db::Json derive implements laravel::validation::__private::Project for an enum or a tuple struct. The comment in binding.rs L55 says: "A form field of the type validates as the JSON it serializes to."
The documentation does not describe this behavior:
- The JSON columns section describes
db::Jsononly for a database column. - The nested objects section says that a nested object is a
#[laravel::input]struct. - The
Projecttrait is in a__privatemodule.
A package that uses this behavior depends on an internal detail, and a patch release can break it. Also, a type that never goes into a database must derive a database trait.
Proposal
Do one of these two things:
- Document the behavior in the validation guide. Say that a field of a
db::Jsonenum or tuple struct validates as the JSON that it serializes to. - Add a public derive for an input field that has no rules on its own fields, for example
#[derive(validation::Opaque)]. Thendb::Jsonstays a database derive.
Option 2 is better for packages. Option 1 is sufficient.
- 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 72/100
Maintainers usually reply within 1 day
-
Commit lockfileOpen
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
rust-lang/socket2#703 · 1 comment ·
Maintainers usually reply within 1 day
-
infra
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
available bug good first issue tooling
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Nixitov/Riptide-Native#817 ·
Maintainers usually reply within 1 day