MCPcopy Create free account
hub / github.com/baerwang/openapi-rs / validate_array_length

Function validate_array_length

src/validator/mod.rs:874–898  ·  view source on GitHub ↗
(key: &str, length: usize, properties: &Properties)

Source from the content-addressed store, hash-verified

872}
873
874fn validate_array_length(key: &str, length: usize, properties: &Properties) -> Result<()> {
875 if let Some(min) = properties.min_items {
876 if length < usize::try_from(min)? {
877 return Err(anyhow!(
878 "The array '{}' must have at least {} items, but got {}",
879 key,
880 min,
881 length
882 ));
883 }
884 }
885
886 if let Some(max) = properties.max_items {
887 if length > usize::try_from(max)? {
888 return Err(anyhow!(
889 "The array '{}' must have at most {} items, but got {}",
890 key,
891 max,
892 length
893 ));
894 }
895 }
896
897 Ok(())
898}
899
900fn format_error(kind: &str, key: &str, value: &str) -> anyhow::Error {
901 anyhow::anyhow!(

Callers 1

validate_single_typeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected