@@ -890,7 +890,8 @@ fn test_set_prevent_duplicates_with_duplicates() {
890
890
891
891
mod key_value_map {
892
892
use super :: * ;
893
- use std:: collections:: BTreeMap ;
893
+ use schemars:: schema:: ObjectValidation ;
894
+ use std:: { collections:: BTreeMap , vec} ;
894
895
895
896
#[ serde_as]
896
897
#[ derive( Clone , Debug , JsonSchema , Serialize ) ]
@@ -936,6 +937,35 @@ mod key_value_map {
936
937
} ,
937
938
}
938
939
940
+ #[ derive( Clone , Debug , Serialize ) ]
941
+ #[ serde( transparent) ]
942
+ struct LimitedProperties ( serde_json:: Value ) ;
943
+
944
+ impl JsonSchema for LimitedProperties {
945
+ fn schema_name ( ) -> String {
946
+ "LimitedProperties" . into ( )
947
+ }
948
+
949
+ fn json_schema ( _: & mut schemars:: gen:: SchemaGenerator ) -> schemars:: schema:: Schema {
950
+ schemars:: schema:: Schema :: Object ( schemars:: schema:: SchemaObject {
951
+ instance_type : Some ( schemars:: schema:: InstanceType :: Object . into ( ) ) ,
952
+ object : Some ( Box :: new ( ObjectValidation {
953
+ max_properties : Some ( 5 ) ,
954
+ min_properties : Some ( 1 ) ,
955
+ additional_properties : Some ( Box :: new ( schemars:: schema:: Schema :: Object (
956
+ schemars:: schema:: SchemaObject {
957
+ instance_type : Some ( schemars:: schema:: InstanceType :: String . into ( ) ) ,
958
+ ..Default :: default ( )
959
+ } ,
960
+ ) ) ) ,
961
+ ..Default :: default ( )
962
+ } ) ) ,
963
+
964
+ ..Default :: default ( )
965
+ } )
966
+ }
967
+ }
968
+
939
969
#[ test]
940
970
fn test_untagged_nested_enum ( ) {
941
971
let value = KVMap ( vec ! [
@@ -962,6 +992,25 @@ mod key_value_map {
962
992
963
993
check_valid_json_schema ( & value) ;
964
994
}
995
+
996
+ #[ test]
997
+ fn test_num_properties ( ) {
998
+ let value = KVMap ( vec ! [
999
+ LimitedProperties ( serde_json:: json!( {
1000
+ "$key$" : "A" ,
1001
+ "a" : "b" ,
1002
+ "c" : "d" ,
1003
+ "e" : "f" ,
1004
+ "g" : "h" ,
1005
+ } ) ) ,
1006
+ LimitedProperties ( serde_json:: json!( {
1007
+ "$key$" : "B" ,
1008
+ "a" : "b" ,
1009
+ } ) ) ,
1010
+ ] ) ;
1011
+
1012
+ check_valid_json_schema ( & value) ;
1013
+ }
965
1014
}
966
1015
967
1016
mod one_or_many {
0 commit comments