-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add message validation based on schema #21
feat: add message validation based on schema #21
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have only concerns to the way of message validation. Great job! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more comments 😅 But overall good!
asyncapi/v2/v2.go
Outdated
if len(o.MessageField.Payload().OneOf()) == 0 { | ||
return []asyncapi.Message{o.MessageField} | ||
} | ||
|
||
var msgs []asyncapi.Message | ||
for _, payload := range o.MessageField.Payload().OneOf() { | ||
p := payload.(*Schema) | ||
msgs = append(msgs, Message{ | ||
PayloadField: p, | ||
}) | ||
} | ||
|
||
return msgs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the true. MessageField
should have OneOf
property and you should use it, not Payload.OneOf()
. Payload.OneOF
is related to single message, not to array of messages :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is not explained at all in the documentation :O Well, only through an example but not clear at all: https://www.asyncapi.com/docs/specifications/v2.0.0#messageObject
Is there any other exception or hidden gem that you know about that I should add here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have information about oneOf
in the https://www.asyncapi.com/docs/specifications/v2.0.0#operationObject
for the message field, you can read:
A definition of the message that will be published or received on this channel. oneOf is allowed here to specify multiple messages, however, a message MUST be valid only against one of the referenced message objects.
so you can have shape:
publish:
message:
payload: ...
or
publish:
message:
oneOf:
- payload: ... # message 1
- payload: ... # message 2
But I agree that should be cleared in the doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, This oneOf
field should be either part of the message object or a new type that holds that field.
Ok, gotta work on it! thks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference asyncapi/spec#588
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Description
This PR adds the required code to validate Kafka message against a JSON Schema document, which is grabbed from the message payload declared in the AsyncAPI document.
It introduces a new error validation notification mechanism, that allows configuring a Go channel where all validation errors will flow. Now the behavior is just logging those validation errors.
You can see a demo of this feature working here
Related issue(s)
Fixes #10