Skip to content

Commit 3ba2d3c

Browse files
authored
Fix payload body checker crash. (#527)
The case when multiple examples were present, and only some of them had a body example, was not handled in the checker. Testing: manual testing with the original repro.
1 parent 3db4381 commit 3ba2d3c

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

restler/checkers/payload_body_checker.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,25 @@ def apply(self, rendered_sequence, lock):
157157

158158
# get the corresponding request examples
159159
self._examples_values = {}
160+
body_examples=[]
160161
if last_request.examples:
161-
for example in last_request.examples.body_examples:
162-
tag_content = example.get_schema_tag_mapping()
163-
for tag in tag_content:
164-
# replace example value None by the string 'null'
165-
val = tag_content[tag]
166-
if val == None:
167-
val = 'null'
168-
if tag in self._examples_values:
169-
self._examples_values[tag].append(val)
170-
else:
171-
self._examples_values[tag] = [val]
162+
body_examples = list(filter(lambda x: x is not None, last_request.examples.body_examples))
163+
164+
for example in body_examples:
165+
tag_content = example.get_schema_tag_mapping()
166+
for tag in tag_content:
167+
# replace example value None by the string 'null'
168+
val = tag_content[tag]
169+
if val == None:
170+
val = 'null'
171+
if tag in self._examples_values:
172+
self._examples_values[tag].append(val)
173+
else:
174+
self._examples_values[tag] = [val]
172175

173176
# set the initial starting body schemas
174-
if last_request.examples and self._start_with_examples:
175-
body_schema_list = list(last_request.examples.body_examples) + [last_request.body_schema]
177+
if self._start_with_examples:
178+
body_schema_list = body_examples + [last_request.body_schema]
176179
else:
177180
body_schema_list = [last_request.body_schema]
178181

0 commit comments

Comments
 (0)