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

This add the possibility to define minimum and maximum for Duration #60

Closed

Conversation

StivenAigleIxxi
Copy link

With the help of some crate like serde_with, it is possible to serialize and deserialize Duration.

With modification serde_valid is able to define minimum and maximum for this type.
To define such minimum, we use the attribute validate with the parameter minimum_duration like this
#[validate(minimum_duration="10ms")], "10ms" is transformed into Duration::from_millis(10).

We can also use s and ns prefix

serde_valid/src/error.rs Outdated Show resolved Hide resolved
serde_valid/src/error.rs Outdated Show resolved Hide resolved
serde_valid/src/error.rs Outdated Show resolved Hide resolved
serde_valid/src/validation/composited.rs Outdated Show resolved Hide resolved
serde_valid/src/validation/duration/minimum_duration.rs Outdated Show resolved Hide resolved
serde_valid_derive/src/error.rs Outdated Show resolved Hide resolved
serde_valid/src/error.rs Outdated Show resolved Hide resolved
serde_valid/tests/complex_test.rs Outdated Show resolved Hide resolved
@yassun7010
Copy link
Owner

yassun7010 commented May 7, 2024

Thanks for your suggestion!

As you wrote in lib.rs, I would like to maintain crates' policy of supporting validation as described in jsonschema.

I think it would be better to have a helper function like #[validate(custom(minimum_duration("10ms"))] to clearly indicate that the validation is not a Jsonschema specification.

@StivenAigleIxxi
Copy link
Author

@yassun7010
Is this something achievable with the current implementation of custom, after a brief search I think not but you know better than me.

May be I could try to implement something like #[validate(not_json_schema(minimum_duration("10ms")))], with such things, the custom attribute will remain a tool for the user to implement custom function. And we will have a dedicated attribute to implement, inside the library, validation that are not in json

@B14ck6u4rd
Copy link

@yassun7010 @StivenAigleIxxi

I think the not_json_schema is irrelevant in a crate above Serde (that can (de)serialize something other than JSON).

@yassun7010
Copy link
Owner

yassun7010 commented May 13, 2024

@StivenAigleIxxi @B14ck6u4rd

I've written my idea in #63;

Does the method using custom meet your requirements?

The way of the limitation is redundant. But, the resolution by custom maintains the position of this crate (based on JsonSchema).

My concern is that the JsonSchema specification will support equivalent validations in the future under different names.

@B14ck6u4rd
Copy link

@StivenAigleIxxi @B14ck6u4rd

I've written my idea in #63;

Does the method using custom meet your requirements?

The way of the limitation is redundant. But, the resolution by custom maintains the position of this crate (based on JsonSchema).

My concern is that the JsonSchema specification will support equivalent validations in the future under different names.

I very like your solution @yassun7010 !

@yassun7010 yassun7010 closed this May 14, 2024
@yassun7010
Copy link
Owner

yassun7010 commented May 14, 2024

I released v0.20.0.

@B14ck6u4rd
Copy link

Thanks for your work @yassun7010 !

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.

3 participants