Avro schema issues

Hi all! I’ve got a fairly large avsc file that I want to validate (not shown here). I’ve loaded up a local Landoop Schema Registry UI. It works fine for simple schemas, but I face issues when I try to nest records.

What am I doing wrong here?

{
    "name": "Test2",
    "namespace": "com.avro",
    "type": "record",
    "fields":[
        {"name": "field1", "type": "string" },
        {
            "name": "test",
            "type": "record",
            "fields": [
                { "name": "field1", "type": "string" }
            ]
        }
    ]
}

I get error ‘Either the input schema or one its references is invalid’.
Then if I try a flat structure:

[
{
    "name": "Test",
    "namespace": "com.avro",
    "type": "record",
    "fields": [
        {
            "name": "field1",
            "type": "string" 
        }
    ]
},
{
    "name": "Test2",
    "namespace": "com.avro",
    "type": "record",
    "fields":[
        {"name": "field1", "type": "com.avro.Test" }
    ]
}
]

I then get error ‘com.avro.Test is not valid’.

Any help will be much appreciated!

Is there a CLI tool available for validating schemas, ideally with verbose errors?

Do you get this error with Confluent Schema Registry? I’m not clear from your post where you’re seeing the error, and how to reproduce it.

Hi Robin! Apologies, let me to fill in those details.

I’m using the landoop/schema-registry-ui:0.9.5 image with confluentinc/cp-schema-registry:5.5.1 within Steph’s docker-compose stack.

I thought it might be a UI issue but the network response from the API is a 422 response.

I’ll try avro tools also, see if I can validate if my schema is correctly written that way.

https://github.com/coderfi/docker-avro-tools

Your first example is indeed wrong according to the Avro specification. It should be written using the following design:

{
    "name": "Test2",
    "namespace": "com.avro",
    "type": "record",
    "fields":[
        {"name": "field1", "type": "string" },
        {
            "name" : "test",
            "type": [
              {
                 "type": "record",
                 "name": "CustomType",
                 "fields": [
                    { "name": "field1", "type": "string" }
                 ]
              }
            ]
        }
    ]
}

FYI your second example is not wrong and compiled successfully using the Avro compiler v1.10.1. Perhaps this tool that you are using (Landoop Schema Registry) is not up to date in terms of dependencies.

3 Likes

That’s awesome, it worked! Thank you very much Ricardo! :+1:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.