strimzi / strimzi-kafka-bridge

An HTTP bridge for Apache Kafka®
Apache License 2.0
286 stars 119 forks source link

`No schema matches` error raised when key or value in a `json` record is a JSON array #892

Closed ppatierno closed 7 months ago

ppatierno commented 7 months ago

When using the json embedded format and sending a message like the following ...

{
  "records": [
    {
      "value": "my-value",
      "key": ["element1",{"field": "element2"}]
    }
  ]
}

The bridge returns ...

{
    "error_code": 400,
    "message": "Validation error on: /records/0/key - No schema matches"
}

This error is raised by the internal Vert.x JSON schema component which is doing the validation on the key field based on the definition we have in the OpenAPI ...

"key": {
    "oneOf": [
        {
            "type": "object"
        },
        {
            "type": "string"
        }
    ]
}

It should work because it's defined as a JSON object, and the array in the example is a valid JSON object. So it seems that the array is making troubles to the validator. The same happens if using the same to the value field of course.

ppatierno commented 7 months ago

Taking a look at this, the issue seems to be on our OpenAPI definition. The key (and value) for the records should be defined also as array as possible type. So something like:

"key": {
    "oneOf": [
        {
            "type": "array"
        },
        {
            "type": "object"
        },
        {
            "type": "string"
        }
    ]
}

Because of course OpenAPI spec uses the JSON Schema Definition where "array" is used as type for a JSON array (an array with JSON object insides).

antonio-pedro99 commented 7 months ago

Hi @ppatierno, I have done something for this, late I will raise the PR