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

How can I reference JSONSchema? #3386

Open
timonviola opened this issue Nov 4, 2024 · 0 comments
Open

How can I reference JSONSchema? #3386

timonviola opened this issue Nov 4, 2024 · 0 comments

Comments

@timonviola
Copy link

Hi

How can I reference JSONSchemas (registered data contracts) with the oneOf keyword?

I am stuck with trying to reference multiple JSONSchemas in on topic using oneOf keyword. I tried to follow this example: https://www.confluent.io/blog/multiple-event-types-in-the-same-kafka-topic/

however, the given example is invalid:

{
  "oneOf": [
     { "$ref": "Customer.schema.json" },
     { "$ref": "Product.schema.json" },
     { "$ref": "Order.schema.json }
  ]
}

I tried to use my data with this schema:

{
  "$id": "http://example.com/oneof.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "description": "Sample schema to help you get started.",
  "oneOf": [
    {
      "$ref": "http://example.com/lunch"
    },
    {
      "$ref": "http://example.com/snow"
    }
  ],
  "title": "oneof",
  "type": "object"
}

I also tried wrapping the "oneOf" object into properties, but alas, no success.

The dummy reference (works as expected):

{
  "$id": "http://example.com/lunch.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "description": "Sample schema to help you get started.",
  "properties": {
    "lunch": {
      "description": "The string type is used for strings of text.",
      "type": "string"
    }
  },
  "title": "lunch",
  "type": "object"
}

The response I get from SchemaRegistry:

{
    "subject": "schema-registry.oneof-value",
    "version": 1,
    "id": 100222,
    "schemaType": "JSON",
    "references": [
        {
            "name": "http://example.com/lunch",
            "subject": "pub.schema-registry-poc-usafo.lunch-sux",
            "version": 1
        },
        {
            "name": "http://example.com/snow",
            "subject": "pub.schema-registry-poc-usafo.snow-value",
            "version": 2
        }
    ],
    "schema": "{\"$id\":\"http://example.com/oneof.schema.json\",\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"additionalProperties\":false,\"description\":\"Sample schema to help you get started.\",\"oneOf\":[{\"$ref\":\"http://example.com/lunch\"},{\"$ref\":\"http://example.com/snow\"}],\"title\":\"oneof\",\"type\":\"object\"}"
}
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

1 participant