Closed StivenAigleIxxi closed 3 months ago
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.
@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
@yassun7010 @StivenAigleIxxi
I think the not_json_schema
is irrelevant in a crate above Serde (that can (de)serialize something other than JSON).
@StivenAigleIxxi @B14ck6u4rd
I've written my idea in https://github.com/yassun7010/serde_valid/pull/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.
@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 !
I released v0.20.0.
Thanks for your work @yassun7010 !
With the help of some crate like
serde_with
, it is possible to serialize and deserialize Duration.With modification
serde_valid
is able to defineminimum
andmaximum
for this type. To define such minimum, we use the attribute validate with the parameterminimum_duration
like this#[validate(minimum_duration="10ms")]
, "10ms" is transformed intoDuration::from_millis(10)
.We can also use
s
andns
prefix