@@ -65,6 +65,7 @@ def __init__(self, definition, resolver=None, formats={}, use_default=True):
65
65
('patternProperties' , self .generate_pattern_properties ),
66
66
('additionalProperties' , self .generate_additional_properties ),
67
67
))
68
+ self ._any_or_one_of_count = 0
68
69
69
70
@property
70
71
def global_state (self ):
@@ -145,16 +146,18 @@ def generate_any_of(self):
145
146
146
147
Valid values for this definition are 3, 4, 5, 10, 11, ... but not 8 for example.
147
148
"""
148
- self .l ('{variable}_any_of_count = 0' )
149
+ self ._any_or_one_of_count += 1
150
+ count = self ._any_or_one_of_count
151
+ self .l ('{variable}_any_of_count{count} = 0' , count = count )
149
152
for definition_item in self ._definition ['anyOf' ]:
150
153
# When we know it's passing (at least once), we do not need to do another expensive try-except.
151
- with self .l ('if not {variable}_any_of_count:' , optimize = False ):
154
+ with self .l ('if not {variable}_any_of_count{count}:' , count = count , optimize = False ):
152
155
with self .l ('try:' , optimize = False ):
153
156
self .generate_func_code_block (definition_item , self ._variable , self ._variable_name , clear_variables = True )
154
- self .l ('{variable}_any_of_count += 1' )
157
+ self .l ('{variable}_any_of_count{count} += 1' , count = count )
155
158
self .l ('except JsonSchemaValueException: pass' )
156
159
157
- with self .l ('if not {variable}_any_of_count:' , optimize = False ):
160
+ with self .l ('if not {variable}_any_of_count{count}:' , count = count , optimize = False ):
158
161
self .exc ('{name} must be valid by one of anyOf definition' , rule = 'anyOf' )
159
162
160
163
def generate_one_of (self ):
@@ -173,16 +176,18 @@ def generate_one_of(self):
173
176
174
177
Valid values for this definition are 3, 5, 6, ... but not 15 for example.
175
178
"""
176
- self .l ('{variable}_one_of_count = 0' )
179
+ self ._any_or_one_of_count += 1
180
+ count = self ._any_or_one_of_count
181
+ self .l ('{variable}_one_of_count{count} = 0' , count = count )
177
182
for definition_item in self ._definition ['oneOf' ]:
178
183
# When we know it's failing (one of means exactly once), we do not need to do another expensive try-except.
179
- with self .l ('if {variable}_one_of_count < 2:' , optimize = False ):
184
+ with self .l ('if {variable}_one_of_count{count} < 2:' , count = count , optimize = False ):
180
185
with self .l ('try:' , optimize = False ):
181
186
self .generate_func_code_block (definition_item , self ._variable , self ._variable_name , clear_variables = True )
182
- self .l ('{variable}_one_of_count += 1' )
187
+ self .l ('{variable}_one_of_count{count} += 1' , count = count )
183
188
self .l ('except JsonSchemaValueException: pass' )
184
189
185
- with self .l ('if {variable}_one_of_count != 1:' ):
190
+ with self .l ('if {variable}_one_of_count{count} != 1:' , count = count ):
186
191
self .exc ('{name} must be valid exactly by one of oneOf definition' , rule = 'oneOf' )
187
192
188
193
def generate_not (self ):
0 commit comments