-
Notifications
You must be signed in to change notification settings - Fork 222
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
Add pubsub source and schema validation #1679
Conversation
Signed-off-by: Shubham Nazare <[email protected]>
sc-poc/modules/pubsub/operations.go
Outdated
"doc": { | ||
Type: "string", | ||
}, |
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.
What is this schema for? Why not keep the entire schema as type = object & AdditionalProperties true
sc-poc/modules/pubsub/operations.go
Outdated
asyncapiProvisionChannel := Channel{ | ||
Name: "asyncapi-provision", | ||
Payload: ChannelPayload{ | ||
Schema: map[string]*v1alpha1.ChannelSchema{ |
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.
Same here
sc-poc/modules/pubsub/operations.go
Outdated
// Channels return channels with their schema | ||
func (a *App) Channels() ChannelsWithSchema { | ||
channels := ChannelsWithSchema{ | ||
Channels: make(map[string]Channel), | ||
Components: &Components{ | ||
Schemas: map[string]interface{}{ | ||
"APIManMsg": map[string]interface{}{ |
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.
Remove this if its no longer needed
sc-poc/modules/pubsub/types.go
Outdated
Schema map[string]interface{} `json:"schema,omitempty"` | ||
Example interface{} `json:"example,omitempty"` | ||
Examples []interface{} `json:"examples,omitempty"` | ||
Schema map[string]*v1alpha1.ChannelSchema `json:"schema,omitempty"` |
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.
Schema map[string]*v1alpha1.ChannelSchema `json:"schema,omitempty"` | |
Schema *v1alpha1.ChannelSchema `json:"schema,omitempty"` |
sc-poc/modules/pubsub/websocket.go
Outdated
err = a.Publish(channel.Name, pubMsg, PublishOptions{}) | ||
if err != nil { |
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.
err = a.Publish(channel.Name, pubMsg, PublishOptions{}) | |
if err != nil { | |
if err := a.Publish(channel.Name, pubMsg, PublishOptions{}); err != nil { |
// Channel describes the name of the pubsub channel | ||
Channel string `json:"channel"` | ||
// Payload describes the payload schema of the channel | ||
Payload map[string]*ChannelSchema `json:"payload,omitempty"` |
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.
Payload map[string]*ChannelSchema `json:"payload,omitempty"` | |
Payload *ChannelSchema `json:"payload,omitempty"` |
sc-poc/modules/pubsub/app.go
Outdated
sourceMan := sourceManT.(*source.App) | ||
sources := sourceMan.GetSources("pubsub") | ||
for _, src := range sources { | ||
channelSrc := src.(*pubsub_channel.PubsubChannelSource) |
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.
Make an interface in this package itself
… validation and pubsub channel source type Signed-off-by: Shubham Nazare <[email protected]>
sc-poc/modules/pubsub/app.go
Outdated
Schema: channelSrc.Spec.Payload, | ||
}, | ||
} | ||
channelSrc := src.(Source) |
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.
Check if its okay. Continue if it isnt
sc-poc/modules/pubsub/asyncapi.go
Outdated
}, | ||
}, | ||
{ | ||
Name: "Error", |
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.
Name: "Error", | |
Name: "PublishError", |
sc-poc/modules/pubsub/asyncapi.go
Outdated
Payload: map[string]interface{}{ | ||
"type": "object", | ||
"properties": map[string]interface{}{ | ||
"message": map[string]interface{}{ |
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.
Accept a message id as well. We need to tell the publisher which message didn't publish. Also you can make json schema directly from a struct without having to make such maps. Look at this library: https://github.com/invopop/jsonschema
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.
Can we do this in a separate PR? I will make an issue for it.
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.
Ok
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.
Signed-off-by: Shubham Nazare <[email protected]>
Signed-off-by: Shubham Nazare <[email protected]>
sc-poc/modules/pubsub/asyncapi.go
Outdated
}, | ||
}, | ||
{ | ||
Name: "PublishError", |
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.
Can we merge publish error with the Acknowledge
message?
Signed-off-by: Shubham Nazare <[email protected]>
sc-poc/modules/pubsub/asyncapi.go
Outdated
}, | ||
"ack": map[string]interface{}{ | ||
"type": "boolean", | ||
OneOf: []MessageEntity{ |
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.
No need of a oneOf if you are returning just a single object
Signed-off-by: Shubham Nazare <[email protected]>
Signed-off-by: Shubham Nazare <[email protected]>
Fixes #1672