@@ -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) ]
854837mod 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}
0 commit comments