Payload validator fails with oneOf in payload
alex-zywicki opened this issue · 4 comments
WIth a message payload that contains a oneOf
payload:
oneOf:
- type: array
items:
type: string
- type: string
When passing an array of string I get this exception:
('[sos on_replay:49]', '------------------ traceback ------------------')
(' |', 'Traceback (most recent call last):')
(' |', ' File "/usr/lib/python3.8/site-packages/asti/sapi_flask/plugins/sos/__init__.py", line 45, in on_replay')
(' |', ' emit("sosreport", reports, to=session.sid, namespace=NAMESPACE)')
(' |', ' File "/usr/local/lib/python3.8/site-packages/flask_socketio/__init__.py", line 838, in emit')
(' |', ' return socketio.emit(event, *args, namespace=namespace, to=to,')
(' |', ' File "/usr/local/lib/python3.8/site-packages/asynction/server.py", line 286, in emit')
(' |', ' validate_payload(payload_args, message.payload)')
(' |', ' File "/usr/local/lib/python3.8/site-packages/asynction/validation.py", line 56, in validate_payload')
(' |', ' if schema["type"] == "array" and schema.get("prefixItems"): # Tuple validation')
(' |', "KeyError: 'type'")
('[sos on_replay:49]', '---------------- end traceback ----------------')
I'm not 100% sure if changing to schema.get("type")
would be correct, but the oneOf
case needs to be handled somehow.
From what I can tell based on https://www.asyncapi.com/docs/specifications/v2.2.0#messageObject this is a valid payload and it seems to validate correctly on https://studio.asyncapi.com/
@dedoussis I tested the change to schema.get("type")
and that seems to fix the issue for me.
Hi @alex-zywicki, apologies for the delay. This is indeed a bug, but the fix is a bit more complex than the one you propose. Will look into raising a PR.
Have released version 0.8.3
that fixes this.
@alex-zywicki Would it be possible to confirm that the new version fixes the issue you encountered? If so, this thread can be closed I guess.