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

fix: make key in kafka msg binding validate as anyOf #466

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

derberg
Copy link
Member

@derberg derberg commented Dec 11, 2023

Kafka binding for messages, in 0.4 version introduced Avro support for key - but JSON Schema is not properly modified

Kafka message binding -> https://github.com/asyncapi/bindings/tree/master/kafka#message-binding-object
Screenshot 2023-12-11 at 11 01 52

so things like below should be allowed:

      bindings:
        kafka:
          key:
            $ref: "https://deploy-preview-921--asyncapi-website.netlify.app/resources/casestudies/adeo/CostingResponseKey.avsc"

Just go to https://studio.asyncapi.com/?url=https://github.com/raw/asyncapi/spec/d78dcea70c9b094a3df72f9a4e811828cec778cc/examples/adeo-kafka-request-reply-asyncapi.yml and try to remove lines 242-245 all all suddenly validation stops failing

Where issue is coming from

This is what json schema for message binding says: https://github.com/asyncapi/spec-json-schemas/blob/master/bindings/kafka/0.4.0/message.json#L13-L21

current JSON Schema validates agains oneOf listed schemas, but problem is that these are reference object + json schema. JSON schema defines $ref property as well, so when in key you put $ref, it is then valid against both schemas listed under oneOf and yeah, it is an error.

I don't think there is a better solution than just using anyOf instead of oneOf 🤔

Also, such validation combination like the one I fix, is used in many other bindings, so also not sure but maybe I should propagate the fix everywhere?

This PR fixes

  • enables people to put Avro as key inline
  • changes validation keyword from oneOf to anyOf

Copy link

sonarcloud bot commented Dec 11, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@derberg derberg requested a review from M3lkior December 12, 2023 11:14
Copy link
Collaborator

@lbroudoux lbroudoux left a comment

Choose a reason for hiding this comment

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

LGTM!

@lbroudoux lbroudoux merged commit 559660c into asyncapi:master Dec 13, 2023
19 checks passed
@asyncapi-bot
Copy link
Contributor

🎉 This PR is included in version 6.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

4 participants