@@ -75,9 +75,19 @@ def _non_string_min_length(self, instance, mL):
75
75
# pylint: disable=unused-argument, arguments-renamed
76
76
def maxLength (self , validator , mL , instance , schema ):
77
77
if validator .is_type (instance , "string" ):
78
- if len (instance ) > mL :
79
- yield ValidationError (f"{ instance !r} is longer than { mL } " )
80
- return
78
+ if schema .get ("format" ) == "json" :
79
+ try :
80
+ instance = json .loads (instance )
81
+ except : # noqa: E722
82
+ pass
83
+ return
84
+ yield from self ._non_string_max_length (instance , mL )
85
+ return
86
+ else :
87
+ if len (instance ) > mL :
88
+ yield ValidationError (f"{ instance !r} is longer than { mL } " )
89
+ return
90
+
81
91
# there are scenarios where Fn::Sub may not predictable so use
82
92
# best judgement
83
93
key , value = is_function (instance )
@@ -93,15 +103,25 @@ def maxLength(self, validator, mL, instance, schema):
93
103
validator , mL , self ._fix_sub_string (value [0 ]), schema
94
104
)
95
105
return
106
+
96
107
if "object" in ensure_list (schema .get ("type" )):
97
108
yield from self ._non_string_max_length (instance , mL )
98
109
99
110
# pylint: disable=unused-argument, arguments-renamed
100
111
def minLength (self , validator , mL , instance , schema ):
101
112
if validator .is_type (instance , "string" ):
102
- if len (instance ) < mL :
103
- yield ValidationError (f"{ instance !r} is shorter than { mL } " )
104
- return
113
+ if schema .get ("format" ) == "json" :
114
+ try :
115
+ instance = json .loads (instance )
116
+ except : # noqa: E722
117
+ pass
118
+ return
119
+ yield from self ._non_string_min_length (instance , mL )
120
+ return
121
+ else :
122
+ if len (instance ) < mL :
123
+ yield ValidationError (f"{ instance !r} is shorter than { mL } " )
124
+ return
105
125
106
126
# there are scenarios where Fn::Sub may not predictable so use
107
127
# best judgement
0 commit comments