Skip to content

Update Validator 0.18#4894

Merged
agourlay merged 6 commits intodevfrom
update-Validator-0.18
Aug 15, 2024
Merged

Update Validator 0.18#4894
agourlay merged 6 commits intodevfrom
update-Validator-0.18

Conversation

@agourlay
Copy link
Copy Markdown
Member

@agourlay agourlay commented Aug 15, 2024

This update our Validator infrastructure to the 0.18.1 version.

The important changes are:

  • #[validate] becomes #[validate(nested)] for fields implementing Validate.
  • new syntax for validation with custom function
  • a validation on an Option<_> field will be executed on the contained type if the option is Some.

}
}

impl<V> ValidateExt for Vec<V>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is fantastic. This implementation has caused some hidden panics before. 😄

validate_geo_polygon_line_helper(l)?;
Ok(())
}
_ => Err(ValidationError::new("not_empty")),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the None case is checked with an extra validation in

_ => Err(Status::invalid_argument("Malformed GeoPolygon type")),

function = "validate_unique_collections",
arg = "&'v_a mut HashSet<String>"
))]
#[validate(custom(function = "validate_unique_collections", use_context))]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the new macro refused to work with HashSet<String> and forced me to create a new struct.

See context in https://github.com/Keats/validator?tab=readme-ov-file#custom

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

😞

Since this struct doesn't leak to other places I'm totally fine with it.

@agourlay agourlay marked this pull request as ready for review August 15, 2024 11:59
@agourlay agourlay requested a review from timvisee August 15, 2024 11:59
Copy link
Copy Markdown
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

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

Thank you so much for going through all this trouble! 🙏

@agourlay agourlay force-pushed the update-Validator-0.18 branch from dc2eab4 to dcab5a5 Compare August 15, 2024 12:49
@agourlay agourlay merged commit c884438 into dev Aug 15, 2024
@agourlay agourlay deleted the update-Validator-0.18 branch August 15, 2024 13:22
generall pushed a commit that referenced this pull request Aug 26, 2024
* Update Validator 0.18

* fix new test error message

* clearer geo error message

* fix error message

* fix unit tests

* Put spaces back

---------

Co-authored-by: timvisee <[email protected]>
@timvisee timvisee mentioned this pull request Dec 16, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants