Skip to content

Commit b858c80

Browse files
committed
fix: Check for models duplicates and prevent AsyncAPI gen.
If models json schema gets altered so the used ref identifiers are predictable, we can allow model duplicates. Resolves: #4
1 parent 4f233f3 commit b858c80

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

fastapi_sio/asyncapi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ def get_asyncapi(
3434
handler.model for handler in handlers if handler.model is not None
3535
] + [emitter.model for emitter in emitters if emitter.model is not None]
3636

37+
# Check for duplicates in models
38+
model_names = [model.__name__ for model in used_models]
39+
duplicates = {name for name in model_names if model_names.count(name) > 1}
40+
if duplicates:
41+
raise ValueError(
42+
f"Cannot generate AsyncAPI documentation due to duplicate models: {', '.join(duplicates)}"
43+
)
44+
3745
return AsyncAPI(
3846
id=AsyncAPIIdentifier(id),
3947
info=AsyncAPIInfo(

0 commit comments

Comments
 (0)