Schema registry is not accepting a type by reference

I have the following schemas:

{
    "namespace": "org.wcn",
    "type": "record",
    "name": "Detail",
    "fields": [
        {
            "name": "quantity",
            "type": "int"
        },
        {
            "name": "total",
            "type": "float"
        }
    ]
}

and:

{
    "namespace": "org.wcn",
    "type": "record",
    "doc": "This Schema describes about Order",
    "name": "Order",
    "fields": [
        {
            "name": "order_id",
            "type": "long"
        },
        {
            "name": "customer_id",
            "type": "long"
        },
        {
            "name": "total",
            "type": "float"
        },
        {
            "name": "detail",
            "type": "org.wcn.Detail"
        }
    ]
}

These schemas compile and work in code locally, however:

I can upload the first one to schema registry no problem. The second one gets the error:

ERROR Could not parse Avro schema (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)
org.apache.avro.SchemaParseException: "org.wcn.Detail" is not a defined name. The type of the "detail" field must be a defined name or a {"type": ...} expression.

This is thrown by the schema registry.

If I reconfigure the schema to be “all in one”:

{
    "namespace": "org.wcn",
    "type": "record",
    "doc": "This Schema describes about Order",
    "name": "OrderComplete",
    "fields": [
        {
            "name": "order_id",
            "type": "long"
        },
        {
            "name": "customer_id",
            "type": "long"
        },
        {
            "name": "total",
            "type": "float"
        },
        {
            "name": "detail",
            "type": {
                "namespace": "org.wcn",
                "type": "record",
                "name": "Detail",
                "fields": [
                    {
                        "name": "quantity",
                        "type": "int"
                    },
                    {
                        "name": "total",
                        "type": "float"
                    }
                ]
            }
        }
    ]
}

It will upload with no problems.

However this doesn’t sound like the way schema registry is intended to be used. I thought it would dereference schemas as needed so long as they were previously uploaded.
Your thoughts will be appreciated.
wcn

@wcn00 can you verify the Confluent Platform version you’re using?

I run it with this image:
confluentinc/cp-schema-registry:6.0.2

Thanks for getting back so fast.
wcn

This is interesting. The info statement when uploading the “detail” type that cannot subsequently be dereferenced is:

INFO Registering new schema: subject org.wcn.Detail, version null, id null, type null (io.confluent.kafka.schemaregistry.rest.resources.SubjectVersionsResource)

The subject looks sensible, but the type is null. When I look into that I find doc relating to the “references” field when posting a schema. For example:

“references”: [
{
“name”: “com.acme.Referenced”,
“subject”: “childSubject”,
“version”: 1
}

I’ll investigate from that point of view and update here.
Note , that in my schema uploads I am not specifying references.

Yup, thats it. If you upload a schema which references other schema “types” then they must be explicitly declared in a references list.

ttfn

1 Like

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