Skip to content

Commit

Permalink
Remove a couple clones around deserializing validators (#31219)
Browse files Browse the repository at this point in the history
*

GitOrigin-RevId: dd27331ae5f5a70694a1588777367e07eab554d4
  • Loading branch information
sshader authored and Convex, Inc. committed Oct 30, 2024
1 parent 8f7f0b5 commit 7a1bc13
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions crates/common/src/schemas/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl TryFrom<JsonValue> for DocumentSchema {

fn try_from(v: JsonValue) -> Result<Self, Self::Error> {
let schema_type: Validator = v.try_into()?;
match schema_type.clone() {
match schema_type {
Validator::Any => Ok(DocumentSchema::Any),
Validator::Union(value) => {
let schemas: Vec<_> = value
Expand All @@ -491,9 +491,7 @@ impl TryFrom<JsonValue> for DocumentSchema {
// once data has been migrated
Ok(object_schema.filter_system_fields())
} else {
Err(anyhow::anyhow!(invalid_top_level_type_in_schema(
&schema_type
)))
Err(anyhow::anyhow!(invalid_top_level_type_in_schema(&s)))
}
})
.collect::<anyhow::Result<_>>()?;
Expand Down Expand Up @@ -757,15 +755,15 @@ impl TryFrom<JsonValue> for ObjectValidator {
type Error = anyhow::Error;

fn try_from(value: JsonValue) -> Result<Self, Self::Error> {
let value = value
.as_object()
.ok_or_else(|| anyhow::anyhow!("Object must be an object"))?;
let JsonValue::Object(value) = value else {
anyhow::bail!("Object must be an object");
};
let schema = ObjectValidator(
value
.into_iter()
.map(|(k, v)| {
let field_name = k.parse::<IdentifierFieldName>()?;
let field_value = FieldValidator::try_from(v.clone()).map_err(|e| {
let field_value = FieldValidator::try_from(v).map_err(|e| {
e.wrap_error_message(|msg| {
format!("Invalid validator for key `{field_name}`: {msg}")
})
Expand Down

0 comments on commit 7a1bc13

Please sign in to comment.