Readme
This commit is contained in:
1 parent
536d5b14d8
commit
427a824e45
2 files changed
+263
-2
No files matched your search
+13
-2
@@ -1,4 +1,3 @@
|
||||
|
||||
use axum::{
|
||||
extract::{rejection::JsonRejection, State},
|
||||
http::StatusCode,
|
||||
@@ -34,6 +33,9 @@ enum ValidationMode {
|
||||
struct FieldSpec {
|
||||
#[serde(rename = "type")]
|
||||
data_type: DataType,
|
||||
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
value: Option<Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -122,6 +124,15 @@ fn validate_data(data: &Value, schema: &SchemaConfig) -> Result<(), String> {
|
||||
type_name(&spec.data_type)
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(expected) = &spec.value {
|
||||
if value != expected {
|
||||
return Err(format!(
|
||||
"Field '{key}' must equal {}",
|
||||
expected
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if matches!(schema.mode, ValidationMode::Strict) {
|
||||
@@ -405,4 +416,4 @@ async fn main() {
|
||||
axum::serve(listener, app)
|
||||
.await
|
||||
.expect("HTTP server failed");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user