Skip to content

Commit 01169df

Browse files
goffrieConvex, Inc.
authored andcommitted
Remove support for Map/Set validators (#41842)
Maps and sets are undocumented and deprecated; start getting rid of them. GitOrigin-RevId: e0131a88d68e0729150b6ce45925bf2f72175650
1 parent 57cd938 commit 01169df

File tree

7 files changed

+35
-234
lines changed

7 files changed

+35
-234
lines changed

crates/common/src/schemas/json.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ pub enum ValidatorJson {
641641
Boolean,
642642
String,
643643
Bytes,
644+
#[serde(alias = "map")]
645+
#[serde(alias = "set")]
644646
Any,
645647
Literal {
646648
value: JsonValue,
@@ -652,13 +654,6 @@ pub enum ValidatorJson {
652654
Array {
653655
value: Box<ValidatorJson>,
654656
},
655-
Set {
656-
value: Box<ValidatorJson>,
657-
},
658-
Map {
659-
keys: Box<ValidatorJson>,
660-
values: Box<ValidatorJson>,
661-
},
662657
Record {
663658
keys: Box<ValidatorJson>,
664659
values: Box<FieldTypeJson>,
@@ -690,11 +685,6 @@ impl TryFrom<ValidatorJson> for Validator {
690685
ValidatorJson::Literal { value } => Ok(Validator::Literal(value.try_into()?)),
691686
ValidatorJson::Id { table_name } => Ok(Validator::Id(table_name.parse()?)),
692687
ValidatorJson::Array { value } => Ok(Validator::Array(Box::new((*value).try_into()?))),
693-
ValidatorJson::Set { value } => Ok(Validator::Set(Box::new((*value).try_into()?))),
694-
ValidatorJson::Map { keys, values } => Ok(Validator::Map(
695-
Box::new((*keys).try_into()?),
696-
Box::new((*values).try_into()?),
697-
)),
698688
ValidatorJson::Record { keys, values } => {
699689
let error_short_code = "InvalidRecordType";
700690
let keys_validator = Validator::try_from(*keys)?;
@@ -758,13 +748,6 @@ impl TryFrom<Validator> for ValidatorJson {
758748
Validator::Array(t) => ValidatorJson::Array {
759749
value: Box::new(ValidatorJson::try_from(*t)?),
760750
},
761-
Validator::Set(t) => ValidatorJson::Set {
762-
value: Box::new(ValidatorJson::try_from(*t)?),
763-
},
764-
Validator::Map(k, v) => ValidatorJson::Map {
765-
keys: Box::new(ValidatorJson::try_from(*k)?),
766-
values: Box::new(ValidatorJson::try_from(*v)?),
767-
},
768751
Validator::Record(k, v) => ValidatorJson::Record {
769752
keys: Box::new(ValidatorJson::try_from(*k)?),
770753
values: Box::new(FieldTypeJson::try_from(FieldValidator {
@@ -853,9 +836,15 @@ impl TryFrom<ObjectValidator> for BTreeMap<String, FieldTypeJson> {
853836
#[cfg(test)]
854837
mod tests {
855838
use errors::ErrorMetadataAnyhowExt;
856-
use serde_json::Value as JsonValue;
839+
use serde_json::{
840+
json,
841+
Value as JsonValue,
842+
};
857843

858-
use crate::schemas::validator::LiteralValidator;
844+
use crate::schemas::{
845+
json::ValidatorJson,
846+
validator::LiteralValidator,
847+
};
859848

860849
#[test]
861850
fn test_infinite_literal_is_user_error() -> anyhow::Result<()> {
@@ -872,4 +861,21 @@ mod tests {
872861
assert!(error.is_bad_request());
873862
Ok(())
874863
}
864+
865+
#[test]
866+
fn test_map_set_are_any() -> anyhow::Result<()> {
867+
assert_eq!(
868+
serde_json::from_value::<ValidatorJson>(
869+
json!({"type": "map", "keys": {"type": "string"}, "values": {"type": "string"}})
870+
)?,
871+
ValidatorJson::Any
872+
);
873+
assert_eq!(
874+
serde_json::from_value::<ValidatorJson>(
875+
json!({"type": "set", "value": {"type": "string"}})
876+
)?,
877+
ValidatorJson::Any
878+
);
879+
Ok(())
880+
}
875881
}

crates/common/src/schemas/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,6 @@ impl DocumentSchema {
805805
}
806806
}
807807

808-
pub fn has_map_or_set(&self) -> bool {
809-
match &self {
810-
DocumentSchema::Any => false,
811-
DocumentSchema::Union(validators) => validators
812-
.iter()
813-
.any(|root_validator| root_validator.has_map_or_set()),
814-
}
815-
}
816-
817808
pub fn is_vector_index_eligible(&self, field_path: &FieldPath) -> bool {
818809
match &self {
819810
DocumentSchema::Any => true,

crates/common/src/schemas/tests.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,54 +1233,6 @@ mod validator_subset {
12331233
)
12341234
}
12351235

1236-
#[test]
1237-
fn test_sets_are_covariant() -> anyhow::Result<()> {
1238-
assert_is_strict_subset(
1239-
Validator::Set(Box::new(Validator::String)),
1240-
Validator::Set(Box::new(Validator::Any)),
1241-
)
1242-
}
1243-
1244-
#[test]
1245-
fn test_arrays_and_sets_dont_mix() -> anyhow::Result<()> {
1246-
assert_is_unrelated(
1247-
Validator::Array(Box::new(Validator::String)),
1248-
Validator::Set(Box::new(Validator::String)),
1249-
)
1250-
}
1251-
1252-
#[test]
1253-
fn test_maps_are_covariant_over_keys() -> anyhow::Result<()> {
1254-
assert_is_strict_subset(
1255-
Validator::Map(Box::new(Validator::String), Box::new(Validator::Any)),
1256-
Validator::Map(Box::new(Validator::Any), Box::new(Validator::Any)),
1257-
)
1258-
}
1259-
1260-
#[test]
1261-
fn test_maps_are_covariant_over_values() -> anyhow::Result<()> {
1262-
assert_is_strict_subset(
1263-
Validator::Map(Box::new(Validator::Any), Box::new(Validator::String)),
1264-
Validator::Map(Box::new(Validator::Any), Box::new(Validator::Any)),
1265-
)
1266-
}
1267-
1268-
#[test]
1269-
fn test_maps_not_related_when_key_not_related() -> anyhow::Result<()> {
1270-
assert_is_unrelated(
1271-
Validator::Map(Box::new(Validator::String), Box::new(Validator::Any)),
1272-
Validator::Map(Box::new(Validator::Int64), Box::new(Validator::Any)),
1273-
)
1274-
}
1275-
1276-
#[test]
1277-
fn test_maps_not_related_when_value_not_related() -> anyhow::Result<()> {
1278-
assert_is_unrelated(
1279-
Validator::Map(Box::new(Validator::Any), Box::new(Validator::String)),
1280-
Validator::Map(Box::new(Validator::Any), Box::new(Validator::Int64)),
1281-
)
1282-
}
1283-
12841236
#[test]
12851237
fn test_changing_union_order() -> anyhow::Result<()> {
12861238
assert_is_equivalent(

0 commit comments

Comments
 (0)