Skip to content

Commit 5e6e593

Browse files
committed
Update circular schema ref check and tag check
1 parent 4e5e6e5 commit 5e6e593

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/openapi_test_client/libraries/api/api_spec.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,17 @@ def resolve_recursive(reference: Any, schemas_seen: list[str] | None = None):
143143
reference.clear()
144144
reference.update(type="object")
145145
else:
146-
schemas_seen.append(schema)
147146
try:
148147
resolved_value = reduce(lambda d, k: d[k], ref_keys, api_spec)
149148
except KeyError as e:
150149
logger.warning(
151150
f"SKIPPED: Unable to resolve '$ref' for '{new_reference}' (KeyError: {e})"
152151
)
153152
else:
153+
schemas_seen.append(schema)
154154
if has_reference(resolved_value):
155155
resolved_value = resolve_recursive(resolved_value, schemas_seen=schemas_seen)
156-
schemas_seen.remove(schema)
156+
schemas_seen.pop()
157157
if isinstance(resolved_value, dict):
158158
reference.update(resolved_value)
159159
else:
@@ -244,17 +244,18 @@ def adjust_recursive(
244244

245245
@staticmethod
246246
def _collect_endpoint_tags(resolved_api_spec: dict[str, Any]) -> list[str]:
247-
tags = []
247+
collected_tags = []
248248

249249
def collect(obj):
250250
if isinstance(obj, dict):
251-
if "tags" in obj:
252-
tags.extend(obj["tags"])
251+
tags = obj.get("tags")
252+
if tags and isinstance(tags, list) and all(isinstance(t, str) for t in tags):
253+
collected_tags.extend(tags)
253254
else:
254255
for k, v in obj.items():
255256
collect(obj[k])
256257

257258
collect(resolved_api_spec["paths"])
258-
if not tags:
259-
tags.append("default")
260-
return list(set(tags))
259+
if not collected_tags:
260+
collected_tags.append("default")
261+
return list(set(collected_tags))

0 commit comments

Comments
 (0)