confluentinc / kafka-rest

Confluent REST Proxy for Kafka
https://docs.confluent.io/current/kafka-rest/docs/index.html
Other
2.25k stars 641 forks source link

v2 - POST /topics/ - return full error why validation has been failed #1239

Open rkobryn opened 5 months ago

rkobryn commented 5 months ago

Following JSON schema is deployed to the schema registry:

{
  "type": "object",
  "additionalProperties": false,
  "title": "demo.schema.v3",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "required": [
    "metafields",
    "MESSAGE"
  ],
  "properties": {
    "MESSAGE": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "required1",
            "required2",
            "required3",
            "required4",
            "required5"
          ],
          "properties": {
            "required3": {
              "type": "boolean"
            },
            "required4": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            },
            "required5": {
              "type": "integer",
              "maximum": 9999999999,
              "exclusiveMinimum": 0
            },
            "required1": {
              "type": "string",
              "minLength": 1,
              "maxLength": 40
            },
            "required2": {
              "type": "integer",
              "maximum": 9999999999,
              "exclusiveMinimum": 0
            }
          }
        }
      ]
    }
  }
}

Following message body is being send to the rest proxy:

{
   "value_schema_id":9996756,
   "key_schema": "{\"type\": \"string\"}",
   "records":[
      {
         "key":"123",
         "value":{
            "MESSAGE":{
               "required1":"123"
            }
         }
      }
   ]
}

Actual HTTP response:

{
    "error_code": 400,
    "message": "Bad Request: #: 6 schema violations found"
}

Is there a way to log full erro message? e.g:

{
    "error_code": 400,
    "message": "Bad Request: #: 6 schema violations found: (Message:
JSON is valid against no schemas from 'oneOf'. Schema path:
#/properties/MESSAGE/oneOf; Message: Required properties are missing from object: required2, required3, required4, required5.
Schema path: #/properties/MESSAGE/oneOf/1/required; ....) "
}

Response is just an example, any message which is showing detailed errors is ok

Thanks