Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload validator fails with oneOf in payload #196

Open
alex-zywicki opened this issue Feb 25, 2022 · 4 comments
Open

Payload validator fails with oneOf in payload #196

alex-zywicki opened this issue Feb 25, 2022 · 4 comments

Comments

@alex-zywicki
Copy link
Contributor

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/

@alex-zywicki
Copy link
Contributor Author

@dedoussis I tested the change to schema.get("type") and that seems to fix the issue for me.

@dedoussis
Copy link
Owner

dedoussis commented Mar 14, 2022

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.

@dedoussis
Copy link
Owner

Have released version 0.8.3 that fixes this.

@dedoussis
Copy link
Owner

dedoussis commented Mar 21, 2022

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants