Custom fields with custom validation for reuse between structures.
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
No files or tests are named. Start by locating the validation derive handling for #[validate(customtype)] and the restriction on unnamed fields; use the LocaleName example to trace the intended behavior. Done means a single-field tuple struct can validate its inner value while existing named-field behavior remains intact, with coverage for the example.
Written by the indexing model from the issue text.
Description
Marshmallow has an option of defining custom field types that can be reused multiple times. This significantly reduces logic errors when you have to reuse the same field over and over again across the whole business logic.
Right now there is a limitation that structs annotated with #validate should have only named fields.
Is it possible to remove that limitation for a case when a structure has only one unnamed field and nothing else. And in this case validate the inner data instead?
Below is the code example that utilizes this feature: both UpdateLocaleRequest and GetLocaleResponse use the same type LocaleName which has a validation defined on the struct and propagated to fields that use this type by having #[validate(customtype)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
#[validate(length(equal = 2))]
pub struct LocaleName(pub String);
#[derive(Serialize, Deserialize, JsonSchema, Validate)]
struct UpdateLocaleRequest {
/// user_id is ignored. need for old api.
user_id: Option<u64>,
/// Locale name
#[validate(customtype)]
locale: LocaleName,
}
#[derive(Serialize, Deserialize, JsonSchema)]
struct GetLocaleResponse {
/// Locales' names
locales: Option<Vec<String>>,
/// The unique identifier for the user.
user_id: Option<u64>,
/// Locale name
#[validate(customtype)]
locale: Option<LocaleName>,
}
- Dominant language
- Rust
- Stars
- 2.5k
- Forks
- 190
- PR merge metrics
- No merged PRs in 30d
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 Keats/validator
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 5/5 Over a week Newbie friendliness 18/100
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 55/100
Similar issues
-
A-git C-bug S-needs-info
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
rust-lang/cargo#17794 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
LadybirdBrowser/ladybird#15821 ·
Maintainers usually reply within 1 day
-
`SortMergeJoinExec` panics instead of returning an error when its output coalescer rejects a batchOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
apache/datafusion#27728 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
limitlessprojects/Go-Hybrid#4764 ·
Maintainers usually reply within 1 day
-
enhancement good first issue ready
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MartinPTielemans/ilo#4238 ·
Maintainers usually reply within 1 day