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

Add pubsub source and schema validation #1679

Merged
merged 6 commits into from
Jun 17, 2023

Conversation

shubham4443
Copy link
Contributor

Fixes #1672

Comment on lines 38 to 40
"doc": {
Type: "string",
},
Copy link
Collaborator

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

asyncapiProvisionChannel := Channel{
Name: "asyncapi-provision",
Payload: ChannelPayload{
Schema: map[string]*v1alpha1.ChannelSchema{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

// 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{}{
Copy link
Collaborator

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

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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Schema map[string]*v1alpha1.ChannelSchema `json:"schema,omitempty"`
Schema *v1alpha1.ChannelSchema `json:"schema,omitempty"`

Comment on lines 105 to 106
err = a.Publish(channel.Name, pubMsg, PublishOptions{})
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Payload map[string]*ChannelSchema `json:"payload,omitempty"`
Payload *ChannelSchema `json:"payload,omitempty"`

sourceMan := sourceManT.(*source.App)
sources := sourceMan.GetSources("pubsub")
for _, src := range sources {
channelSrc := src.(*pubsub_channel.PubsubChannelSource)
Copy link
Collaborator

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

sc-poc/sources/pubsub_channel/source.go Show resolved Hide resolved
… validation and pubsub channel source type

Signed-off-by: Shubham Nazare <[email protected]>
Schema: channelSrc.Spec.Payload,
},
}
channelSrc := src.(Source)
Copy link
Collaborator

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

},
},
{
Name: "Error",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Name: "Error",
Name: "PublishError",

Payload: map[string]interface{}{
"type": "object",
"properties": map[string]interface{}{
"message": map[string]interface{}{
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sc-poc/modules/pubsub/types.go Show resolved Hide resolved
sc-poc/sources/pubsub_channel/source.go Show resolved Hide resolved
Signed-off-by: Shubham Nazare <[email protected]>
},
},
{
Name: "PublishError",
Copy link
Collaborator

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?

},
"ack": map[string]interface{}{
"type": "boolean",
OneOf: []MessageEntity{
Copy link
Collaborator

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

@YourTechBud YourTechBud merged commit 82564ec into spacecloud-io:sc-poc Jun 17, 2023
shubham4443 added a commit to shubham4443/space-cloud that referenced this pull request Jun 22, 2023
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

Successfully merging this pull request may close these issues.

2 participants